diff --git a/src/js/filemanager.js b/src/js/filemanager.js index 85c6beaa9..be4d74339 100644 --- a/src/js/filemanager.js +++ b/src/js/filemanager.js @@ -205,16 +205,28 @@ app.controller('FileManagerController', ['$scope', '$translate', '$timeout', 'Cl var targetFolder = sanitize($scope.cwd + '/' + (entry && entry.isDirectory ? entry.fileName : '')); var dataTransfer = event.originalEvent.dataTransfer; + // check if we have internal drag'n'drop if (dataTransfer.getData('application/cloudron-filemanager')) { - var oldFilePath = sanitize($scope.cwd + '/' + dataTransfer.getData('application/cloudron-filemanager')); - var newFilePath = sanitize(targetFolder + '/' + dataTransfer.getData('application/cloudron-filemanager')); + if ($scope.selected.length === 0) return; - if (oldFilePath === newFilePath) return; + // move files + async.eachLimit($scope.selected, 5, function (entry, callback) { + var newFilePath = sanitize(targetFolder + '/' + entry.fileName); + var oldFilePath = sanitize($scope.cwd + '/' + entry.fileName); - return Client.filesRename($scope.id, $scope.type, oldFilePath, newFilePath, function (error) { + if (newFilePath === oldFilePath) return callback(); + + // TODO this will overwrite files in destination! + Client.filesRename($scope.id, $scope.type, oldFilePath, newFilePath, callback); + }, function (error) { if (error) return Client.error(error); + + $scope.selected = []; + $scope.refresh(); }); + + return; } // figure if a folder was dropped on a modern browser, in this case the first would have to be a directory