-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaster.html
131 lines (95 loc) · 4.46 KB
/
master.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Popsicle server</title>
<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
<form id="popsicle_master" method="get">
<p><input type="submit" value="update popsicles" style="padding:1em 1em; background-color: red; color:#fff; text-transform: uppercase; font-weight:bold; font-size: .8em"></p>
<script type="text/javascript">
print_monitor_update_fields('red') ;
print_monitor_update_fields('green') ;
print_monitor_update_fields('blue') ;
function print_monitor_update_fields(color) {
document.write('<h1 id="' + color + '">' + color + '</h1>') ;
document.write('<div>' ) ;
monitor_count = 4;
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
document.write('<label for="' + color + monitor + '">monitor ' + monitor + ':</label> <input type="text" name="' + color + monitor + '" id="' + color + monitor + '" size="2" maxlength="1" value="">') ;
}
document.write('</div>' ) ;
}
</script>
<p><input type="submit" value="update popsicles" style="padding:1em 1em; background-color: red; color:#fff; text-transform: uppercase; font-weight:bold; font-size: .8em"></p>
</form>
<!-- load Firebase library -->
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.0/firebase-database.js"></script>
<script type="text/javascript">
console.log('initializing firebase db');
var config = {
apiKey: "AIzaSyCuVBF2WWt2tD53KO40S2dungEEx3I6yJQ",
authDomain: "anything-is-popsicle.firebaseapp.com",
databaseURL: "https://anything-is-popsicle.firebaseio.com",
projectId: "anything-is-popsicle",
storageBucket: "",
messagingSenderId: "604298729851"
};
var popsicle_app = firebase.initializeApp(config);
<!-- Commands go here. -->
// console.log("popsicle_app:",popsicle_app.name) ;
popsicle_db = firebase.database();
var color1 = 'red' ;
var color2 = 'green' ;
var color3 = 'blue' ;
var characters = firebase.database().ref('popsicles/');
characters.once('value').then( function (snapshot) {
var characters_array = snapshot.val() ;
// console.log("character:", characters_array);
// console.log ( characters_array.red[1]) ;
monitor_count = 4;
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
document.getElementById(color1+monitor).value = characters_array.red[monitor] ;
}
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
document.getElementById(color2+monitor).value = characters_array.green[monitor] ;
}
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
document.getElementById(color3+monitor).value = characters_array.blue[monitor] ;
}
});
var pop_master = document.getElementById('popsicle_master') ;
pop_master.addEventListener('submit',function (event) {
event.preventDefault() ;
console.log('submitted form') ;
var updates = {};
monitor_count = 4;
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
var new_value = document.getElementById(color1+monitor).value;
if (new_value !='' && new_value != ' ' ) {
// console.log ('new value for ' + color1 + monitor + ':',new_value);
updates['/popsicles/' + color1 + '/' + monitor] = new_value;
}
}
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
var new_value = document.getElementById(color2+monitor).value;
if (new_value !='' && new_value != ' ' ) {
// console.log ('new value for ' + color2 + monitor + ':',new_value);
updates['/popsicles/' + color2 + '/' + monitor] = new_value;
}
}
for (monitor = 1; monitor < monitor_count + 1; monitor++) {
var new_value = document.getElementById(color3+monitor).value;
if (new_value !='' && new_value != ' ' ) {
// console.log ('new value for ' + color3 + monitor + ':',new_value);
updates['/popsicles/' + color3 + '/' + monitor] = new_value;
}
}
firebase.database().ref().update(updates);
alert ('popsicles updated!') ;
}) ;
</script>
</body>
</html>