annotate web/views/set.tpl @ 302:ef407d48cbe5

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