annotate web/views/set.tpl @ 184:cbe14244a372

a few fixes
author Matt Johnston <matt@ucc.asn.au>
date Thu, 06 Feb 2014 20:35:43 +0800
parents 177f616893e6
children adbf70d1449f
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>
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
7 <script>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
8 %include riot.min.js
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
9 </script>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
10
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
11 <style type="text/css">
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
12 span.no_selection {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
13 -webkit-user-select: none; // webkit (safari, chrome) browsers
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
14 -moz-user-select: none; // mozilla browsers
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
15 -khtml-user-select: none; // webkit (konqueror) browsers
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
16 }
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 body {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
19 font-family: "sans-serif";
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
20 }
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 input {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
23 border: 2px solid transparent;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
24 border-radius: 4px;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
25 background-color: white;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
26 border-color: black;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
27 padding: 0;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
28 font-size: 80%;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
29 }
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 input[type="button"] {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
32 width: 4em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
33 height: 4em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
34 margin-left: 0.5em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
35 }
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 input[type="submit"] {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
38 width: 10em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
39 height: 4em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
40 margin-top: 1em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
41 align: center;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
42 }
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 input[type="text"] {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
45 height: 4em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
46 text-align: center;
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
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
49 .onbutton {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
50 background-color: #cdf;
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
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
53 .modified {
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
54 color: #d00;
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
55 font-weight: bold;
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
56 }
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
57
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
58 .existing {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
59 margin-top: 1em;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
60 font-size: 70%;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
61 }
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
62
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
63 </style>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
64 <title>Set templog</title>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
65 </head>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
66
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
67 <body>
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 <section id="paramlist">
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
70 </section>
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
71
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
72 <div id="jsontest">
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
73 </div>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
74
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
75 <input type="button" id="savebutton" value="Save"/>
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
76
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
77 </body>
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 <script type="html/num_input">
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
80 <div id="{id}">
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
81 <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
82 <br/>
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
83 <input type="text" class="input" name="input_{name}" />
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
84 <input type="button" class="button_down" value="-"/>
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
85 <input type="button" class="button_up" value="+"/>
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
86 </div>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
87 </script>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
88
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
89 <script type="html/yesno_button">
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
90 <div id="{id}">
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
91 <span class="existing">{title} <span id="oldvalue">{oldvaluetext}</span></span>
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
92 <br/>
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
93 <input type="button" class="button_no" value="No"/>
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
94 <input type="button" class="button_yes" value="Yes"/>
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
95 </div>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
96 </script>
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>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
99
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
100 function Setter(params) {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
101 var self = $.observable(this);
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 self.params = params;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
104
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
105 $.each(self.params, function(idx, param) {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
106 param.id = "param_id_" + idx;
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
107 param.oldvalue = param.value
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
108 if (typeof(param.oldvalue) == "boolean")
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 ? "Yes" : "No";
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
111 }
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
112 else
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
113 {
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
114 param.oldvaluetext = param.oldvalue;
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
115 }
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
116 });
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
117
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
118 self.edit = function(param, newvalue) {
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
119 param.value = newvalue;
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
120 params[param.name] = param;
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
121 self.trigger("edit", param);
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
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
124 self.adjust = function(param, updown) {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
125 // XXX increment
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
126 param.value += (param.amount*updown);
182
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
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
130 self.save = function() {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
131 var j = JSON.stringify(self.params);
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
132 self.trigger("saved", j)
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
133 }
182
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
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
136 (function() { 'use strict';
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
137
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
138 var params = {{!inline_data}};
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
139 window.setter = new Setter(params);
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
140
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
141 var root = $("#paramlist");
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
142
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
143 var number_template = $("[type='html/num_input']").html();
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
144 var button_template = $("[type='html/yesno_button']").html();
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 setter.on("add", add);
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
147
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
148 setter.on("edit", function(param)
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
149 {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
150 var el = $("#" + param.id);
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
151 if (param.kind === "number")
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
152 {
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
153 set_text_state(el, param);
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 else if (param.kind === "yesno")
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
156 {
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
157 set_button_state(el, param.value);
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
158 }
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
159 var same;
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
160 switch (typeof(param.oldvalue))
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
161 {
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
162 case "boolean":
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
163 same = ((!param.value) == (!param.oldvalue));
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
164 break;
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
165 case "number":
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
166 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
167 break;
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
168 default:
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
169 same = (param.value === param.oldvalue);
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
170 }
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
171
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
172 $("#oldvalue", el).toggleClass("modified", !same);
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
173 });
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
174
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
175 setter.on("saved", function(j) {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
176 $("#jsontest").text(j);
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
177 });
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
178
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
179
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
180
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
181 $.route(function(hash) {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
183 // clear list and add new ones
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
184 root.empty() && $.each(setter.params, function (idx, p) {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
185 add(p);
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
186
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
187 $("#savebutton").click(function() {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
188 setter.save();
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
189 })
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
190 })
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
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
193 function set_text_state(el, param)
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
194 {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
195 var input = $(".input", el);
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
196 var s = Number(param.value).toFixed(param.digits)
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
197 input.text(s).val(s)
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
198 }
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
199
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
200 function set_button_state(el, value)
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
201 {
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
202 $(".button_yes", el).toggleClass("onbutton", value);
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
203 $(".button_no", el).toggleClass("onbutton", !value);
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
204 }
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
205
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
206 function add(param)
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
207 {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
208 if (param.kind === "number")
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
209 {
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
210 var el = $($.render(number_template, param)).appendTo(root);
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
211 var input = $(".input", el);
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
212
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
213 input.keyup(function(e) {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
214 if (e.which == 13)
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
215 {
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
216 setter.edit(param, Number(this.value));
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
217 }
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
218 });
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
219
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
220 input.blur(function(e) {
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
221 setter.edit(param, Number(this.value));
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
222 });
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
223
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
224 $(".button_up", el).click(function() {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
225 setter.adjust(param, 1);
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
226 this.blur()
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 $(".button_down", el).click(function() {
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
229 setter.adjust(param, -1);
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
230 this.blur()
183
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
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
233 set_text_state(el, param);
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
234 }
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
235 else if (param.kind === "yesno")
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 var el = $($.render(button_template, param)).appendTo(root);
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
238 var button_yes = $(".button_yes", el);
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
239 var button_no = $(".button_no", el);
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 button_yes.click(function() {
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
242 setter.edit(param, true);
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
243 this.blur()
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
244 })
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 button_no.click(function() {
184
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
247 setter.edit(param, false);
cbe14244a372 a few fixes
Matt Johnston <matt@ucc.asn.au>
parents: 183
diff changeset
248 this.blur()
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
249 })
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
250
183
177f616893e6 param editor roughly working
Matt Johnston <matt@ucc.asn.au>
parents: 182
diff changeset
251 set_button_state(el, param.value);
182
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
252 }
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
253 }
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
254
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
255 })()
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
256
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
257 </script>
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
258
e731c0d30b09 set nearly working
Matt Johnston <matt@ucc.asn.au>
parents:
diff changeset
259 </html>