X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=js%2Fkivi.File.js;h=8645a09c5a0c92b78a51dfec68e061318ff767e0;hb=0d4bded426d1f09a85256767e8525bd15f551d88;hp=c14c65f2b508c91059de3bc17c01b1ee04b76001;hpb=05ec736510a34ab37d6366a9981ea7da4b1d93db;p=kivitendo-erp.git diff --git a/js/kivi.File.js b/js/kivi.File.js index c14c65f2b..8645a09c5 100644 --- a/js/kivi.File.js +++ b/js/kivi.File.js @@ -1,4 +1,5 @@ namespace('kivi.File', function(ns) { + ns.list_div_id = undefined; ns.rename = function(id,type,file_type,checkbox_class,is_global) { var $dlg = $('#rename_dialog_'+file_type); @@ -77,6 +78,8 @@ namespace('kivi.File', function(ns) { } ns.upload = function(id,type,filetype,upload_title,gl) { + $('#upload_status_dialog').remove(); + kivi.popup_dialog({ url: 'controller.pl', data: { action: 'File/ajax_upload', file_type: filetype, @@ -99,10 +102,30 @@ namespace('kivi.File', function(ns) { $('#upload_selected_button').prop('disabled',$('#upload_files').val() === ''); } + ns.upload_status_dialog = function() { + $('#files_upload').remove(); + $('#upload_status_dialog').remove(); + + var html = '

'; + html = html + '

'; + html = html + '

'; + $(html).hide().appendTo('#' + ns.list_div_id); + + kivi.popup_dialog({id: 'upload_status_dialog', + dialog: {title: kivi.t8('Upload Status'), + height: 200, + width: 650 }}); + }; + ns.upload_selected_files = function(id,type,filetype,maxsize,is_global) { var myform = document.getElementById("upload_form"); - var filesize = 0; var myfiles = document.getElementById("upload_files").files; + + ns.upload_files(id, type, filetype, maxsize,is_global, myfiles, myform); + } + + ns.upload_files = function(id, type, filetype, maxsize, is_global, myfiles, myform) { + var filesize = 0; for ( i=0; i < myfiles.length; i++ ) { var fname =''; try { @@ -125,16 +148,27 @@ namespace('kivi.File', function(ns) { return; } - myform.action ="controller.pl?action=File/ajax_files_uploaded&json=1&object_type="+ - type+'&object_id='+id+'&file_type='+filetype+'&is_global='+is_global; + var fd = new FormData(myform); + if (!myform) { + $(myfiles).each(function(idx, elt) { + fd.append('uploadfiles[+]', elt); + }); + } + fd.append('action', 'File/ajax_files_uploaded'); + fd.append('json', 1); + fd.append('object_type', type); + fd.append('object_id', id); + fd.append('file_type', filetype); + fd.append('is_global', is_global); + var oReq = new XMLHttpRequest(); oReq.onload = ns.attSuccess; oReq.upload.onprogress = ns.attProgress; oReq.upload.onerror = ns.attFailed; oReq.upload.onabort = ns.attCanceled; - oReq.open("post",myform.action, true); + oReq.open("post", 'controller.pl', true); $("#upload_result").html(kivi.t8("start upload")); - oReq.send(new FormData(myform)); + oReq.send(fd); } ns.attProgress = function(oEvent) { @@ -155,6 +189,7 @@ namespace('kivi.File', function(ns) { } ns.attSuccess = function() { + $('#upload_status_dialog').dialog('close'); $('#files_upload').dialog('close'); kivi.eval_json_result(jQuery.parseJSON(this.response)); } @@ -265,4 +300,79 @@ namespace('kivi.File', function(ns) { $.download("controller.pl", data); return false; } + + ns.add_enlarged_thumbnail = function(e) { + var file_id = $(e.target).data('file-id'); + var overlay_img_id = 'enlarged_thumb_' + file_id; + var overlay_img = $('#' + overlay_img_id); + + if (overlay_img.data('is-overlay-shown') == 1) return; + + $('.thumbnail').off('mouseover'); + overlay_img.data('is-overlay-shown', 1); + overlay_img.show(); + + if (overlay_img.data('is-overlay-loaded') == 1) return; + + var data = { + action: 'File/ajax_get_thumbnail', + file_id: file_id, + file_version: $(e.target).data('file-version'), + size: 512 + }; + + $.post("controller.pl", data, kivi.eval_json_result); + }; + + ns.remove_enlarged_thumbnail = function(e) { + $(e.target).hide(); + $(e.target).data('is-overlay-shown', 0); + $('.thumbnail').on('mouseover', ns.add_enlarged_thumbnail); + }; + + ns.init = function() { + // Preventing page from redirecting + $("#" + ns.list_div_id).on("dragover", function(e) { + e.preventDefault(); + e.stopPropagation(); + }); + + $("#" + ns.list_div_id).on("drop", function(e) { + e.preventDefault(); + e.stopPropagation(); + }); + + // Drag enter + $('.upload_drop_zone').on('dragenter', function (e) { + e.stopPropagation(); + e.preventDefault(); + }); + + // Drag over + $('.upload_drop_zone').on('dragover', function (e) { + e.stopPropagation(); + e.preventDefault(); + }); + + // Drop + $('.upload_drop_zone').on('drop', function (e) { + e.stopPropagation(); + e.preventDefault(); + + ns.upload_status_dialog(); + + var object_type = $(e.target).data('object-type'); + var object_id = $(e.target).data('object-id'); + var file_type = $(e.target).data('file-type'); + var is_global = $(e.target).data('is-global'); + var maxsize = $(e.target).data('maxsize'); + var files = e.originalEvent.dataTransfer.files; + ns.upload_files(object_id, object_type, file_type, maxsize, is_global, files); + }); + + $('.thumbnail').on('mouseover', ns.add_enlarged_thumbnail); + $('.overlay_img').on('click', ns.remove_enlarged_thumbnail); + $('.overlay_img').on('mouseout', ns.remove_enlarged_thumbnail); + }; + });