-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.js
More file actions
171 lines (140 loc) · 5.44 KB
/
module.js
File metadata and controls
171 lines (140 loc) · 5.44 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
// Module JavaScript for UI elements
// Variables
/*
var maxSysRelays = 8;
var minReqRelays = 1;
*/
// Sub Functions
function digitalTemplate(n, typeArray) {
var html_digital = '<p class="sensorRow additional">'+
'<span class="num">'+
' <input type="hidden" name="digitalNum[]" value="' + n +'">' + n +
'</span>'+
'<span>'+
' <input id="digitalLabel' + n +'" type="text" name="digitalLabel[]" placeholder="Digital Label" class="digitalLabel" Value="Digital Sensor '+n+'" required>'+
' <select id="digitalType' + n +'" name="digitalType[]" class="digitalType" required>'+
' <option>Select Type</option>';
for (var key in typeArray) {
if (typeArray.hasOwnProperty(key)) {
html_digital += ' <option value="' + key + '">' + typeArray[key] + '</option>';
}
}
html_digital += ' </select>'+
' <input id="digitalGPIO0' + n +'" type="text" name="digitalGPIO[]" placeholder="GPIO" class="digitalGPIO" required>'+
' <select id="digitalActive0" name="digitalActive[]" class="digitalActive" required>'+
' <option value="low">Active Low</option><option value="high">Active High</option>'+
' </select>'+
'</span>'+
'<a href="#" id="removeDigital" title="Remove this digital sensor"><i class="icon-minus-sign"></i></a>'+
'</p>';
return html_digital;
}
function analogTemplate(n, typeArray) {
var html_analog = '<p class="sensorRow additional">'+
'<span class="num">'+
' <input type="hidden" name="analogNum[]" value="' + n +'">' + n +
'</span>'+
'<span>'+
' <input id="analogLabel' + n +'" type="text" name="analogLabel[]" placeholder="Analog Label" class="analogLabel" Value="Analog Sensor '+n+'" required>'+
' <select id="analogType' + n +'" name="analogType[]" class="analogType" required>'+
' <option>Select Type</option>';
for (var key in typeArray) {
if (typeArray.hasOwnProperty(key)) {
html_analog += ' <option value="' + key + '">' + typeArray[key] + '</option>';
}
}
html_analog += ' </select>'+
' <input id="analogGPIO' + n +'" type="text" name="analogGPIO[]" placeholder="GPIO" class="analogGPIO" required>'+
' <input id="analogHysterisis' + n +'" type="number" name="analogHysterisis[]" placeholder="Hysterisis" value="0" class="analogHysterisis" required>'+
'</span>'+
'<a href="#" id="removeAnalog" title="Remove this analog sensor"><i class="icon-minus-sign"></i></a>'+
'</p>';
return html_analog;
}
function updateDigitalCount(n) {
if(n==1) {
$('#digitalCount').html( n + ' Digital Senor' ); // singular
} else {
$('#digitalCount').html( n + ' Digital Senors' ); // plural
}
}
function updateAnalogCount(n) {
if(n==1) {
$('#analogCount').html( n + ' Analog Senor' ); // singular
} else {
$('#analogCount').html( n + ' Analog Senors' ); // plural
}
}
/*
function checkMaxRelay(currentRelays, sysMax, inRelays, outRelays) {
if (currentRelays >= inRelays || currentRelays >=outRelays) {
alert("Sorry, but you cannot add anymore relays because you do not have the required audio inputs and outputs required to suprelay these relays. The system has detected that you have "+inRelays+" audio input channel(s) and "+outRelays+" audio output channel(s). Please add more suprelayed audio devices first to be able to add more relays.");
return false;
}
if (currentRelays >= sysMax) {
alert("Sorry, but you cannot add anymore relays because you already have the maximum number of relays the system will suprelay.");
return false;
}
return true;
}
*/
/*
function checkMinRelay(currentRelays, minRelays) {
if (currentRelays <= minRelays) {
alert("Sorry, but you cannot remove any more relays because this system requires a minimum of "+minRelays+" relay(s).");
return false;
}
return true;
}
*/
// Main Scripts
$(window).load(function(){
$(function() {
// Get Digital Types
var digitalTypeArray = $('#digitalTypeArray').text();
var digitalTypeArray = JSON.parse(digitalTypeArray);
// Get Analog Types
var analogTypeArray = $('#analogTypeArray').text();
var analogTypeArray = JSON.parse(analogTypeArray);
/*
var inputRelays = $('#detectedRX').val();
var outputRelays = $('#detectedTX').val();
*/
var d = $('#digitalWrap p').size();
updateDigitalCount(d);
var a = $('#analogWrap a').size();
updateAnalogCount(a);
$('#addDigital').live('click', function() {
// if(checkMaxRelay(d, maxSysRelays, inputRelays, outputRelays)) {
d++;
$(digitalTemplate(d, digitalTypeArray)).appendTo('#digitalWrap');
updateDigitalCount(d);
// }
return false;
});
$('#removeDigital').live('click', function() {
// if(checkMinRelay(d, minReqRelays)) {
$(this).parents('p').remove();
d--;
updateDigitalCount(d);
// }
return false;
});
$('#addAnalog').live('click', function() {
// if(checkMaxRelay(a, maxSysRelays, inputRelays, outputRelays)) {
a++;
$(analogTemplate(a, analogTypeArray)).appendTo('#analogWrap');
updateAnalogCount(a);
// }
return false;
});
$('#removeAnalog').live('click', function() {
// if(checkMinRelay(i, minReqRelays)) {
$(this).parents('p').remove();
a--;
updateAnalogCount(a);
// }
return false;
});
});
});//]]>