annotate web/views/set.tpl @ 492:23c6cf01d237

working kinda
author Matt Johnston <matt@ucc.asn.au>
date Tue, 11 Feb 2014 23:47:53 +0800
parents 46e327c00246
children f2838211f6ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
3 <head>
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
5 <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,minimum-scale=1">
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
6 <script src="jquery-2.1.0.min.js"></script>
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
7 <script src="jquery.mobile.custom.min.js"></script>
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 <script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 %include riot.min.js
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10 </script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 <style type="text/css">
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 span.no_selection {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 -webkit-user-select: none; // webkit (safari, chrome) browsers
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 -moz-user-select: none; // mozilla browsers
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 -khtml-user-select: none; // webkit (konqueror) browsers
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
17 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
18
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 body {
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
20 font-family: sans-serif;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
21 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
22
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 input {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 border: 2px solid transparent;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 border-radius: 4px;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 background-color: white;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 border-color: black;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 padding: 0;
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
29 font-size: 30pt;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
30 height: 34pt;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
31 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 input[type="button"] {
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
34 width: 34pt;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
35 margin-left: 4pt;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
36 -webkit-appearance: none;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
37 -moz-appearance: none;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
38 background:#fff;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
39 vertical-align: center;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 input[type="submit"] {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
43 margin-top: 1em;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
44 align: center;
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
45 width: 10em;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
47
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
48 input[type="text"], input[type="number"] {
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 text-align: center;
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
50 width: 4em;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
51 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
52
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
53 #savebox {
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
54 vertical-align: center;
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
55 width: 100%;
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
56 }
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
57
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
58 input[type="button"].onbutton {
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
59 background: #ccc;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
60 }
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
61
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
62 input[type="button"].yesno {
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
63 width: 2.5em;
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
64 }
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
65
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
66 input[type="button"]#savebutton {
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
67 width: 5em;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
68 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
69
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
70 .modified {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
71 color: #d00;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
72 font-weight: bold;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
73 }
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
74
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
75 .existing {
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
76 margin-top: 10pt;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
78
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
79 span.inputrow {
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
80 //vertical-align: center;
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
81 }
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
82
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
83 </style>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
84 <title>Set templog</title>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
85 </head>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88 <script type="html/num_input">
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 <div id="{id}">
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
90 <span class="existing">{title} <span id="oldvalue">{oldvaluetext}{unit}</span></span>
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
91 <br/>
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
92 <span class="inputrow">
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
93 <input type="number" class="input" name="input_{name}" />
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
94 <input type="button" class="button_down" value="-"/>
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
95 <input type="button" class="button_up" value="+"/>
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
96 </span>
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
97 </div>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
98 </script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 <script type="html/yesno_button">
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 <div id="{id}">
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
102 <span class="existing">{title} <span id="oldvalue">{oldvaluetext}</span></span>
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
103 <br/>
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
104 <span class="inputrow">
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
105 <input type="button" class="button_no yesno" value="No"/>
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
106 <input type="button" class="button_yes yesno" value="Yes"/>
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
107 </span>
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
108 </div>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
109 </script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
110
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
111 <script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
112
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
113 function Setter(params, csrf_blob) {
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
114 var self = $.observable(this);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
115
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 self.params = params;
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
117 self.csrf_blob = csrf_blob
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
118
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
119 $.each(self.params, function(idx, param) {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 param.id = "param_id_" + idx;
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
121 param.oldvalue = param.value
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
122 if (typeof(param.oldvalue) == "boolean")
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
123 {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
124 param.oldvaluetext = param.oldvalue ? "Yes" : "No";
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
125 }
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
126 else
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
127 {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
128 param.oldvaluetext = param.oldvalue;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
129 }
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
130 });
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
131
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
132 self.edit = function(param, newvalue) {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
133 param.value = newvalue;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 params[param.name] = param;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135 self.trigger("edit", param);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 self.adjust = function(param, updown) {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 // XXX increment
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
140 param.value += (param.amount*updown);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 self.trigger("edit", param);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
144 self.save = function() {
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
145 self.trigger("status", "Saving...")
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
146
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
147 var post_json = {};
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
148 post_json.csrf_blob = self.csrf_blob;
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
149 post_json.params =
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
150 self.params.map(function(v, idx, array) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
151 return {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
152 name: v.name,
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
153 value: v.value
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
154 };
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
155 });
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
156
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
157 var post_data = {data: JSON.stringify(post_json)};
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
158
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
159 var req = $.ajax({type: "POST",
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
160 url: "set/update",
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
161 data: post_data});
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
162
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
163 req.done(function(data, status, hdr) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
164 self.trigger("status", "Saved")
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
165 });
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
166
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
167 req.fail(function(data, status, hdr) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
168 self.trigger("status",
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
169 "Failed: " + data.status + ' '
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
170 + data.statusText + ' ' + data.responseText)
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
171 });
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
172 }
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
173 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
174
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
175 (function() { 'use strict';
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
176
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 var params = {{!inline_data}};
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
178 var csrf_blob = "{{!csrf_blob}}";
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
179 var allowed = {{allowed}};
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
180 window.setter = new Setter(params, csrf_blob);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182 var number_template = $("[type='html/num_input']").html();
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 var button_template = $("[type='html/yesno_button']").html();
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 setter.on("add", add);
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
186
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 setter.on("edit", function(param)
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
188 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
189 var el = $("#" + param.id);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 if (param.kind === "number")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
192 set_text_state(el, param);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 else if (param.kind === "yesno")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 {
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
196 set_button_state(el, param.value);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 }
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
198 var same;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
199 switch (typeof(param.oldvalue))
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
200 {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
201 case "boolean":
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
202 same = ((!param.value) == (!param.oldvalue));
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
203 break;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
204 case "number":
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
205 same = Math.abs(param.value - param.oldvalue) < 1e-3 * param.amount;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
206 break;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
207 default:
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
208 same = (param.value === param.oldvalue);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
209 }
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
210
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
211 $("#oldvalue", el).toggleClass("modified", !same);
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
212 });
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
213
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
214 setter.on("status", function(status) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
215 $('#status').text(status)
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
216 })
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
217
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
218 var root;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
219
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
220 window.onload = function() {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
221 // clear list and add new ones
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
222 root = $("#paramlist");
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
223
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
224 root.empty() && $.each(setter.params, function (idx, p) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
225 add(p);
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
226 })
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
227
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
228 if (!allowed) {
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
229 $("#savebutton").attr("disabled", true);
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
230 $('#status').text("No cert")
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
231 }
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
232
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
233 $("#savebutton").click(function() {
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
234 setter.save();
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
235 })
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
236 }
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
237
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
238 function set_text_state(el, param)
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
239 {
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
240 var input = $(".input", el);
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
241 var s = Number(param.value).toFixed(param.digits)
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
242 input.text(s).val(s)
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
243 }
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
244
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
245 function set_button_state(el, value)
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
246 {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
247 $(".button_yes", el).toggleClass("onbutton", value);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
248 $(".button_no", el).toggleClass("onbutton", !value);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
251 function add(param)
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 if (param.kind === "number")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 var el = $($.render(number_template, param)).appendTo(root);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 var input = $(".input", el);
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
257
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
258 input.keyup(function(e) {
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
259 if (e.which == 13)
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
260 {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
261 setter.edit(param, Number(this.value));
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
262 }
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
263 });
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
264
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
265 input.blur(function(e) {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
266 setter.edit(param, Number(this.value));
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
267 });
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
268
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
269 $(".button_up", el).on("vmousedown", function(e) {
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
270 e.preventDefault();
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
271 setter.adjust(param, 1);
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
272 this.blur()
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
273 });
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
274 $(".button_down", el).on("vmousedown", function(e) {
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
275 e.preventDefault();
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
276 setter.adjust(param, -1);
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
277 this.blur()
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
278 });
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
279
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
280 set_text_state(el, param);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
281 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
282 else if (param.kind === "yesno")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
283 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
284 var el = $($.render(button_template, param)).appendTo(root);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 var button_yes = $(".button_yes", el);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 var button_no = $(".button_no", el);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
288 button_yes.on("vmousedown", function(e) {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
289 setter.edit(param, true);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
290 this.blur()
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291 })
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
292
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
293 button_no.on("vmousedown", function(e) {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
294 setter.edit(param, false);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
295 this.blur()
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296 })
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
297
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
298 set_button_state(el, param.value);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
299 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
300 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
301
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
302 })()
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
304
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
305
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 </script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
308 <body>
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
309
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
310 <section id="paramlist">
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
311 </section>
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
312
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
313 <span id="savebox">
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
314 <input type="button" id="savebutton" value="Save"/>
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
315 <span id="status"></span>
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
316 </span>
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
317
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
318
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
319 </body>
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
320
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
321 </html>