This repository has been archived by the owner on Oct 24, 2018. It is now read-only.
/
list.scala.html
123 lines (98 loc) · 4.09 KB
/
list.scala.html
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
@(currentPage: Page[(Computer, Option[Company])], currentOrderBy: Int, currentFilter: String)(implicit flash: play.api.mvc.Flash)
@****************************************
* Helper generating navigation links *
****************************************@
@link(newPage: Int, newOrderBy: Option[Int] = None) = @{
routes.Application.list(newPage, newOrderBy.map { orderBy =>
if(orderBy == scala.math.abs(currentOrderBy)) -currentOrderBy else orderBy
}.getOrElse(currentOrderBy), currentFilter)
}
@**********************************
* Helper generating table headers *
***********************************@
@header(orderBy: Int, title: String) = {
<th class="col@orderBy header @if(scala.math.abs(currentOrderBy) == orderBy) @{if(currentOrderBy < 0) "headerSortDown" else "headerSortUp"}">
<a href="@link(0, Some(orderBy))">@title</a>
</th>
}
@main {
<h1>@Messages("computers.list.title", currentPage.total)</h1>
@flash.get("success").map { message =>
<div class="alert-message warning">
<strong>Done!</strong> @message
</div>
}
<div id="actions">
@helper.form(action=routes.Application.list()) {
<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">
}
<a class="btn success" id="add" href="@routes.Application.create()">Add a new computer</a>
</div>
@Option(currentPage.items).filterNot(_.isEmpty).map { computers =>
<table class="computers zebra-striped">
<thead>
<tr>
@header(2, "Computer name")
@header(3, "Introduced")
@header(4, "Discontinued")
@header(5, "Company")
</tr>
</thead>
<tbody>
@computers.map {
case (computer, company) => {
<tr>
<td><a href="@routes.Application.edit(computer.id)">@computer.name</a></td>
<td>
@computer.introduced.map(_.format("dd MMM yyyy")).getOrElse { <em>-</em> }
</td>
<td>
@computer.discontinued.map(_.format("dd MMM yyyy")).getOrElse { <em>-</em> }
</td>
<td>
@company match {
case Some(c) => {
@c.name
}
case None => {
<em>-</em>
}
}
</td>
</tr>
}
}
</tbody>
</table>
<div id="pagination" class="pagination">
<ul>
@currentPage.prev.map { page =>
<li class="prev">
<a href="@link(page)">← Previous</a>
</li>
}.getOrElse {
<li class="prev disabled">
<a>← Previous</a>
</li>
}
<li class="current">
<a>Displaying @(currentPage.offset + 1) to @(currentPage.offset + computers.size) of @currentPage.total</a>
</li>
@currentPage.next.map { page =>
<li class="next">
<a href="@link(page)">Next →</a>
</li>
}.getOrElse {
<li class="next disabled">
<a>Next →</a>
</li>
}
</ul>
</div>
}.getOrElse {
<div class="well">
<em>Nothing to display</em>
</div>
}
}