From 4e89a0faf652f2f100cca47cca54a3b35e720aad Mon Sep 17 00:00:00 2001 From: Simon Birnbach Date: Tue, 27 Mar 2012 21:38:55 +0200 Subject: Added uploading to folder and cancellable downloads --- files/js/files.js | 173 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 143 insertions(+), 30 deletions(-) (limited to 'files/js/files.js') diff --git a/files/js/files.js b/files/js/files.js index 5f61bdd2ac3..6eed25dfe99 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -1,3 +1,25 @@ +var uploadingFiles = {}; +Files={ + cancelUpload:function(filename) { + if(uploadingFiles[filename]) { + uploadingFiles[filename].abort(); + delete uploadingFiles[filename]; + return true; + } + return false; + }, + cancelUploads:function() { + $.each(uploadingFiles,function(index,file){ + file.abort(); + delete uploadingFiles[index]; + var filename = $('tr').filterAttr('data-file',index); + filename.hide(); + filename.find('input[type="checkbox"]').removeAttr('checked'); + filename.removeClass('selected'); + }); + procesSelection(); + } +} $(document).ready(function() { $('#fileList tr').each(function(){ //little hack to set unescape filenames in attribute @@ -151,9 +173,13 @@ $(document).ready(function() { }); // drag&drop support using jquery.fileupload + $(document).bind('drop dragover', function (e) { + e.preventDefault(); // prevent browser from doing anything, if file isn't dropped in dropZone + }); + $(function() { $('.file_upload_start').fileupload({ - //dropZone: $('#content'), // restrict dropZone to content div + dropZone: $('#content'), // restrict dropZone to content div add: function(e, data) { var files = data.files; var totalSize=0; @@ -178,7 +204,97 @@ $(document).ready(function() { } }); }else{ - data.submit(); + if($.support.xhrFileUpload) { + for(var i=0;i tr').not('[data-mime]').fadeOut(); + $('#fileList > tr').not('[data-mime]').remove(); + } + }) + .error(function(jqXHR, textStatus, errorThrown) { + if(errorThrown === 'abort') { + $('#notification').hide(); + $('#notification').text(t('files', 'Upload cancelled.')); + $('#notification').fadeIn(); + } + }); + } + uploadingFiles[files[i].name] = jqXHR; + } + }else{ + data.submit().success(function(data, status) { + response = jQuery.parseJSON(data[0].body.innerText); + if(response[0] != undefined && response[0].status == 'success') { + var file=response[0]; + delete uploadingFiles[file.name]; + $('tr').filterAttr('data-file',file.name).data('mime',file.mime); + var size = $('tr').filterAttr('data-file',file.name).find('td.filesize').text(); + if(size==t('files','Pending')){ + $('tr').filterAttr('data-file',file.name).find('td.filesize').text(file.size); + } + FileList.loadingDone(file.name); + } else { + $('#notification').text(t('files', response.data.message)); + $('#notification').fadeIn(); + $('#fileList > tr').not('[data-mime]').fadeOut(); + $('#fileList > tr').not('[data-mime]').remove(); + } + }); + } + var date=new Date(); if(files){ for(var i=0;i tr').not('[data-mime]').fadeOut(); - $('#fileList > tr').not('[data-mime]').remove(); - } - }, fail: function(e, data) { // TODO: cancel upload & display error notification }, @@ -230,17 +338,22 @@ $(document).ready(function() { $('#uploadprogressbar').progressbar('value',progress); }, start: function(e, data) { - $('#uploadprogressbar').progressbar({value:0}); - $('#uploadprogressbar').fadeIn(); + $('#uploadprogressbar').progressbar({value:0}); + $('#uploadprogressbar').fadeIn(); + if(data.dataType != 'iframe ') { + $('#upload input.stop').show(); + } }, stop: function(e, data) { - $('#uploadprogressbar').progressbar('value',100); - $('#uploadprogressbar').fadeOut(); + if(data.dataType != 'iframe ') { + $('#upload input.stop').hide(); + } + $('#uploadprogressbar').progressbar('value',100); + $('#uploadprogressbar').fadeOut(); } }) }); - //add multiply file upload attribute to all browsers except konqueror (which crashes when it's used) if(navigator.userAgent.search(/konqueror/i)==-1){ -- cgit v1.2.3