-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain_scripts.html
107 lines (87 loc) · 3.3 KB
/
main_scripts.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
<script>
$( document ).ready(function() {
var form = document.getElementById('uploadEventDataForm');
var formInputs = {};
var defaultEmail = document.cookie;
if (defaultEmail && !form.email.value) {
form.email.value = defaultEmail;
}
states.forEach(function(state){
form.state.options[form.state.options.length] = new Option(state.name, state.abbreviation);
});
form.state.selectedIndex = 0;
var numUploads = {};
var fileUrls = [];
numUploads.done = 0;
numUploads.total = 0;
// Upload the files into a folder in drive
// This is set to send them all to one folder (specificed in the .gs file)
$(form).on( "submit", iteratorFileUpload );
function iteratorFileUpload(e) {
e.preventDefault();
var allFiles = document.getElementById('myFile').files;
formData = $(form).serializeArray();
formInputs = {};
for (var n = 0; n < formData.length; n++){
var inputValue = formData[n].value;
if ( $(form[formData[n].name]).prop('required') && (inputValue === null || inputValue === undefined || inputValue === '') ) {
alert('Please provide a value for ' + formData[n].name);
return
};
formInputs[formData[n].name] = formData[n].value;
}
if (allFiles.length == 0) {
alert('No file selected!');
}
else {
//Show Progress Bar
$('#uploadEventDataForm :submit').prop('disabled', 'disabled');
// Scroll progress bar into view
$('html,body').animate({scrollTop: document.body.scrollHeight},"fast");
document.cookie = form.email.value;
numUploads.total = allFiles.length;
$('#progressbar').progressbar({
value : false
});
//.append("<div class='caption'>37%</div>");
$(".progress-label").html('Uploading files...');
// Send each file at a time
for (var i = 0; i < allFiles.length; i++) {
sendFileToDrive(allFiles[i], i);
}
}
}
function sendFileToDrive(file, index) {
var reader = new FileReader();
reader.onload = function (e) {
var content = reader.result;
console.log('Sending ' + file.name);
google.script.run.withSuccessHandler(updateProgressbar)
.uploadFileToDrive(content, file.name, formInputs, index);
}
reader.readAsDataURL(file);
}
function updateProgressbar( idUpdate ){
console.log('Received: ' + idUpdate);
fileUrls.push(idUpdate);
numUploads.done++;
var porc = Math.ceil((numUploads.done / numUploads.total)*100);
$("#progressbar").progressbar({value: porc });
$(".progress-label").text(numUploads.done +'/'+ numUploads.total + " Uploaded Successfully");
if( numUploads.done == numUploads.total ){
numUploads.done = 0;
google.script.run.withSuccessHandler(showConfirm)
.sendEmailConfirmation(form.email.value, fileUrls);
};
}
function showConfirm() {
$('#uploadEventDataForm :submit').html('Upload Complete').removeClass('btn-primary').addClass('btn-success');
$('#confirmModal').modal({keyboard: false, backdrop: 'static', show: true});
$('html, body').animate({ scrollTop: 0 });
}
function fileUploaded(status) {
document.getElementById('uploadEventDataForm').style.display = 'none';
document.getElementById('output').innerHTML = status;
}
});
</script>