Revision ccdf370b
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
js/kivi.ImageUpload.js | ||
---|---|---|
5 | 5 |
const M = kivi.Materialize; |
6 | 6 |
|
7 | 7 |
let num_images = 0; |
8 |
ns.upload_in_progress = undefined; |
|
8 | 9 |
|
9 | 10 |
ns.add_files = function(target) { |
10 | 11 |
let files = []; |
... | ... | |
67 | 68 |
}; |
68 | 69 |
|
69 | 70 |
ns.upload_selected_files = function(id, type, maxsize) { |
71 |
$("#upload_modal").modal({ dismissible: false }); |
|
70 | 72 |
$("#upload_modal").modal("open"); |
71 | 73 |
|
72 | 74 |
kivi.FileDB.retrieve_all((myfiles) => { |
... | ... | |
91 | 93 |
|
92 | 94 |
let xhr = new XMLHttpRequest; |
93 | 95 |
xhr.open('POST', 'controller.pl', true); |
94 |
xhr.onload = ns.attSuccess;
|
|
95 |
xhr.upload.onprogress = ns.attProgress;
|
|
96 |
xhr.upload.onerror = ns.attFailed;
|
|
97 |
xhr.upload.onabort = ns.attCanceled;
|
|
96 |
xhr.onload = ns.upload_complete;
|
|
97 |
xhr.upload.onprogress = ns.progress;
|
|
98 |
xhr.upload.onerror = ns.failed;
|
|
99 |
xhr.upload.onabort = ns.abort;
|
|
98 | 100 |
xhr.send(data); |
101 |
|
|
102 |
ns.upload_in_progress = xhr; |
|
99 | 103 |
}); |
100 | 104 |
}); |
101 | 105 |
}; |
102 | 106 |
|
103 |
ns.attProgress = function(event) {
|
|
107 |
ns.progress = function(event) {
|
|
104 | 108 |
if (event.lengthComputable) { |
105 | 109 |
var percent_complete = (event.loaded / event.total) * 100; |
110 |
console.log(percent_complete); |
|
106 | 111 |
$("#upload_progress div").removeClass("indeterminate").addClass("determinate").attr("style", "width: " + percent_complete + "%"); |
107 | 112 |
} |
108 | 113 |
}; |
109 | 114 |
|
110 |
ns.attFailed = function() {
|
|
115 |
ns.failed = function() {
|
|
111 | 116 |
$('#upload_modal').modal('close'); |
112 | 117 |
M.flash(kivi.t8("An error occurred while transferring the file.")); |
113 | 118 |
}; |
114 | 119 |
|
115 |
ns.attCanceled = function() {
|
|
120 |
ns.abort = function() {
|
|
116 | 121 |
$('#upload_modal').modal('close'); |
117 | 122 |
M.flash(kivi.t8("The transfer has been canceled by the user.")); |
123 |
|
|
124 |
ns.upload_in_progress = undefined; |
|
118 | 125 |
}; |
119 | 126 |
|
120 |
ns.attSuccess = function() {
|
|
127 |
ns.upload_complete = function() {
|
|
121 | 128 |
$('#upload_modal').modal('close'); |
122 | 129 |
M.flash(kivi.t8("Files have been uploaded successfully.")); |
123 | 130 |
kivi.FileDB.delete_all(ns.reload_images); |
Auch abrufbar als: Unified diff
ImageUpload: modal undismissable + cancel