annotate web/views/set.tpl @ 542:30628aa50a10

use base64 data, faster
author Matt Johnston <matt@ucc.asn.au>
date Thu, 21 May 2015 00:00:10 +0800
parents 0833f0aaf159
children 61269311ed3d
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 }
524
0833f0aaf159 fixed point for old values
Matt Johnston <matt@ucc.asn.au>
parents: 492
diff changeset
126 else if (param.kind == "number")
0833f0aaf159 fixed point for old values
Matt Johnston <matt@ucc.asn.au>
parents: 492
diff changeset
127 {
0833f0aaf159 fixed point for old values
Matt Johnston <matt@ucc.asn.au>
parents: 492
diff changeset
128 param.oldvaluetext = Number(param.oldvalue).toFixed(param.digits)
0833f0aaf159 fixed point for old values
Matt Johnston <matt@ucc.asn.au>
parents: 492
diff changeset
129 }
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
130 else
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
131 {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
132 param.oldvaluetext = param.oldvalue;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
133 }
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
134 });
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
135
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
136 self.edit = function(param, newvalue) {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
137 param.value = newvalue;
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 params[param.name] = param;
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 self.trigger("edit", param);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142 self.adjust = function(param, updown) {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 // XXX increment
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
144 param.value += (param.amount*updown);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
145 self.trigger("edit", param);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
146 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
147
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
148 self.save = function() {
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
149 self.trigger("status", "Saving...")
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
150
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
151 var post_json = {};
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
152 post_json.csrf_blob = self.csrf_blob;
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
153 post_json.params =
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
154 self.params.map(function(v, idx, array) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
155 return {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
156 name: v.name,
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
157 value: v.value
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 });
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
160
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
161 var post_data = {data: JSON.stringify(post_json)};
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 var req = $.ajax({type: "POST",
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
164 url: "set/update",
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
165 data: post_data});
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.done(function(data, status, hdr) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
168 self.trigger("status", "Saved")
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
169 });
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
170
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
171 req.fail(function(data, status, hdr) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
172 self.trigger("status",
492
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
173 "Failed: " + data.status + ' '
23c6cf01d237 working kinda
Matt Johnston <matt@ucc.asn.au>
parents: 489
diff changeset
174 + data.statusText + ' ' + data.responseText)
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
175 });
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
176 }
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
177 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
178
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
179 (function() { 'use strict';
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 var params = {{!inline_data}};
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
182 var csrf_blob = "{{!csrf_blob}}";
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
183 var allowed = {{allowed}};
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
184 window.setter = new Setter(params, csrf_blob);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
186 var number_template = $("[type='html/num_input']").html();
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
187 var button_template = $("[type='html/yesno_button']").html();
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 setter.on("add", add);
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
190
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
191 setter.on("edit", function(param)
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
192 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
193 var el = $("#" + param.id);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
194 if (param.kind === "number")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
195 {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
196 set_text_state(el, param);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
197 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
198 else if (param.kind === "yesno")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
199 {
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
200 set_button_state(el, param.value);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201 }
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
202 var same;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
203 switch (typeof(param.oldvalue))
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
204 {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
205 case "boolean":
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
206 same = ((!param.value) == (!param.oldvalue));
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
207 break;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
208 case "number":
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
209 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
210 break;
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
211 default:
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
212 same = (param.value === param.oldvalue);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
213 }
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
214
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
215 $("#oldvalue", el).toggleClass("modified", !same);
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
216 });
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 setter.on("status", function(status) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
219 $('#status').text(status)
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
220 })
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
221
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
222 var root;
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 window.onload = function() {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
225 // clear list and add new ones
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
226 root = $("#paramlist");
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
227
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
228 root.empty() && $.each(setter.params, function (idx, p) {
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
229 add(p);
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
230 })
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
231
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
232 if (!allowed) {
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
233 $("#savebutton").attr("disabled", true);
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
234 $('#status').text("No cert")
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
235 }
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
236
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
237 $("#savebutton").click(function() {
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
238 setter.save();
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
239 })
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
240 }
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
241
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
242 function set_text_state(el, param)
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 var input = $(".input", el);
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
245 var s = Number(param.value).toFixed(param.digits)
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
246 input.text(s).val(s)
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
247 }
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
248
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
249 function set_button_state(el, value)
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250 {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
251 $(".button_yes", el).toggleClass("onbutton", value);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
252 $(".button_no", el).toggleClass("onbutton", !value);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 }
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 function add(param)
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 if (param.kind === "number")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 var el = $($.render(number_template, param)).appendTo(root);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
260 var input = $(".input", el);
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
261
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
262 input.keyup(function(e) {
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
263 if (e.which == 13)
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 setter.edit(param, Number(this.value));
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
266 }
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
267 });
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
268
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
269 input.blur(function(e) {
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
270 setter.edit(param, Number(this.value));
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
271 });
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
272
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
273 $(".button_up", el).on("vmousedown", function(e) {
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
274 e.preventDefault();
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
275 setter.adjust(param, 1);
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
276 this.blur()
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
277 });
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
278 $(".button_down", el).on("vmousedown", function(e) {
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
279 e.preventDefault();
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
280 setter.adjust(param, -1);
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
281 this.blur()
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
282 });
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
283
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
284 set_text_state(el, param);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
285 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
286 else if (param.kind === "yesno")
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
287 {
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
288 var el = $($.render(button_template, param)).appendTo(root);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
289 var button_yes = $(".button_yes", el);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
290 var button_no = $(".button_no", el);
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
291
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
292 button_yes.on("vmousedown", function(e) {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
293 setter.edit(param, true);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
294 this.blur()
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
295 })
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
296
489
46e327c00246 gets current params
Matt Johnston <matt@ucc.asn.au>
parents: 488
diff changeset
297 button_no.on("vmousedown", function(e) {
484
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
298 setter.edit(param, false);
4a51e2bf689b a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 483
diff changeset
299 this.blur()
482
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
483
93af94e6bd9d param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 482
diff changeset
302 set_button_state(el, param.value);
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
303 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
304 }
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
305
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
306 })()
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
307
487
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
308
931408ce71d9 working OK
Matt Johnston <matt@ucc.asn.au>
parents: 485
diff changeset
309
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
310 </script>
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
311
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
312 <body>
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
313
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
314 <section id="paramlist">
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
315 </section>
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
316
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
317 <span id="savebox">
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
318 <input type="button" id="savebutton" value="Save"/>
488
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
319 <span id="status"></span>
4792e9910cde watcher script
Matt Johnston <matt@ucc.asn.au>
parents: 487
diff changeset
320 </span>
485
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
321
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
322
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
323 </body>
d68af9e84485 working
Matt Johnston <matt@ucc.asn.au>
parents: 484
diff changeset
324
482
9950ffa9a79b set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
325 </html>