annotate web/views/set.tpl @ 188:ae5efca89001

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