Skip to content

Commit

Permalink
List view with (partial) links.
Browse files Browse the repository at this point in the history
  • Loading branch information
seancorfield committed Nov 7, 2011
1 parent e29df38 commit 4740cba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/example/controllers/user.clj
Expand Up @@ -14,6 +14,9 @@
(def ^:private users (atom initial-user-data))

;; data access methods - would be in a service
(defn- get-department-by-id [id]
(first (filter #(== id (:id %)) departments)))

(defn- get-user-by-id [id]
(first (filter #(== id (:id %)) @users)))

Expand Down Expand Up @@ -59,5 +62,13 @@
identity)
(content (:name dept)))))))

(defn form-list [rc nodes]
nodes)
(defn list-view [rc nodes]
(at nodes
[:tr.zero] (if (empty? @users) identity (substitute ""))
[:tr.user]
(clone-for [user @users]
[:td.id :a] (content (str (:id user)))
[:td.name :a] (content (str (:first-name user) " " (:last-name user)))
[:td.email] (content (:email user))
[:td.department] (content (:name (get-department-by-id (:department-id user))))
)))
23 changes: 23 additions & 0 deletions src/example/views/user/list.html
@@ -0,0 +1,23 @@
<table border="0" cellspacing="0">
<col width="40" />
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Email</th>
<th>Department</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<!-- need to make this conditional -->
<tr class="zero"><td colspan="5">No users exist but <a href="/user/form">new ones can be added</a>.</td></tr>
<tr class="user">
<td class="id"><a href="/user/form/id/">#local.id#</a></td>
<td class="name"><a href="/user/form/id/">#local.user.getFirstName()# #local.user.getLastName()#</a></td>
<td class="email">#local.user.getEmail()#</td>
<td class="department">#local.user.getDepartment().getName()#</td>
<td class="delete"><a href="/user/delete/id/">DELETE</a></td>
</tr>
</tbody>
</table>

0 comments on commit 4740cba

Please sign in to comment.