-
Notifications
You must be signed in to change notification settings - Fork 0
/
food-service.js
179 lines (163 loc) · 12.8 KB
/
food-service.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
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
window.targetThing = "";
window.alertActive = false;
window.emailActive = false;
window.userEmailAddress = "";
window.currentMachine = "";
window.key = "";
$.support.cors = true;
setTimeout(function(){
$('button#emailsubmit').click(function(e){
var emailaddy = $("#emailfield").val();
console.log(emailaddy);
window.setEmailAddress(emailaddy);
$("#emailfield").prop('disabled', true);
$('button#emailsubmit').prop("disabled",true);
});
$('button#alertButton').click(function(e){
var emailaddy = $("#emailfield").val();
// $("#emailfield").prop('disabled', true);
$('button#alertButton').prop("disabled",true);
window.sendEmailAlert();
});
$('select#deviceSelect').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
populateStoreList(valueSelected);
});
$('select#reportSelect').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
freeboard.showLoadingIndicator(true);
setTimeout(function(){
freeboard.showLoadingIndicator(false);
window.location = valueSelected;
},1000);
});
$('#storeTablediv').parent().parent().parent().css({overflow:"scroll"});
$('#machinediv input').change(function () {
// The one that fires the event is always the
// checked one; you don't need to test for this
var newMachine = $(this).val();
window.currentMachine = newMachine;
changeMachine(newMachine);
});
$('#alertdiv input').change(function () {
// The one that fires the event is always the
// checked one; you don't need to test for this
var newSelection = $(this).val();
if (newSelection == "mix_out" || newSelection == "mix_low") {
$('#alertthresh').prop('disabled', true);
}
else $('#alertthresh').prop('disabled', false);
});
},3000);
function populateStoreList(region) {
$('tr.storeentry').remove();
if (region === 'ALL') {
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store1" onclick="changeStore()" href="#">Store 1111</a></td><td class="ZipCell">91225</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 2222</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 3333</a></td><td class="ZipCell">10011</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4444</a></td><td class="ZipCell">44313</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 5555</a></td><td class="ZipCell">11880</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 2121</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 3131</a></td><td class="ZipCell">25135</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4141</a></td><td class="ZipCell">62002</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 5151</a></td><td class="ZipCell">09822</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 6161</a></td><td class="ZipCell">27652</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4242</a></td><td class="ZipCell">33445</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 2424</a></td><td class="ZipCell">89898</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 6464</a></td><td class="ZipCell">10220</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4646</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 6868</a></td><td class="ZipCell">35835</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0001</a></td><td class="ZipCell">44313</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0002</a></td><td class="ZipCell">90123</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store1" onclick="changeStore()" href="#">Store 0003</a></td><td class="ZipCell">91225</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0004</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0005</a></td><td class="ZipCell">10011</td><td class="StatusCell; red">1</td></tr>');
}
else if (region === 'NORTH') {
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store1" onclick="changeStore()" href="#">Store 1111</a></td><td class="ZipCell">91225</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 2222</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 3333</a></td><td class="ZipCell">10011</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4444</a></td><td class="ZipCell">44313</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 5555</a></td><td class="ZipCell">11880</td><td class="StatusCell; red">1</td></tr>');
}
else if (region === 'SOUTH') {
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 2121</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 3131</a></td><td class="ZipCell">25135</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4141</a></td><td class="ZipCell">62002</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 5151</a></td><td class="ZipCell">09822</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 6161</a></td><td class="ZipCell">27652</td><td class="StatusCell; red">1</td></tr>');
}
else if (region === 'EAST') {
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4242</a></td><td class="ZipCell">33445</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 2424</a></td><td class="ZipCell">89898</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 6464</a></td><td class="ZipCell">10220</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 4646</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 6868</a></td><td class="ZipCell">35835</td><td class="StatusCell; red">1</td></tr>');
}
else if (region === 'WEST') {
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0001</a></td><td class="ZipCell">44313</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0002</a></td><td class="ZipCell">90123</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store1" onclick="changeStore()" href="#">Store 0003</a></td><td class="ZipCell">91225</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0004</a></td><td class="ZipCell">10007</td><td class="StatusCell; red">1</td></tr>');
$("#storetable > tbody:last").append('<tr class="storeentry"><td class="StoreCell"><a id="store2" onclick="changeStore()" href="#">Store 0005</a></td><td class="ZipCell">10011</td><td class="StatusCell; red">1</td></tr>');
}
//for (var resource in resources){
//$('select#deviceSelect').append('<OPTION class=reslistitem VALUE='+resource+' id='+resource+'>'+resources[resource]+'</OPTION>');
//}
}
function changeStore() {
freeboard.showLoadingIndicator(true);
$('#machinediv').hide();
setTimeout(function(){
$('#machinediv').show();
freeboard.showLoadingIndicator(false);
},1000);
}
function changeMachine(machine) {
freeboard.showLoadingIndicator(true);
setTimeout(function(){
freeboard.setDatasourceSettings("Machine_1", {"datafile":"https://thingproxy.freeboard.io/fetch/https://rawgit.com/bugvish/sandbox/master/"+machine+".json"});
freeboard.showLoadingIndicator(false);
},1200);
}
window.setEmailAddress = function(email) {
window.userEmailAddress = email;
}
window.sendEmailAlert = function() {
window.emailActive = true;
if (window.userEmailAddress !== '') {
$.ajax({
type: "POST",
url: "https://mandrillapp.com/api/1.0/messages/send.json",
data: {
'key': window.key,
'message': {
'from_email': '[email protected]',
'to': [
{
'email': window.userEmailAddress,
'type': 'to'
}
],
'autotext': 'true',
'subject': 'Food Service Machine Alert!',
'html': 'Mix out on Machine 1 at Store 1111.'
}
}
}).done(function(response) {
});
}
}
window.resetEmail = function() {
window.emailActive = false;
}
window.startServiceRequest = function() {
window.servicerq1 = true;
freeboard.showDialog($("<div align='center'>Service Request Detected! Please press Confirm</div>"),"Alert","Confirm",null,function(){dweetio.dweet_for(window.targetThing+'-send', {"led15":true}, function(err, dweet){});});
}
window.endServiceRequest = function() {
window.servicerq2 = true;
dweetio.dweet_for(window.targetThing+'-send', {"led15":false}, function(err, dweet){});
}