diff options
author | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-03-13 17:26:37 +0100 |
---|---|---|
committer | Jörn Friedrich Dreyer <jfd@butonic.de> | 2013-03-28 18:17:18 +0100 |
commit | c1a944a655239ae44af27dfa939a39c703c41cb2 (patch) | |
tree | d9b1eaa00fa0395448b95d4bca2c9da325a5ed0d /apps | |
parent | 4dd4167f803c7dd3d5fd9bc586ed2363dbf954bb (diff) | |
download | nextcloud-server-c1a944a655239ae44af27dfa939a39c703c41cb2.tar.gz nextcloud-server-c1a944a655239ae44af27dfa939a39c703c41cb2.zip |
return created table row, use as context in fileupload events
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files/js/filelist.js | 164 |
1 files changed, 153 insertions, 11 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 1db54f45bb8..4fdb76b1026 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -88,17 +88,17 @@ var FileList={ $('#permissions').val() ); - FileList.insertElement(name, 'file', tr.attr('data-file',name)); - var row = $('tr').filterAttr('data-file',name); + FileList.insertElement(name, 'file', tr); if(loading){ - row.data('loading',true); + tr.data('loading',true); }else{ - row.find('td.filename').draggable(dragOptions); + tr.find('td.filename').draggable(dragOptions); } if (hidden) { - row.hide(); + tr.hide(); } - FileActions.display(row.find('td.filename')); + FileActions.display(tr.find('td.filename')); + return tr; }, addDir:function(name,size,lastModified,hidden){ @@ -113,13 +113,14 @@ var FileList={ ); FileList.insertElement(name,'dir',tr); - var row = $('tr').filterAttr('data-file',name); - row.find('td.filename').draggable(dragOptions); - row.find('td.filename').droppable(folderDropOptions); + var td = tr.find('td.filename'); + td.draggable(dragOptions); + td.droppable(folderDropOptions); if (hidden) { - row.hide(); + tr.hide(); } - FileActions.display(row.find('td.filename')); + FileActions.display(tr.find('td.filename')); + return tr; }, refresh:function(data) { var result = jQuery.parseJSON(data.responseText); @@ -351,6 +352,147 @@ var FileList={ }; $(document).ready(function(){ + + // handle upload events + $('#file_upload_start').on('fileuploaddrop', function(e, data) { + // only handle drop to dir if fileList exists + if ($('#fileList').length > 0) { + var dropTarget = $(e.originalEvent.target).closest('tr'); + if(dropTarget && dropTarget.data('type') === 'dir') { // drag&drop upload to folder + var dirName = dropTarget.data('file'); + // update folder in form + data.formData = function(form) { + var formArray = form.serializeArray(); + // array index 0 contains the max files size + // array index 1 contains the request token + // array index 2 contains the directory + var parentDir = formArray[2]['value']; + if (parentDir === '/') { + formArray[2]['value'] += dirName; + } else { + formArray[2]['value'] += '/'+dirName; + } + return formArray; + } + } + } + }); + $('#file_upload_start').on('fileuploadadd', function(e, data) { + // only add to fileList if it exists + if ($('#fileList').length > 0) { + + if(FileList.deleteFiles && FileList.deleteFiles.indexOf(data.files[0].name)!=-1){//finish delete if we are uploading a deleted file + FileList.finishDelete(null, true); //delete file before continuing + } + + // add ui visualization to existing folder or as new stand-alone file? + var dropTarget = $(e.originalEvent.target).closest('tr'); + if(dropTarget && dropTarget.data('type') === 'dir') { + // add to existing folder + var dirName = dropTarget.data('file'); + + // set dir context + data.context = $('tr').filterAttr('data-type', 'dir').filterAttr('data-file', dirName); + + // update upload counter ui + var uploadtext = data.context.find('.uploadtext'); + var currentUploads = parseInt(uploadtext.attr('currentUploads')); + currentUploads += 1; + uploadtext.attr('currentUploads', currentUploads); + if(currentUploads === 1) { + var img = OC.imagePath('core', 'loading.gif'); + data.context.find('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.text(t('files', '1 file uploading')); + uploadtext.show(); + } else { + uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); + } + } else { + // add as stand-alone row to filelist + var uniqueName = getUniqueName(data.files[0].name); + var size=t('files','Pending'); + if(data.files[0].size>=0){ + size=data.files[0].size; + } + var date=new Date(); + // create new file context + data.context = FileList.addFile(uniqueName,size,date,true,false); + + } + } + }); + $('#file_upload_start').on('fileuploaddone', function(e, data) { + // only update the fileList if it exists + if ($('#fileList').length > 0) { + var response; + if (typeof data.result === 'string') { + response = data.result; + } else { + // fetch response from iframe + response = data.result[0].body.innerText; + } + var result=$.parseJSON(response); + + if(typeof result[0] !== 'undefined' && result[0].status === 'success') { + var file = result[0]; + + if (data.context.data('type') === 'file') { + // update file data + data.context.attr('data-mime',file.mime).attr('data-id',file.id); + var size = data.context.data('size'); + if(size!=file.size){ + data.context.attr('data-size', file.size); + data.context.find('td.filesize').text(humanFileSize(file.size)); + } + if (FileList.loadingDone) { + FileList.loadingDone(file.name, file.id); + } + } else { + // update upload counter ui + var uploadtext = data.context.find('.uploadtext'); + var currentUploads = parseInt(uploadtext.attr('currentUploads')); + currentUploads -= 1; + uploadtext.attr('currentUploads', currentUploads); + if(currentUploads === 0) { + var img = OC.imagePath('core', 'filetypes/folder.png'); + data.context.find('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.text(''); + uploadtext.hide(); + } else { + uploadtext.text(currentUploads + ' ' + t('files', 'files uploading')); + } + + // update folder size + var size = parseInt(data.context.data('size')); + size += parseInt(file.size) ; + data.context.attr('data-size', size); + data.context.find('td.filesize').text(humanFileSize(size)); + + } + } + } + }); + $('#file_upload_start').on('fileuploadfail', function(e, data) { + // only update the fileList if it exists + // cleanup files, error notification has been shown by fileupload code + var tr = data.context; + if (typeof tr === 'undefined') { + tr = $('tr').filterAttr('data-file', data.files[0].name); + } + if (tr.attr('data-type') === 'dir') { + //cleanup uploading to a dir + var uploadtext = tr.find('.uploadtext'); + var img = OC.imagePath('core', 'filetypes/folder.png'); + tr.find('td.filename').attr('style','background-image:url('+img+')'); + uploadtext.text(''); + uploadtext.hide(); //TODO really hide already + } else { + //remove file + tr.fadeOut(); + tr.remove(); + } + }); + $('#notification').hide(); $('#notification').on('click', '.undo', function(){ if (FileList.deleteFiles) { |