Revision d04d57fd
Von Bernd Bleßmann vor etwa 3 Jahren hinzugefügt
js/kivi.File.js | ||
---|---|---|
1 | 1 |
namespace('kivi.File', function(ns) { |
2 |
ns.list_div_id = undefined; |
|
2 | 3 |
|
3 | 4 |
ns.rename = function(id,type,file_type,checkbox_class,is_global) { |
4 | 5 |
var $dlg = $('#rename_dialog_'+file_type); |
... | ... | |
77 | 78 |
} |
78 | 79 |
|
79 | 80 |
ns.upload = function(id,type,filetype,upload_title,gl) { |
81 |
$('#upload_status_dialog').remove(); |
|
82 |
|
|
80 | 83 |
kivi.popup_dialog({ url: 'controller.pl', |
81 | 84 |
data: { action: 'File/ajax_upload', |
82 | 85 |
file_type: filetype, |
... | ... | |
99 | 102 |
$('#upload_selected_button').prop('disabled',$('#upload_files').val() === ''); |
100 | 103 |
} |
101 | 104 |
|
105 |
ns.upload_status_dialog = function() { |
|
106 |
$('#files_upload').remove(); |
|
107 |
$('#upload_status_dialog').remove(); |
|
108 |
|
|
109 |
var html = '<div id="upload_status_dialog"><p><div id="upload_result"></div></p>'; |
|
110 |
html = html + '<p><input type="button" value="' + kivi.t8('close') + '" size="30" onclick="$(\'#upload_status_dialog\').dialog(\'close\');">'; |
|
111 |
html = html + '</p></div>'; |
|
112 |
$(html).hide().appendTo('#' + ns.list_div_id); |
|
113 |
|
|
114 |
kivi.popup_dialog({id: 'upload_status_dialog', |
|
115 |
dialog: {title: kivi.t8('Upload Status'), |
|
116 |
height: 200, |
|
117 |
width: 650 }}); |
|
118 |
}; |
|
119 |
|
|
102 | 120 |
ns.upload_selected_files = function(id,type,filetype,maxsize,is_global) { |
103 | 121 |
var myform = document.getElementById("upload_form"); |
104 |
var filesize = 0; |
|
105 | 122 |
var myfiles = document.getElementById("upload_files").files; |
123 |
|
|
124 |
ns.upload_files(id, type, filetype, maxsize,is_global, myfiles, myform); |
|
125 |
} |
|
126 |
|
|
127 |
ns.upload_files = function(id, type, filetype, maxsize, is_global, myfiles, myform) { |
|
128 |
var filesize = 0; |
|
106 | 129 |
for ( i=0; i < myfiles.length; i++ ) { |
107 | 130 |
var fname =''; |
108 | 131 |
try { |
... | ... | |
125 | 148 |
return; |
126 | 149 |
} |
127 | 150 |
|
128 |
myform.action ="controller.pl?action=File/ajax_files_uploaded&json=1&object_type="+ |
|
129 |
type+'&object_id='+id+'&file_type='+filetype+'&is_global='+is_global; |
|
151 |
var fd = new FormData(myform); |
|
152 |
if (!myform) { |
|
153 |
$(myfiles).each(function(idx, elt) { |
|
154 |
fd.append('uploadfiles[+]', elt); |
|
155 |
}); |
|
156 |
} |
|
157 |
fd.append('action', 'File/ajax_files_uploaded'); |
|
158 |
fd.append('json', 1); |
|
159 |
fd.append('object_type', type); |
|
160 |
fd.append('object_id', id); |
|
161 |
fd.append('file_type', filetype); |
|
162 |
fd.append('is_global', is_global); |
|
163 |
|
|
130 | 164 |
var oReq = new XMLHttpRequest(); |
131 | 165 |
oReq.onload = ns.attSuccess; |
132 | 166 |
oReq.upload.onprogress = ns.attProgress; |
133 | 167 |
oReq.upload.onerror = ns.attFailed; |
134 | 168 |
oReq.upload.onabort = ns.attCanceled; |
135 |
oReq.open("post",myform.action, true);
|
|
169 |
oReq.open("post", 'controller.pl', true);
|
|
136 | 170 |
$("#upload_result").html(kivi.t8("start upload")); |
137 |
oReq.send(new FormData(myform));
|
|
171 |
oReq.send(fd);
|
|
138 | 172 |
} |
139 | 173 |
|
140 | 174 |
ns.attProgress = function(oEvent) { |
... | ... | |
155 | 189 |
} |
156 | 190 |
|
157 | 191 |
ns.attSuccess = function() { |
192 |
$('#upload_status_dialog').dialog('close'); |
|
158 | 193 |
$('#files_upload').dialog('close'); |
159 | 194 |
kivi.eval_json_result(jQuery.parseJSON(this.response)); |
160 | 195 |
} |
... | ... | |
265 | 300 |
$.download("controller.pl", data); |
266 | 301 |
return false; |
267 | 302 |
} |
303 |
|
|
304 |
ns.init = function() { |
|
305 |
// Preventing page from redirecting |
|
306 |
$("#" + ns.list_div_id).on("dragover", function(e) { |
|
307 |
e.preventDefault(); |
|
308 |
e.stopPropagation(); |
|
309 |
}); |
|
310 |
|
|
311 |
$("#" + ns.list_div_id).on("drop", function(e) { |
|
312 |
e.preventDefault(); |
|
313 |
e.stopPropagation(); |
|
314 |
}); |
|
315 |
|
|
316 |
// Drag enter |
|
317 |
$('.upload_drop_zone').on('dragenter', function (e) { |
|
318 |
e.stopPropagation(); |
|
319 |
e.preventDefault(); |
|
320 |
}); |
|
321 |
|
|
322 |
// Drag over |
|
323 |
$('.upload_drop_zone').on('dragover', function (e) { |
|
324 |
e.stopPropagation(); |
|
325 |
e.preventDefault(); |
|
326 |
}); |
|
327 |
|
|
328 |
// Drop |
|
329 |
$('.upload_drop_zone').on('drop', function (e) { |
|
330 |
e.stopPropagation(); |
|
331 |
e.preventDefault(); |
|
332 |
|
|
333 |
ns.upload_status_dialog(); |
|
334 |
|
|
335 |
var object_type = $(e.target).data('object-type'); |
|
336 |
var object_id = $(e.target).data('object-id'); |
|
337 |
var file_type = $(e.target).data('file-type'); |
|
338 |
var is_global = $(e.target).data('is-global'); |
|
339 |
var maxsize = $(e.target).data('maxsize'); |
|
340 |
var files = e.originalEvent.dataTransfer.files; |
|
341 |
ns.upload_files(object_id, object_type, file_type, maxsize, is_global, files); |
|
342 |
}); |
|
343 |
|
|
344 |
}; |
|
345 |
|
|
268 | 346 |
}); |
Auch abrufbar als: Unified diff
Dateimanagement: Upload per Drag/Drop