Don't show success notifications for failed copy actions and update folder sizes
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
5767659d22
commit
98ee32b91c
|
@ -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,9 +2098,12 @@
|
|||
})
|
||||
.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);
|
||||
|
@ -2091,30 +2112,35 @@
|
|||
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 (fileNames.length === 1) {
|
||||
if (filesToNotify.length === 1) {
|
||||
OC.Notification.show(t('files', 'Copied {origin} inside {destination}',
|
||||
{
|
||||
origin: fileNames[0],
|
||||
origin: filesToNotify[0],
|
||||
destination: targetPath
|
||||
}
|
||||
), {timeout: 10});
|
||||
} else if (fileNames.length < 4) {
|
||||
} else if (filesToNotify.length > 0 && filesToNotify.length < 3) {
|
||||
OC.Notification.show(t('files', 'Copied {origin} inside {destination}',
|
||||
{
|
||||
origin: fileNames.join(', '),
|
||||
origin: filesToNotify.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,
|
||||
origin: filesToNotify[0],
|
||||
nbfiles: filesToNotify.length - 1,
|
||||
destination: targetPath
|
||||
}
|
||||
), {timeout: 10});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
|
|
Loading…
Reference in New Issue