-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwizard_ifthen.php
More file actions
465 lines (452 loc) · 15.7 KB
/
wizard_ifthen.php
File metadata and controls
465 lines (452 loc) · 15.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?php include 'header.php'; ?>
<script>
var statements=[];
var edit_id=null;
var edit=false;
$( function() {
var s_index=0;
$('#prev').button({
icon: "ui-icon-triangle-1-w"
}).click(function() {
localStorage.setItem("statements", JSON.stringify(statements));
if (localStorage.getItem("board")=="ra_cloud_hub")
{
window.location.href = "wizard_cloud_fallback.php";
}
else
{
if(localStorage.getItem("buzzer")=="true")
{
window.location.href = "wizard_buzzer.php";
}
else
{
if(localStorage.getItem("jebaoattachment")=="true")
{
window.location.href = "wizard_dcpumpattachment.php";
}
else
{
if(localStorage.getItem("rfexpansion")=="true")
{
window.location.href = "wizard_rfexpansion.php";
}
else
{
var num_ports=2;
if (localStorage.getItem("board")=="ra_star") num_ports=4;
if(localStorage.getItem("dimmingexpansion")=="true")
window.location.href = "wizard_dimmingexpansion_port.php?port=5";
else
window.location.href = "wizard_standarddimming_port.php?port="+num_ports;
}
}
}
}
});
$('#next').button({
icon: "ui-icon-triangle-1-e",
iconPosition: "end"
}).click(function() {
localStorage.setItem("statements", JSON.stringify(statements));
window.location.href = "wizard_ready.php";
});
$('#addnew').button({
icon: "ui-icon-circle-plus",
}).click(function() {
$('#ifthensettings').show();
$('#addnew').hide();
});
$('#save').button({
icon: "ui-icon-circle-check",
}).click(function() {
var settings_ok=false;
if ($('#ifoperator').val().indexOf("is")>=0 && $('#thenoperator').val().indexOf("turn")>=0) settings_ok=true;
if ($('#ifoperator').val().indexOf("is")==-1 && $('#thenoperator').val().indexOf("turn")==-1 && $('#ifvalue').val()!="" && $('#thenvalue').val()!="") settings_ok=true;
if ($('#ifoperator').val().indexOf("is")==-1 && $('#thenoperator').val().indexOf("turn")>=0 && $('#ifvalue').val()!="") settings_ok=true;
if ($('#ifoperator').val().indexOf("is")>=0 && $('#thenoperator').val().indexOf("turn")==-1 && $('#thenvalue').val()!="") settings_ok=true;
if (settings_ok)
{
if (edit)
{
edit=false;
console.log(edit_id);
statements[edit_id][1]=$('#params').val();
statements[edit_id][2]=$('#ifoperator').val();
statements[edit_id][3]=$('#ifvalue').val();
statements[edit_id][4]=$('#results').val();
statements[edit_id][5]=$('#thenoperator').val();
statements[edit_id][6]=$('#thenvalue').val();
build_statements();
}
else
{
if ($('#statements').html().indexOf("configured")!=-1) $('#statements').html("");
statements.push([s_index,$('#params').val(),$('#ifoperator').val(),$('#ifvalue').val(),$('#results').val(),$('#thenoperator').val(),$('#thenvalue').val()]);
build_statements();
s_index++;
}
$('#ifthensettings').hide();
$('#addnew').show();
}
else
{
$( "#dialog-message" ).dialog("open");
}
});
$('#params').selectmenu({
change: function( event, ui ) {
CheckIfValue(ui.item.value);
}
});
$('#results').selectmenu({
change: function( event, ui ) {
CheckThenValue(ui.item.value);
}
});
$('#ifvalue').change(function() {
CheckIfValue($('#params').val());
});
$('#thenvalue').change(function() {
CheckThenValue($('#results').val());
});
$('#ifoperator, #thenoperator').selectmenu();
$( "#dialog-message" ).dialog({
autoOpen: false,
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
$('#ifthensettings').hide();
if (localStorage.getItem("statements")!=null)
{
statements=JSON.parse(localStorage.getItem("statements"));
build_statements();
}
CheckIfValue($('#params').val());
CheckThenValue($('#results').val());
});
function build_statements()
{
if (statements.length>0)
{
$('#statements').html("");
for (a=0;a<statements.length;a++)
{
$('#statements').html($('#statements').html() + "<p class='statement_code' id='statement" + a + "'><span class='ui-button-icon ui-icon ui-icon-circle-minus statement_button' id='statement_delete_b" + a + "'></span><span class='ui-button-icon-space'> </span><span class='ui-button-icon ui-icon ui-icon-pencil statement_button' id='statement_edit_b" + a + "'></span><span class='ui-button-icon-space'> </span>if (" + statements[a][1] + " " + statements[a][2] + " " + statements[a][3] + ") then " + statements[a][4] + " " + statements[a][5] + " " + statements[a][6] + " " + "</p>");
}
$('.statement_button').click(function(event) {
if (event.target.id.indexOf("delete","")!=-1)
{
$('#' + event.target.id.replace("_delete_b","")).remove();
statements.splice(event.target.id.replace("statement_delete_b",""),1);
build_statements();
$('#ifthensettings').hide();
$('#addnew').show();
}
if (event.target.id.indexOf("edit","")!=-1)
{
var id=event.target.id.replace("statement_edit_b","");
edit=true;
edit_id=id;
$('#params').val(statements[id][1]).selectmenu("refresh");
$('#ifoperator').val(statements[id][2]).selectmenu("refresh");
$('#ifvalue').val(parseInt(statements[id][3]));
$('#results').val(statements[id][4]).selectmenu("refresh");
$('#thenoperator').val(statements[id][5]).selectmenu("refresh");
$('#thenvalue').val(parseInt(statements[id][6]));
$('#ifthensettings').show();
$('#addnew').hide();
}
});
}
else
{
$('#statements').html("<p>No if/then statements configured yet.</p>");
}
}
function CheckIfValue(whichselect)
{
if (whichselect.indexOf("Port")==-1)
{
$('#ifoperator option:not(:contains("is"))').prop("disabled",false);
if($('#ifoperator').val().indexOf("is")>=0)
$('#ifoperator option:contains("less than or equal to")').prop("selected",true);
$('#ifoperator option:contains("is")').prop("disabled",true);
$('#ifvalue').show();
}
else
{
$('#ifoperator option:contains("is")').prop("disabled",false);
if($('#ifoperator').val().indexOf("is")==-1)
$('#ifoperator option:contains("is On")').prop("selected",true);
$('#ifoperator option:not(:contains("is"))').prop("disabled",true);
$('#ifvalue').hide();
}
$('#ifoperator').selectmenu("refresh");
switch (whichselect)
{
case "Temperature 1":
case "Temperature 2":
case "Temperature 3":
$('#ifvalue').prop("step",0.1);
break;
case "pH":
case "pH Expansion":
$('#ifvalue').prop("step",0.01);
break;
case "Low ATO":
case "High ATO":
case "Alarm":
case "I/O Channel 0":
case "I/O Channel 1":
case "I/O Channel 2":
case "I/O Channel 3":
case "I/O Channel 4":
case "I/O Channel 5":
case "ATO Timeout":
case "Overheat":
case "Leak":
case "Bus Lock":
case "Feeding Mode":
case "Water Change Mode":
case "Lights On Mode":
$('#ifvalue').prop("max",1);
$('#ifvalue').prop("step",1);
if ($('#ifvalue').val()>1) $('#ifvalue').val(1);
break;
case "Month":
$('#ifvalue').prop("max",12);
$('#ifvalue').prop("step",1);
if ($('#ifvalue').val()>12) $('#ifvalue').val(12);
break;
case "Day":
$('#ifvalue').prop("max",31);
$('#ifvalue').prop("step",1);
if ($('#ifvalue').val()>31) $('#ifvalue').val(31);
break;
case "Hour (24hr)":
$('#ifvalue').prop("max",23);
$('#ifvalue').prop("step",1);
if ($('#ifvalue').val()>23) $('#ifvalue').val(23);
break;
case "Minute":
case "Second":
$('#ifvalue').prop("max",59);
$('#ifvalue').prop("step",1);
if ($('#ifvalue').val()>59) $('#ifvalue').val(59);
break;
case "Day of the week":
$('#ifvalue').prop("max",6);
$('#ifvalue').prop("step",1);
if ($('#ifvalue').val()>6) $('#ifvalue').val(6);
break;
case "Port 1":
break;
default:
$('#ifvalue').prop("step",1);
break;
}
}
function CheckThenValue(whichselect)
{
if (whichselect.indexOf("Port")==-1)
{
$('#thenoperator option:not(:contains("turn"))').prop("disabled",false);
if($('#thenoperator').val().indexOf("turn")>=0)
$('#thenoperator option:contains("less than or equal to")').prop("selected",true);
$('#thenoperator option:contains("turn")').prop("disabled",true);
$('#thenvalue').show();
}
else
{
$('#thenoperator option:contains("turn")').prop("disabled",false);
if($('#thenoperator').val().indexOf("turn")==-1)
$('#thenoperator option:contains("turn On")').prop("selected",true);
$('#thenoperator option:not(:contains("turn"))').prop("disabled",true);
$('#thenvalue').hide();
}
$('#thenoperator').selectmenu("refresh");
}
</script>
<div id="sidemenu" class="split split-horizontal">
<div id=logo></div>
<a href="/webwizard"><img src="image/left_arrow.png" align="absmiddle"> Back to Code View</a>
<button id=go_board class="ui-button ui-widget ui-corner-all go_buttons">Board</button>
<button id=go_memory class="ui-button ui-widget ui-corner-all go_buttons">Memory</button>
<button id=go_temperature class="ui-button ui-widget ui-corner-all go_buttons">Temperature</button>
<button id=go_expansion class="ui-button ui-widget ui-corner-all go_buttons">Expansion</button>
<button id=go_attachment class="ui-button ui-widget ui-corner-all go_buttons">Attachments</button>
<button id=go_mainrelay class="ui-button ui-widget ui-corner-all go_buttons">Main Relay</button>
<button id=go_relayexpansion class="ui-button ui-widget ui-corner-all go_buttons">Relay Expansion 1</button>
<button id=go_relayexpansion2 class="ui-button ui-widget ui-corner-all go_buttons">Relay Expansion 2</button>
<button id=go_standarddimming class="ui-button ui-widget ui-corner-all go_buttons">Standard Dimming</button>
<button id=go_dimmingexpansion class="ui-button ui-widget ui-corner-all go_buttons">Dimming Expansion</button>
<button id=go_rfexpansion class="ui-button ui-widget ui-corner-all go_buttons">RF Expansion</button>
<button id=go_dcpumpattachment class="ui-button ui-widget ui-corner-all go_buttons">DC Pump</button>
<button id=go_buzzer class="ui-button ui-widget ui-corner-all go_buttons">Buzzer</button>
<button id=go_ifthen class="ui-button ui-widget ui-corner-all go_buttons">If / Then</button>
<button id=go_ready class="ui-button ui-widget ui-corner-all go_buttons">Generate</button>
</div>
<div id="main" class="split split-horizontal">
<h1>Reef Angel Web Wizard</h1>
<h2>If/Then Statements</h2>
<div id="statements">
<p>No if/then statements configured yet.</p>
</div>
<div id=ifthensettings>
<p class="ifp"><span class="ifspan">If</span>
<select id="params">
<optgroup label="Parameters">
<option>Temperature 1</option>
<option>Temperature 2</option>
<option>Temperature 3</option>
<option>pH</option>
<option>Salinity</option>
<option>ORP</option>
<option>pH Expansion</option>
<option>PAR</option>
<option>Humidity</option>
<option>Water Level</option>
<option>Water Level 1</option>
<option>Water Level 2</option>
<option>Water Level 3</option>
<option>Water Level 4</option>
</optgroup>
<optgroup label="Input">
<option>Low ATO</option>
<option>High ATO</option>
<option>Alarm</option>
<option>I/O Channel 0</option>
<option>I/O Channel 1</option>
<option>I/O Channel 2</option>
<option>I/O Channel 3</option>
<option>I/O Channel 4</option>
<option>I/O Channel 5</option>
</optgroup>
<optgroup label="Output">
<option>Daylight Channel</option>
<option>Actinic Channel</option>
<option>Daylight 2 Channel</option>
<option>Actinic 2 Channel</option>
</optgroup>
<optgroup label="Flags">
<option>ATO Timeout</option>
<option>Overheat</option>
<option>Leak</option>
<option>Bus Lock</option>
<option>Feeding Mode</option>
<option>Water Change Mode</option>
<option>Lights On Mode</option>
</optgroup>
<optgroup label="Main Relay Box">
<option>Main Box Port 1</option>
<option>Main Box Port 2</option>
<option>Main Box Port 3</option>
<option>Main Box Port 4</option>
<option>Main Box Port 5</option>
<option>Main Box Port 6</option>
<option>Main Box Port 7</option>
<option>Main Box Port 8</option>
</optgroup>
<optgroup label="Expansion Relay Box">
<option>Exp Box Port 1</option>
<option>Exp Box Port 2</option>
<option>Exp Box Port 3</option>
<option>Exp Box Port 4</option>
<option>Exp Box Port 5</option>
<option>Exp Box Port 6</option>
<option>Exp Box Port 7</option>
<option>Exp Box Port 8</option>
</optgroup>
<optgroup label="Time">
<option>Year</option>
<option>Month</option>
<option>Day</option>
<option>Hour (24hr)</option>
<option>Minute</option>
<option>Second</option>
<option>Day of the week</option>
</optgroup>
</select>
<select id="ifoperator">
<option>less than or equal to</option>
<option>less than</option>
<option>equal to</option>
<option>different than</option>
<option>greater than</option>
<option>greater than or equal to</option>
<option>is On</option>
<option>is Off</option>
</select>
<input type="number" id="ifvalue" min="0" step="0.1">
</p>
<p class="ifp"><span class="ifspan">Then</span>
<select id="results">
<optgroup label="Main Relay Box">
<option>Main Box Port 1</option>
<option>Main Box Port 2</option>
<option>Main Box Port 3</option>
<option>Main Box Port 4</option>
<option>Main Box Port 5</option>
<option>Main Box Port 6</option>
<option>Main Box Port 7</option>
<option>Main Box Port 8</option>
</optgroup>
<optgroup label="Expansion Relay Box">
<option>Exp Box Port 1</option>
<option>Exp Box Port 2</option>
<option>Exp Box Port 3</option>
<option>Exp Box Port 4</option>
<option>Exp Box Port 5</option>
<option>Exp Box Port 6</option>
<option>Exp Box Port 7</option>
<option>Exp Box Port 8</option>
</optgroup>
<optgroup label="Dimming">
<option>Daylight Channel</option>
<option>Actinic Channel</option>
<option>Daylight 2 Channel</option>
<option>Actinic 2 Channel</option>
<option>Expansion Channel 0</option>
<option>Expansion Channel 1</option>
<option>Expansion Channel 2</option>
<option>Expansion Channel 3</option>
<option>Expansion Channel 4</option>
<option>Expansion Channel 5</option>
</optgroup>
<optgroup label="DC Pump">
<option>DC Pump Mode</option>
<option>DC Pump Speed</option>
<option>DC Pump Duration</option>
</optgroup>
</select>
<select id="thenoperator">
<option>turn On</option>
<option>turn Off</option>
<option>less than or equal to</option>
<option>less than</option>
<option>equal to</option>
<option>different than</option>
<option>greater than</option>
<option>greater than or equal to</option>
</select>
<input type="number" id="thenvalue" min="0" step="0.1">
</p>
<button id=save class="ui-button ui-widget ui-corner-all">Save</button>
</div>
<div>
<button id=addnew class="ui-button ui-widget ui-corner-all">Add New Statement</button>
</div>
<div id="dialog-message" title="Missing value">
<p>All fields required.</p>
</div>
<div id=footer>
<button id=prev class="ui-button ui-widget ui-corner-all">Prev</button>
<button id=next class="ui-button ui-widget ui-corner-all">Next</button>
</div>
</div>
<?php include 'footer.php'; ?>