annotate web/views/set.tpl @ 191:8318d50d766d

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