diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-09-15 18:13:45 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-09-15 18:13:45 +0200 |
commit | 98ee32b91c7111aa9b73f72950350819b591d39c (patch) | |
tree | 7d021fa19dece0fe7360fa85664d05722749c097 /apps/files/js/filelist.js | |
parent | 5767659d226a47d59bc6a024033e54c3741eebc7 (diff) | |
download | nextcloud-server-98ee32b91c7111aa9b73f72950350819b591d39c.tar.gz nextcloud-server-98ee32b91c7111aa9b73f72950350819b591d39c.zip |
Don't show success notifications for failed copy actions and update folder sizes
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'apps/files/js/filelist.js')
-rw-r--r-- | apps/files/js/filelist.js | 92 |
1 files changed, 59 insertions, 33 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index d67cb409b1e..9a073fe9d29 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -2050,10 +2050,14 @@ */ copy: function(fileNames, targetPath, callback) { var self = this; + var filesToNotify = []; + var count = 0; + var dir = this.getCurrentDirectory(); if (dir.charAt(dir.length - 1) !== '/') { dir += '/'; } + var target = OC.basename(targetPath); if (!_.isArray(fileNames)) { fileNames = [fileNames]; } @@ -2066,6 +2070,20 @@ targetPath = targetPath + '/'; } self.filesClient.copy(dir + fileName, targetPath + fileName) + .done(function () { + filesToNotify.push(fileName); + + // if still viewing the same directory + if (OC.joinPaths(self.getCurrentDirectory(), '/') === dir) { + // recalculate folder size + var oldFile = self.findFileEl(target); + var newFile = self.findFileEl(fileName); + var oldSize = oldFile.data('size'); + var newSize = oldSize + newFile.data('size'); + oldFile.data('size', newSize); + oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize)); + } + }) .fail(function(status) { if (status === 412) { // TODO: some day here we should invoke the conflict dialog @@ -2080,42 +2098,50 @@ }) .always(function() { self.showFileBusyState($tr, false); + count++; + + /** + * We only show the notifications once the last file has been copied + */ + if (count === fileNames.length) { + // Remove leading and ending / + if (targetPath.slice(0, 1) === '/') { + targetPath = targetPath.slice(1, targetPath.length); + } + if (targetPath.slice(-1) === '/') { + targetPath = targetPath.slice(0, -1); + } + + if (filesToNotify.length > 0) { + // Since there's no visual indication that the files were copied, let's send some notifications ! + if (filesToNotify.length === 1) { + OC.Notification.show(t('files', 'Copied {origin} inside {destination}', + { + origin: filesToNotify[0], + destination: targetPath + } + ), {timeout: 10}); + } else if (filesToNotify.length > 0 && filesToNotify.length < 3) { + OC.Notification.show(t('files', 'Copied {origin} inside {destination}', + { + origin: filesToNotify.join(', '), + destination: targetPath + } + ), {timeout: 10}); + } else { + OC.Notification.show(t('files', 'Copied {origin} and {nbfiles} other files inside {destination}', + { + origin: filesToNotify[0], + nbfiles: filesToNotify.length - 1, + destination: targetPath + } + ), {timeout: 10}); + } + } + } }); }); - // Remove leading and ending / - if (targetPath.slice(0, 1) === '/') { - targetPath = targetPath.slice(1, targetPath.length); - } - if (targetPath.slice(-1) === '/') { - targetPath = targetPath.slice(0, -1); - } - - // Since there's no visual indication that the files were copied, let's send some notifications ! - if (fileNames.length === 1) { - OC.Notification.show(t('files', 'Copied {origin} inside {destination}', - { - origin: fileNames[0], - destination: targetPath - } - ), {timeout: 10}); - } else if (fileNames.length < 4) { - OC.Notification.show(t('files', 'Copied {origin} inside {destination}', - { - origin: fileNames.join(', '), - destination: targetPath - } - ), {timeout: 10}); - } else { - OC.Notification.show(t('files', 'Copied {origin} and {nbfiles} other files inside {destination}', - { - origin: fileNames[0], - nbfiles: fileNames.length, - destination: targetPath, - } - ), {timeout: 10}); - } - if (callback) { callback(); } |