1
|
|
|
/** global: maxUpload */ |
2
|
|
|
// Third Party Libraries |
3
|
|
|
require('./bootstrap'); |
4
|
|
|
require('jquery-easing'); |
5
|
|
|
require('datatables.net-bs4'); |
6
|
|
|
require('dropzone'); |
7
|
|
|
require('select2'); |
8
|
|
|
require('fastselect'); |
9
|
|
|
//require('clipboard'); |
10
|
|
|
|
11
|
|
|
$(document).ready(function() |
12
|
|
|
{ |
13
|
|
|
// Enable any tooltips on the page |
14
|
|
|
initTooltip(); |
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
// Initialize any tooltips on the page |
18
|
|
|
function initTooltip() |
19
|
|
|
{ |
20
|
|
|
$('[data-tooltip="tooltip"]').tooltip(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/////////////////////////// Drag and Drop/File Upload Functions //////////////////////////////////// |
24
|
|
|
// Initialize drag and drop for only one file |
25
|
|
View Code Duplication |
function fileDrop(form) |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
// Initialize Drag and Drop |
28
|
|
|
var drop = $('#dropzone-box').dropzone( |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
url: form.attr('action'), |
31
|
|
|
autoProcessQueue: false, |
32
|
|
|
parallelUploads: 1, |
33
|
|
|
maxFiles: 1, |
34
|
|
|
maxFilesize: maxUpload, |
35
|
|
|
addRemoveLinks: true, |
36
|
|
|
chunking: true, |
37
|
|
|
chunkSize: 1000000, |
38
|
|
|
parallelChunkUploads: false, |
39
|
|
|
method: "POST", |
40
|
|
|
init: function() |
41
|
|
|
{ |
42
|
|
|
var myDrop = this; |
43
|
|
|
form.on('submit', function(e, formData) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
e.preventDefault(); |
46
|
|
|
if(myDrop.getQueuedFiles().length > 0) |
47
|
|
|
{ |
48
|
|
|
myDrop.processQueue(); |
49
|
|
|
$('#forProgressBar').show(); |
50
|
|
|
$('.submit-button').attr('disabled', true); |
51
|
|
|
} |
52
|
|
|
else |
53
|
|
|
{ |
54
|
|
|
$.post(form.attr('action'), form.serialize(), function(data) |
55
|
|
|
{ |
56
|
|
|
uploadComplete(data); |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
}); |
60
|
|
|
this.on('sending', function(file, xhr, formData) |
61
|
|
|
{ |
62
|
|
|
var formArray = form.serializeArray(); |
63
|
|
|
$.each(formArray, function() |
64
|
|
|
{ |
65
|
|
|
formData.append(this.name, this.value); |
66
|
|
|
}); |
67
|
|
|
}); |
68
|
|
|
this.on('uploadprogress', function(progress) |
69
|
|
|
{ |
70
|
|
|
var prog = Math.round(progress.upload.progress); |
71
|
|
|
|
72
|
|
|
if(prog != 100) |
73
|
|
|
{ |
74
|
|
|
$("#progressBar").css("width", prog+"%"); |
75
|
|
|
$("#progressStatus").text(prog+"%"); |
76
|
|
|
} |
77
|
|
|
// $("#progressBar").css("width", Math.round(progress.upload.progress)+"%"); |
78
|
|
|
// $("#progressStatus").text(Math.round(progress.upload.progress)+"%"); |
79
|
|
|
}); |
80
|
|
|
this.on('reset', function() |
81
|
|
|
{ |
82
|
|
|
$('#form-errors').addClass('d-none'); |
83
|
|
|
}); |
84
|
|
|
this.on('success', function(files, response) |
85
|
|
|
{ |
86
|
|
|
console.log(response); |
|
|
|
|
87
|
|
|
uploadComplete(response); |
88
|
|
|
}); |
89
|
|
|
this.on('errormultiple', function(file, response) |
90
|
|
|
{ |
91
|
|
|
uploadFailed(response); |
92
|
|
|
}); |
93
|
|
|
} |
94
|
|
|
}); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// Initialize drag and drop for multiple file uploads |
98
|
|
View Code Duplication |
function multiFileDrop(form) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
// Initialize Drag and Drop |
101
|
|
|
var drop = $('#dropzone-box').dropzone( |
|
|
|
|
102
|
|
|
{ |
103
|
|
|
url: form.attr('action'), |
104
|
|
|
autoProcessQueue: false, |
105
|
|
|
parallelUploads: 1, |
106
|
|
|
maxFiles: 1, |
107
|
|
|
maxFilesize: maxUpload, |
108
|
|
|
addRemoveLinks: true, |
109
|
|
|
chunking: true, |
110
|
|
|
chunkSize: 1000000, |
111
|
|
|
parallelChunkUploads: false, |
112
|
|
|
method: "POST", |
113
|
|
|
init: function() |
114
|
|
|
{ |
115
|
|
|
var myDrop = this; |
116
|
|
|
form.on('submit', function(e, formData) |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
e.preventDefault(); |
119
|
|
|
if(myDrop.getQueuedFiles().length > 0) |
120
|
|
|
{ |
121
|
|
|
myDrop.processQueue(); |
122
|
|
|
$('#forProgressBar').show(); |
123
|
|
|
$('.submit-button').attr('disabled', true); |
124
|
|
|
} |
125
|
|
|
else |
126
|
|
|
{ |
127
|
|
|
$.post(form.attr('action'), form.serialize(), function(data) |
128
|
|
|
{ |
129
|
|
|
uploadComplete(data); |
130
|
|
|
}); |
131
|
|
|
} |
132
|
|
|
}); |
133
|
|
|
this.on('sending', function(file, xhr, formData) |
134
|
|
|
{ |
135
|
|
|
var formArray = form.serializeArray(); |
136
|
|
|
$.each(formArray, function() |
137
|
|
|
{ |
138
|
|
|
formData.append(this.name, this.value); |
139
|
|
|
}); |
140
|
|
|
}); |
141
|
|
|
this.on('uploadprogress', function(progress) |
142
|
|
|
{ |
143
|
|
|
var prog = Math.round(progress.upload.progress); |
144
|
|
|
|
145
|
|
|
if(prog != 100) |
146
|
|
|
{ |
147
|
|
|
$("#progressBar").css("width", prog+"%"); |
148
|
|
|
$("#progressStatus").text(prog+"%"); |
149
|
|
|
} |
150
|
|
|
// $("#progressBar").css("width", Math.round(progress.upload.progress)+"%"); |
151
|
|
|
// $("#progressStatus").text(Math.round(progress.upload.progress)+"%"); |
152
|
|
|
}); |
153
|
|
|
this.on('reset', function() |
154
|
|
|
{ |
155
|
|
|
$('#form-errors').addClass('d-none'); |
156
|
|
|
}); |
157
|
|
|
this.on('success', function(files, response) |
158
|
|
|
{ |
159
|
|
|
console.log(response); |
|
|
|
|
160
|
|
|
uploadComplete(response); |
161
|
|
|
}); |
162
|
|
|
this.on('errormultiple', function(file, response) |
163
|
|
|
{ |
164
|
|
|
uploadFailed(response); |
165
|
|
|
}); |
166
|
|
|
} |
167
|
|
|
}); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
// Reset the progress bar and drag and drop box |
171
|
|
|
function resetProgressBar() |
172
|
|
|
{ |
173
|
|
|
$('#dragndrop-notice').text('Or Drag Files Here'); |
174
|
|
|
$('#progressBar').css('width', '0%').attr('aria-valuenow', 0); |
175
|
|
|
$('#progressStatus').text(''); |
176
|
|
|
$('#forProgressBar').hide(); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
// Reset the Edit Modal to its default state |
180
|
|
|
function resetEditModal() |
181
|
|
|
{ |
182
|
|
|
$('#edit-modal').modal('hide'); |
183
|
|
|
$('#edit-modal').find('.modal-title').text(''); |
184
|
|
|
$('#edit-modal').find('.modal-body').text(''); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
////////////////////////////////////////////////////////////////////////////////////////// |
188
|
|
|
|
189
|
|
|
// Make the functions in this file globally accessable |
190
|
|
|
window.resetProgressBar = resetProgressBar; |
191
|
|
|
window.resetEditModal = resetEditModal; |
192
|
|
|
window.fileDrop = fileDrop; |
193
|
|
|
window.multiFileDrop = multiFileDrop; |
194
|
|
|
|