1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
@(currentPage: io.ebean.PagedList[Computer], currentSortBy: String, currentOrder: String, currentFilter: String)
@****************************************
* Helper generating navigation links *
****************************************@
@link(newPage:Int, newSortBy:String) = @{
var sortBy = currentSortBy
var order = currentOrder
if(newSortBy != null) {
sortBy = newSortBy
if(currentSortBy == newSortBy) {
if(currentOrder == "asc") {
order = "desc"
} else {
order = "asc"
}
} else {
order = "asc"
}
}
// Generate the link
routes.HomeController.list(newPage, sortBy, order, currentFilter)
}
@**********************************
* Helper generating table headers *
***********************************@
@header(key:String, title:String) = {
<th class="@key.replace(".","_") header @if(currentSortBy == key) { @{if(currentOrder == "asc") "headerSortDown" else "headerSortUp" } }">
<a href="@link(0, key)">@title</a>
</th>
}
@main {
<h1 id="homeTitle">@Messages("computers.list.title", currentPage.getTotalCount)</h1>
@if(flash.containsKey("success")) {
<div class="alert-message warning">
<strong>Done!</strong> @flash.get("success")
</div>
}
<div id="actions">
<form action="@link(0, "name")" method="GET">
<input type="search" id="searchbox" name="f" value="@currentFilter" placeholder="Filter by computer name...">
<input type="submit" id="searchsubmit" value="Filter by name" class="btn primary">
</form>
<a class="btn success" id="add" href="@routes.HomeController.create()">Add a new computer</a>
</div>
@if(currentPage.getTotalCount == 0) {
<div class="well">
<em>Nothing to display</em>
</div>
} else {
<table class="computers zebra-striped">
<thead>
<tr>
@header("name", "Computer name")
@header("introduced", "Introduced")
@header("discontinued", "Discontinued")
@header("company.name", "Company")
</tr>
</thead>
<tbody>
@for(computer <- currentPage.getList.asScala) {
<tr>
<td><a href="@routes.HomeController.edit(computer.id)">@computer.name</a></td>
<td>
@if(computer.introduced == null) {
<em>-</em>
} else {
@computer.introduced.format("dd MMM yyyy")
}
</td>
<td>
@if(computer.discontinued == null) {
<em>-</em>
} else {
@computer.discontinued.format("dd MMM yyyy")
}
</td>
<td>
@if(computer.company == null) {
<em>-</em>
} else {
@computer.company.name
}
</td>
</tr>
}
</tbody>
</table>
<div id="pagination" class="pagination">
<ul>
@if(currentPage.hasPrev) {
<li class="prev">
<a href="@link(currentPage.getPageIndex - 1, null)">← Previous</a>
</li>
} else {
<li class="prev disabled">
<a>← Previous</a>
</li>
}
<li class="current">
<a>Displaying @currentPage.getDisplayXtoYofZ(" to "," of ")</a>
</li>
@if(currentPage.hasNext) {
<li class="next">
<a href="@link(currentPage.getPageIndex + 1, null)">Next →</a>
</li>
} else {
<li class="next disabled">
<a>Next →</a>
</li>
}
</ul>
</div>
}
}