-
Notifications
You must be signed in to change notification settings - Fork 0
/
pageSerial-js.html
229 lines (210 loc) · 9.98 KB
/
pageSerial-js.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
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
<script>
document.getElementById('idCBs').readOnly = true;
document.getElementById('idCBsModel').readOnly = true;
document.getElementById('idActionResult').readOnly = true;
document.getElementById('idCBlastsyncs').readOnly = true;
//document.getElementById('idCBOUs').readOnly = true;
document.getElementById('idCBassets').readOnly = false;
document.getElementById('idCBosversions').readOnly = true;
document.getElementById('idCBManufactureDate').readOnly = true;
document.getElementById('idCBOUautoUpdateExpirations').readOnly = true;
document.getElementById('idCBmacAddresss').readOnly = true;
document.getElementById('idLan2').readOnly = true;
document.getElementById('idWan2').readOnly = true;
document.getElementById('idCBRecentUsers0s').readOnly = true;
document.addEventListener("DOMContentLoaded", function() {
var elems = document.querySelectorAll('select');
var instances = M.FormSelect.init(elems);
fetchCBOUs()
});
function fetchCBOUs(){
google.script.run
.withSuccessHandler(printCBOUs)
.findCBOUs();
}
window.printCBOUs = function(CBOU) {
document.getElementById('idCBs').value = CBOU[1];
document.getElementById('idCBsModel').value = CBOU[2];
document.getElementById('idCBlastsyncs').value = CBOU[4];
// document.getElementById('idCBOUs').value = CBOU[6];
document.getElementById('idCBassets').value = CBOU[7];
document.getElementById('idCBosversions').value = CBOU[8];
document.getElementById('idCBManufactureDate').value = CBOU[9];
document.getElementById('idCBOUautoUpdateExpirations').value = CBOU[10];
document.getElementById('idCBmacAddresss').value = CBOU[11];
document.getElementById('idLan2').value = lan2;
document.getElementById('idWan2').value = wan2;
document.getElementById('idActionResult').value = "Current status is " + CBOU[3];
let status = CBOU[3];
if (status == "ACTIVE") {
btnWipe.disabled=false;
btnReset.disabled=false;
btnEnable.disabled=true;
btnDisable.disabled=false;
btnDeprovision.disabled=false;
document.getElementById("idActionResult").style.backgroundColor="#81c784";
document.getElementById('idInfo').value = "Displays information about device with the following serial number";
} else if (status == "DISABLED") {
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=false;
btnDisable.disabled=true;
btnDeprovision.disabled=false;
document.getElementById("idActionResult").style.backgroundColor="#e57373";
document.getElementById('idInfo').value = "Displays information about device with the following serial number";
} else if (status == null) {
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
btnRefresh.disabled=true;
document.getElementById("idActionResult").style.backgroundColor="#ffc90e";
document.getElementById("idActionResult").value = "The serial number you selected does not appear to belong to your school. See in CB_LookUp. Contact your IT partner if you have any questions.";
document.getElementById("idCBs").value = "";
document.getElementById('idInfo').value = "";
document.getElementById('idLan2').value = "";
document.getElementById('idWan2').value = "";
} else if (status == "") {
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
btnRefresh.disabled=true;
document.getElementById("idActionResult").style.backgroundColor="#ffc90e";
document.getElementById("idActionResult").value = "You seem to lack rights to view device details. Contact your IT partner.";
document.getElementById("idCBs").value = "";
document.getElementById("idInfo").value = "";
} else {
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
// btnDeprovision.disabled=false; // This is for testing error messages for devices already DEPROVISIONED
document.getElementById("idActionResult").style.backgroundColor="#ba68c8";
document.getElementById('idInfo').value = "Displays information about device with the following serial number";
}
if (CBOU[12] !=""){
var list2 = CBOU[12];
var lan2 = list2[0].ipAddress;
var wan2 = list2[0].wanIpAddress;
document.getElementById('idLan2').value = lan2;
document.getElementById('idWan2').value = wan2;
} else {
var lan2 = "Not available";
var wan2 = "Not available";
document.getElementById('idLan2').value = lan2;
document.getElementById('idWan2').value = wan2;
}
var list0 = CBOU[13];
for (i=0; i<list0.length; i++) {
var user0 = list0[i].email;
var type0 = list0[i].type;
let html0='<style>td,th{border:0px solid black;}</style><table>';
html0+='<tr><td>' + user0 + '</td></tr>';
html0+='</table>';
var myTable0 = document.getElementById("idCBRecentUsers0s");
myTable0.insertAdjacentHTML("beforeend", html0);
}
}
document.getElementById("btnWipe").addEventListener("click",wipeCBS);
function wipeCBS(){
var sernum = document.getElementById("idCBs").value;
google.script.run
.withSuccessHandler(printWipeCB)
.wipeCB(sernum);
}
window.printWipeCB = function(serno) {
document.getElementById("idActionResult").style.backgroundColor="#81c784";
document.getElementById("idActionResult").value = " The device " + serno + " will have profiles deleted";
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
}
document.getElementById("btnReset").addEventListener("click",resetCBS);
function resetCBS(){
var sernum = document.getElementById("idCBs").value;
google.script.run
.withSuccessHandler(printResetCB)
.resetCB(sernum);
}
window.printResetCB = function(serno) {
document.getElementById("idActionResult").style.backgroundColor="#81c784";
document.getElementById("idActionResult").value = " The device " + serno + " will be powerwashed";
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
}
document.getElementById("btnEnable").addEventListener("click",enableCBS);
function enableCBS(){
var sernum = document.getElementById("idCBs").value;
google.script.run
.withSuccessHandler(printEnableCB)
.enableCB(sernum);
}
window.printEnableCB = function(serno) {
document.getElementById("idActionResult").style.backgroundColor="#81c784";
document.getElementById("idActionResult").value = " The device " + serno + " has been activated - Click UPDATE PAGE to see result";
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
}
document.getElementById("btnDisable").addEventListener("click",disableCBS);
function disableCBS(){
var sernum = document.getElementById("idCBs").value;
google.script.run
.withSuccessHandler(printDisableCB)
.disableCB(sernum);
}
window.printDisableCB = function(serno) {
document.getElementById("idActionResult").style.backgroundColor="#e57373";
document.getElementById("idActionResult").value = " The device " + serno + " will be disabled - Click UPDATE PAGE to see result";
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
}
function confirmDeprovision() {
let confirmDeprovision = confirm("\n---------------------------------------------------\nTHE DEVICE WILL NOW BE PERMANENTLY SCRAPPED.\nNOTE! THIS ACTION IS IRREVOCABLE.\n\Select OK to mark the device for SCRAPPING.\nCancel undoes the action.\n---------------------------------------------------");
if (confirmDeprovision) {
alert("\n---------------------------------------------------\nThe device is now marked as scrapped (deprovisioned).\n---------------------------------------------------");
var sernum = document.getElementById("idCBs").value;
google.script.run
.withSuccessHandler(printDeprovisionCB)
.deprovisionCB(sernum);
} else {
alert("\n---------------------------------------------------\nYou canceled scrapping (deprovisioning). Nothing has changed.\n---------------------------------------------------");
}
}
window.printDeprovisionCB = function(feedback) {
var serial = feedback[0];
var result = feedback[1];
var bgcolor = feedback[2];
document.getElementById("idActionResult").style.backgroundColor=bgcolor;
document.getElementById("idActionResult").value = " The device " + serial + " " + result;
btnWipe.disabled=true;
btnReset.disabled=true;
btnEnable.disabled=true;
btnDisable.disabled=true;
btnDeprovision.disabled=true;
}
document.getElementById("btnRefresh").addEventListener("click",getUrl);
function getUrl(){
var sernum = document.getElementById("idCBs").value;
google.script.run
.withSuccessHandler(function(url){
var realWebAddress = url + '?sn=' + sernum
window.open(realWebAddress, "_top");
})
.getScriptURL();
}
</script>