/
main.scala.html
375 lines (317 loc) · 11.5 KB
/
main.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
@(template:QuerkiTemplate.QuerkiTemplate, title: String, rc:PlayRequestContext, addStyles:Boolean = false, forms:Seq[Form[_]] = Seq.empty)(content: Html)
@import models.system._
@import play.api.Logger
@import helper._
@import querki.values.SpaceState
@space = @{ rc.state }
@thing = @{ rc.thing }
@nav = @{ NavSection.nav(rc) }
@formErrors = @{
val formsWithErrors = forms.filter(_.hasErrors)
if (formsWithErrors.isEmpty)
None
else
Some(formsWithErrors.flatMap(errorForm => errorForm.errors.map(error => "'" + errorForm(error.key).value.getOrElse("") + "' is not a legal value")).mkString(", ") + " (see below)")
}
@errors = @{
val flash = rc.request.flash
flash.get("error") orElse rc.error orElse formErrors
}
@infoMsg = @{
rc.request.flash.get("info")
}
@requester = @{ rc.requester }
@ownerId = @{
space match {
case Some(s) => s.owner.toThingId
case None => ""
}
}
@spaceId = @{
space match {
case Some(s) => s.toThingId
case None => ""
}
}
@createOptGroups(s:SpaceState) = {
<optgroup label="Models in @s.displayName">
@for(model <- s.models.toSeq.sortBy(_.displayName)) {
<option value="@model.toThingId">@model.displayName</option>
}
</optgroup>
@s.app.map { app => @createOptGroups(app) }
}
@createForm(s:SpaceState) = {
<div id="create-dialog" title="Create a Thing">
<p>Choose which kind of Thing to create:</p>
<select name="newModel" id="newModel">
<option value="">Choose a Model</option>
@createOptGroups(s)
</select>
</div>
}
@createFormInSpace = @{
space match {
case Some(s) => createForm(s)
case None => {}
}
}
@displayNavLink(display:String, url:Call, idStr:String, enabled:Boolean) = {
@if(enabled) {
<li><a href="@url" @idStr>@Html(display)</a></li>
} else {
<li class="disabled"><a>@Html(display)</a></li>
}
}
@displayNavDivider = {
<li class="divider"></li>
}
@strippedTitle(title:String) = @{
title.filter(c => c.isLetterOrDigit || c == ' ')
}
@displayNavSection(title:String, links:Seq[Navigable]) = {
@defining(strippedTitle(title)) { stripped =>
<li class="dropdown"><a data-target="#@stripped" href="#@stripped" class="dropdown-toggle" data-toggle="dropdown">@title <b class="caret"></b></a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">@for(link <- links) {
@displayNavigable(link)}
</ul>
</li>
}
}
@displayNavigable(section:Navigable) = @{
section match {
case NavLink(display, url, id, enabled) => {
val idStr = id match {
case Some(i) => " id=" + i
case None => ""
}
displayNavLink(display, url, idStr, enabled)
}
case NavSection(title, links) => displayNavSection(title, links)
case NavDivider => displayNavDivider
}
}
<!DOCTYPE html>
@*********************
* This is the main system template. We'll get fancier as things go,
* but by and large, all universal template shell should go here.
*
* Most of this is adapted from Bootstrap's "fluid" example:
* http://twitter.github.com/bootstrap/examples/fluid.html
********************@
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@Html(title)</title>
<!-- TODO: we need to make this CSS responsive! But that may require jQuery Mobile... -->
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/jquery-ui-1.10.0.custom.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/jquery.ui.menubar.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.css")">
<!-- This padding is needed for the top navbar. Bootstrap doc says to put it between the main and responsive CSS: -->
<style>
body {
padding-top: 40px;
}
</style>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap-responsive.css")">
<link type="text/css" rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/jquery.selectboxit/3.6.0/jquery.selectBoxIt.css" />
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/manifest.css")">
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<!-- TODO: these should come from a jQuery CDN, instead of locally -->
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.js")"></script>
<script src="@routes.Assets.at("javascripts/jquery.manifest.min.js")"></script>
<script src="@routes.Assets.at("javascripts/jquery-ui-1.10.0.custom.js")"></script>
<script src="@routes.Assets.at("javascripts/jquery.ui.menubar.js")"></script>
<script src="@routes.Assets.at("javascripts/bootstrap.js")"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.selectboxit/3.6.0/jquery.selectBoxIt.min.js"></script>
<script src="@routes.Assets.at("javascripts/underscore-min.js")"></script>
<script src="@routes.Assets.at("javascripts/jquery.autosize-min.js")"></script>
<script src="@routes.Assets.at("javascripts/querki-common.js")"></script>
<script type="text/javascript" src='@routes.Application.javascriptRoutes()'></script>
@PageEventManager.addHeaders(rc, template)
<link rel="shortcut icon" href="@routes.Assets.at("images/Capital.png")">
<script>
$(function() {
// Bootstrap and jQuery UI both have conflicting .button functions. This is a
// Bootstrap function to turn it into "btn" instead. See:
// https://github.com/twitter/bootstrap/issues/6094
// var btn = $.fn.button //.noConflict()
// $.fn.btn = btn
// At this point, we are now preferring Bootstrap buttons instead, and disabling
// the jQuery UI ones.
$("#querkiBar").menubar({
autoExpand: false,
menuIcon: true,
buttons: false
});
$("#identityMenu").position({
my: "right",
at: "right"
});
@if(space.isDefined) {
$("#createThing").on("click", function(evt) {
$("#create-dialog").dialog("open");
});
$("#create-dialog").dialog({
autoOpen:false,
height: 300,
width: 350,
modal: true,
buttons: {
"Create": function () {
var modelId = $("#newModel :selected").first().val()
if (modelId && (modelId.length > 0)) {
// TBD: Bit of an abstraction break here -- the Javascript needs to know the URL syntax for
// model creation. Can we do this better somehow?
window.location = "@routes.Application.createThing(rc.ownerHandle, space.get.toThingId, None)" + "?model=" + modelId;
} else {
// TODO: The Create button should really be disabled unless a legit option
// is picked; not quite sure how to do that in jQuery UI.
}
},
"Cancel": function () {
$(this).dialog("close");
}
},
close: function () {
}
});
}
@if(thing.isDefined) {
$("#deleteThing").on("click", function(evt) {
$("#delete-dialog").dialog("open");
return false;
});
$("#delete-dialog").dialog({
autoOpen:false,
height: 200,
width: 350,
modal: true,
buttons: {
"Delete": function () {
window.location = "@routes.Application.deleteThing(rc.ownerHandle, space.get.toThingId, thing.get.toThingId)";
},
"Cancel": function () {
$(this).dialog("close");
}
},
close: function () {
}
});
}
finalSetup("@ownerId", "@spaceId", $('body'));
});
</script>
<style>
#querkiBar { margin: 0 0 0 0; }
/*
* Workaround for what seems to be a bug in Bootstrap's theming: this is the text color for the
* links in the collapsed menus. Bootstrap produces this as grayDark, and I can't figure out how
* to make it right.
*/
.nav-collapse .nav > li > a,
.nav-collapse .dropdown-menu a {
color: #ffffff;
}
.navbar .brand {
padding-top: 5px;
padding-bottom: 5px;
}
body {
margin: 0;
}
.guts {
margin: 8px;
}
._menuSection {
color: white;
}
.sortableList { list-style-type: none; margin: 0; padding: 0; width: 60%; }
.sortableList li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
.sortableList li span { position: absolute; margin-left: -1.3em; }
.statusLine {
display: none;
position: absolute;
left: 30px;
top: 40px;
z-index: 100;
}
</style>
</head>
<body>
<div id="statusLine" class="statusLine"><span id="statusText" class="label label-info">Status</span></div>
@if(!rc.chromeless) {
<!-- Bootstrap menus -->
<div class="container">
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<!-- This is the bit that takes over when we collapse a small screen -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="@routes.Application.index"><img src="@routes.Assets.at("images/Logo-menubar.png")"></a>
<div class="nav-collapse collapse">
<ul class="nav">
@for(section <- nav.sections) {
@displayNavigable(section)
}
</ul>
<ul class="nav pull-right">
@defining(NavSection.loginNav(rc)) { section =>
@displayNavigable(section)
}
</ul>
@if(space.isDefined) {
@form(routes.Application.search(rc.ownerHandle, space.get.toThingId), 'class -> "navbar-search pull-right") {
<input id="searchInput" name="searchInput" type="text" class="search-query" placeholder="Search">
}
}
</div>
</div>
</div>
</div>
</div>
}
@createFormInSpace
@if(thing.isDefined) {
<div id="delete-dialog" title="Confirm Delete">
<p><b>Are you sure you want to delete @Html(thing.get.displayName)? There is currently no way to get it back!</b></p>
</div>
}
<!-- This container stuff is likely to go into a lower-level, Space-rendering template -->
<div class="guts container-fluid">
<div class="row-fluid">
<div class="querki-content span12">
@errors match {
case None => {}
case Some(msg) => {
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong>Error:</strong> @msg
</div>
}
}
@infoMsg match {
case None => {}
case Some(msg) => {
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">x</button>
@msg
</div>
}
}
@content
</div><!--/span12-->
</div><!--/row-->
@if(!rc.chromeless) {
<hr>
<footer>
<p>© Querki 2013</p>
</footer>
}
</div><!--/.fluid-container-->
</body>
</html>