-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo-script.js
More file actions
508 lines (363 loc) · 12.7 KB
/
video-script.js
File metadata and controls
508 lines (363 loc) · 12.7 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
var spinner = $('#loader');
const scriptURLC ='https://script.google.com/macros/s/AKfycbwChFoeZe8vagm2tXzhIfFssGjYbItkuaFE-BHiS87MSJItse8kHuxU53z9oUNsPNGR/exec';
const serverlessForm = document.forms['serverless-form'];
var timerOn = false;
var bgAnimate = false;
var oldOrderID = 0000;
var currentOrderID = 0000;
var oldTech = "";
var currentTech = "";
var orderID;
var lastName;
var tapeNum;
var initials;
var qcNotes;
var needsReview;
var notesOnly;
var billingNotes;
$("#reset-btn").click(function(){
$("#contactForm").trigger("reset");
$(".pulled-detail").html("");
$("#billing-notes").val("").change();
resetTimer();
});
var countdownDuration = 10 * 60 * 1000;
$("#restart-button").click(function(){
console.log("restart button Clicked");
countdownDuration = 10 * 60 * 1000;
$("#stop-timer").html("10:00");
if (timerOn == false){
timerOn = true;
runTimer();
}
$("body").css({"animation-name":"", "animation-duration":"", "animation-iteration-count":""})
})
$("#stop-button").click(function(){
console.log("Stop button Clicked");
resetTimer();
})
$("#progress-btn").click(function(){
console.log("Order Progress Button Clicked");
getOrderProgress(orderID);
})
function resetTimer(){
timerOn = false;
bgAnimate = false;
$("body").css({"animation-name":"", "animation-duration":"", "animation-iteration-count":""})
$("#stop-timer-button").css("display", "");
$("#stop-timer-div").css("display", "none");
$("body").css("background-color", "black");
// clearInterval(timer);
countdownDuration = 10 * 60 * 1000;
}
$("#stop-timer-button").click(function(){
runTimer();
})
function runTimer(){
console.log("stop timer button clicked");
timerOn = true;
$("#stop-timer-button").css("display", "none");
$("#stop-timer-div").css("display", "inherit");
$("#stop-timer").css("width", $("#stop-timer").width());
var now = new Date().getTime();
var countdownTime = now + countdownDuration;
console.log("Countdown Duration: " + countdownDuration);
console.log("current Time: " + now);
console.log("Countdown Time: " + countdownTime);
var timer = setInterval(function(){
console.log("Tick");
var now = new Date().getTime();
var distance = (now + countdownDuration) - now;
console.log("countdownTime: " + countdownTime);
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
if (seconds < 10) seconds = "0" + seconds;
$("#stop-timer").html(minutes + ":" + seconds);
countdownDuration = countdownDuration - 1000;
// If the count down is finished, write some text
if (distance <= 0) {
clearInterval(timer);
countdownDuration = 10 * 60 * 1000;
timerOn = false;
bgAnimate = true;
$("body").css({"animation-name":"doneFlash", "animation-duration":"1.6s", "animation-iteration-count":"infinite"})
}
if (timerOn == false) {
clearInterval(timer);
countdownDuration = 10 * 60 * 1000;
}
}, 1000);
}
//Get Order Notes
$('#order-id').change(function(){
var orderID = $('#order-id').val();
var tapeName = orderID.split("_");
$("#logged-text").html("");
if (tapeName.length > 1){
$('#order-id').val(tapeName[0]);
$('#last-name').val(tapeName[1]);
$('#tape-num').val(tapeName[2]);
$('#tape-num').focus();
}
currentOrderID = $('#order-id').val();
currentTech = $('#initials').val();
console.log("Getting Order Notes");
$('#order-notes').html("Retrieving Order Notes");
$('#last-name').val("");
$('#last-name').attr("placeholder", "Retrieving Customer Name");
getOrderDetails(currentOrderID, $('#tape-num').val(), currentTech);
})
$('#tape-num').change(function(){
currentOrderID = $('#order-id').val();
currentTech = $('#initials').val();
$("#logged-text").html("");
$('#existing-qc-notes').html("Retrieving Tape Notes");
getOrderDetails(currentOrderID, $('#tape-num').val(), currentTech);
})
//If the initials have been updated, update order Status on Order Tracking.
$('#initials').change(function(){
currentOrderID = $('#order-id').val();
currentTech = $('#initials').val();
getOrderDetails(currentOrderID, $('#tape-num').val(), currentTech);
})
//-----------------------------------------------------------------
//~~~~~~~~~~~~~~~~~~~~~~~~~Form Submission~~~~~~~~~~~~~~~~~~~~~~~~~
//-----------------------------------------------------------------
function getFormDetails(){
orderID = $('#order-id').val();
lastName = $('#last-name').val();
tapeNum = $('#tape-num').val();
initials = $('#initials').val();
qcNotes = $('#qc-notes').val();
needsReview = $('#needs-review').is(":checked");
notesOnly = $('#notes-only').is(":checked");
billingNotes = $('#billing-notes').val();
if (currentOrderID != oldOrderID || currentTech != oldTech){
checkOrderStatus = true;
oldOrderID = currentOrderID;
oldTech = currentTech;
} else {
checkOrderStatus = false;
}
}
serverlessForm.addEventListener('submit', e => {
e.preventDefault();
getFormDetails();
console.log("Tape Number: " + tapeNum);
var standardMessage = {
title: 'Ready to Log Tape <br/>' + orderID + '_' + lastName + '_ ' + tapeNum + '?',
text: 'Has the file been reviewed? Ready to Log Tape?',
icon: 'question',
showCancelButton: true,
confirmButtonText: 'Log Tape',
returnFocus: false,
focusCancel: true
};
var loggedMessage = {
title: 'TAPE IS ALREADY LOGGED! <br/>' + orderID + '_' + lastName + '_ ' + tapeNum,
text: 'This tape has already been logged! Please confirm the tape information is correct and select "Log Notes Only" to log the tape.',
icon: 'warning',
showCancelButton: true,
showConfirmButton: false,
confirmButtonText: 'Log Tape',
returnFocus: false,
focusCancel: true
};
var message = {};
if ($("#logged-text").html() != ""){
if (!$("#notes-only").prop('checked')){
message = loggedMessage;
} else {
loggedMessage.showConfirmButton = true;
loggedMessage.text = "Tape has already been logged! Confirm you would like to log notes only!";
message = loggedMessage;
}
} else {
message = standardMessage;
}
Swal.fire(message).then((result) => {
if (result.isConfirmed) {
// Swal.fire('Saved!', '', 'success')
logTape(e)
}
})
});
function logTape(e){
spinner.show();
getFormDetails();
var params = new URLSearchParams({
orderID: orderID,
lastName: lastName,
tapeNum: tapeNum,
initials: initials,
qcNotes: qcNotes,
needsReview: needsReview,
notesOnly: notesOnly,
billingNotes: billingNotes,
orderCategory: "video",
requestType: "logTape"
});
console.log("Notes Only: " + notesOnly);
var tapeProgress = "";
fetch(scriptURLC, {
method: 'POST',
body: params
})
.then(res => {
console.log(res);
spinner.hide();
res.json().then(function(data) {
console.log(data);
tapeProgress = data.tapeProgress;
if (res['status'] == 200) {
if(data.errorTitle == ""){
Swal.fire({
title: "Tape Logged!",
html: "Tape #" + tapeNum + " For Order " + orderID + "_" + $("#last-name").val() + " Has Been Logged!" + "<br/>" + data.tapeProgress,
icon: "success",
returnFocus: false
}).then((result) => {
if (result.isConfirmed) {
// Swal.fire('Saved!', '', 'success')
// $(".resetAble").val("");
resetTimer();
$('#order-id').val(orderID);
$('#stop-time').val("")
$('#tape-num').val("");
$('#qc-notes').val("");
$("#billing-notes").val("").change();
$('#needs-review').prop('checked', false);
$('#notes-only').prop('checked', false);
$('#existing-qc-notes').html("");
$('#tape-num').focus();
$('#logged-text').html("");
}
});
} else { //There was a logging error
Swal.fire({
title: data.errorTitle,
html: data.errorText,
icon: "error",
returnFocus: false
});
}
return true;
} else {
Swal.fire("Something went wrong!", "Review Footage Log and/or contact Admin<br/>" + orderID + "<br/>" + tapeNum + "<br/>" + qcNotes + "<br/>" + billingNotes, "error");
}
});
document.getElementById('submitForm').classList.remove('loading');
})
.catch(error => {
spinner.hide();
// document.getElementById('submitForm').classList.remove('loading');
Swal.fire("Something went wrong!", "Review Footage Log and/or contact Admin", "error");
// todo enable submit button
})
}
function getOrderDetails(orderID, tapeNum, initials){
getFormDetails();
var params = new URLSearchParams({
orderID: orderID,
tapeNum: tapeNum,
initials: initials,
checkOrderStatus: checkOrderStatus,
requestType: "getOrderDetails"
});
fetch(scriptURLC, {
method: 'POST',
body: params
}).then(response => response.json())
.then(data => {
var splitNotes = data.tapeNotes.split("\n\n");
console.log(splitNotes);
var formattedNotes = "";
if (splitNotes.length > 1){
splitNotes.forEach(line => formattedNotes = formattedNotes + line + "<br/>");
} else {
formattedNotes = data.tapeNotes;
}
$("#existing-qc-notes").html(formattedNotes);
$("#order-notes").html('<a href="' + data.orderURL + '" target="_blank">Link to File Log</a>' + '</br>' + data.orderNotes);
$("#last-name").val(data.customerName);
copyToClipboard($('#order-id').val() + "_" + $('#last-name').val() + "_" + ('000' + $('#tape-num').val()).slice(-3))
$('#last-name').attr("placeholder", "Smith");
if ($('#tape-num').val() == "") {
$('#tape-num').focus();
} else if ($("#initials").val() == "") {
$('#initials').focus();
} else {
$('#qc-notes').focus();
}
try {
// Your asynchronous code here
if (data.logged === true) {
$("#logged-text").html("(Tape Already logged)");
}
} catch {
console.log("Error occurred: " + error.message);
console.log("No logging information Present");
}
console.log(data)
});
}
function getOrderProgress(orderID){
spinner.show();
getFormDetails();
var params = new URLSearchParams({
orderID: orderID,
requestType: "getOrderProgress"
});
console.log("Getting Order Progress");
var tapeProgress = "";
fetch(scriptURLC, {
method: 'POST',
body: params
})
.then(res => {
console.log(res);
spinner.hide();
res.json().then(function(data) {
console.log(data);
tapeProgress = data.tapeProgress;
if (res['status'] == 200) {
if(data.errorTitle == ""){
Swal.fire({
title: "Current Order Progress",
html: data.tapeProgress,
icon: "success",
returnFocus: false
}).then((result) => {
if (result.isConfirmed) {
}
});
} else { //There was a logging error
Swal.fire({
title: data.errorTitle,
html: data.errorText,
icon: "error",
returnFocus: false
});
}
return true;
} else {
Swal.fire("Something went wrong!", "Please Try Again or Contact Admin", "error");
}
});
document.getElementById('submitForm').classList.remove('loading');
})
.catch(error => {
spinner.hide();
// document.getElementById('submitForm').classList.remove('loading');
Swal.fire("Something went wrong!", "Review Footage Log and/or contact Admin", "error");
// todo enable submit button
})
}
function copyToClipboard(value) {
var tempInput = document.createElement("input");
tempInput.value = value;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
}