-
Notifications
You must be signed in to change notification settings - Fork 14
/
sensor.js
85 lines (71 loc) · 2.97 KB
/
sensor.js
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
function addRow(){
var sensorList, field_name_li, field_type_li, field_name_input, field_type_select,
float_option, string_option, bool_option;
fields = document.getElementById("field-list");
// Make field name input
field_name_input = document.createElement("input");
field_name_input.setAttribute("type","text");
field_name_input.setAttribute("name","field-name");
field_name_input.setAttribute("class","inline-block-child");
fields.appendChild(field_name_input);
//Make field type
field_type_select = document.createElement("select");
field_type_select.setAttribute("name", "field-type");
field_type_select.setAttribute("class", "inline-block-child");
float_option = document.createElement("option");
float_option.setAttribute("value", "float");
float_option.appendChild(document.createTextNode("Float"));
field_type_select.appendChild(float_option);
string_option = document.createElement("option");
string_option.setAttribute("value", "string");
string_option.appendChild(document.createTextNode("String"));
field_type_select.appendChild(string_option);
bool_option = document.createElement("option");
bool_option.setAttribute("value", "bool");
bool_option.appendChild(document.createTextNode("Boolean"));
field_type_select.appendChild(bool_option);
fields.appendChild(field_type_select);
// Make unit input
unit_input = document.createElement("input");
unit_input.setAttribute("type","text");
unit_input.setAttribute("name","field-unit")
unit_input.setAttribute("class", "inline-block-child");
fields.appendChild(unit_input);
var hr = document.createElement('hr');
fields.appendChild(hr);
}
var add_field_button = document.getElementById("addfieldbutton");
add_field_button.onclick = function() {
addRow();
}
/*
selectView displays the correct view of the "Add or Modify Sensors" page
-the default view is to show existing sensors
-if a user submits a new sensor which posts and reloads page, then the add new sensor view should remain
*/
function selectView() {
var newSensorDiv = document.getElementById("add-new-sensor");
var existingSensorDiv = document.getElementById("existing-sensors");
var modifyButton = document.getElementById("current-sensor-btn");
var newButton = document.getElementById("add-sensor-btn");
if (sessionStorage.getItem('viewing') == 'addingNew'){
newSensorDiv.style.display = "block";
existingSensorDiv.style.display = 'none';
modifyButton.style.backgroundColor = 'var(--light-accent)';
newButton.style.backgroundColor = 'var(--green)';
}
else {
newSensorDiv.style.display = "none";
existingSensorDiv.style.display = 'block';
modifyButton.style.backgroundColor = 'var(--green)';
newButton.style.backgroundColor = 'var(--light-accent)';
}
}
function displayCurrentSensors() {
sessionStorage.setItem('viewing', 'existing');
selectView()
}
function displayAddNewSensor() {
sessionStorage.setItem('viewing', 'addingNew');
selectView()
}