Commit e093e788 authored by asseldonk's avatar asseldonk
Browse files

filebrowser: allow drag and drop of multiple files

parent 956fa643
......@@ -179,40 +179,32 @@ var FileBaseEvents = Class.extend({
dragAndDrop: function(node, data) {
var self = this;
// dragstart
node.on("dragstart", function(event) {
event.originalEvent.dataTransfer.setData("dataName", data.name);
// opacity on dragged node
node.toggleClass("dragstart", true);
// a bit of permissions
/* var path = self.FileBase.workflow.path +"/" + data.name;
var dfd = self.FileBase.instance.GET("/ajax/fs/checkPermissions", {
"path": JSON.stringify(path)
});
dfd.done(function(result) {
// toggle class for node if permission = true
if (result.permission === true) {
$(node).toggleClass("dragstart", true);
} else {
// if no permissions, do not allow any effects
event.originalEvent.dataTransfer.effectAllowed = "none";
if (data.type == "d") {
vispa.messenger.info("No permissions to move directory", "glyphicon glyphicon-remove");
} else {
vispa.messenger.info("No permissions to move file", "glyphicon glyphicon-remove");
}
}
});*/
// end a bit of permissions
// if node is not selected, select it
if (! self.FileBase.selections.entries[self.FileBase.helper.abspath(data.name)]) {
self.FileBase.selections.changeSelection(node, true);
}
// opacity on selected and dragged node
var selectedItems = Object.keys(self.FileBase.selections.entries);
for (var i = 0; i < selectedItems.length; i++) {
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass("dragstart", true);
}
});
// dragend
node.on("dragend", function(event) {
event.preventDefault();
// remove all potential set css classes
// remove all potential set css classes from selected items
var selectedItems = Object.keys(self.FileBase.selections.entries);
for (var i = 0; i < selectedItems.length; i++) {
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass(
"stop-pointer-events", false);
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass("dragstart", false);
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass("dragover", false);
}
// remove all potential set css classes from element on which dragend occurs
node.toggleClass("stop-pointer-events", false);
node.toggleClass("dragstart", false);
node.toggleClass("dragover", false);
......@@ -260,17 +252,25 @@ var FileBaseEvents = Class.extend({
// drop
node.on("drop", function(event) {
event.preventDefault();
// remove all potential set css classes
// remove potentially set css classes from selected items
var selectedItems = Object.keys(self.FileBase.selections.entries);
for (var i = 0; i < selectedItems.length; i++) {
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass(
"stop-pointer-events", false);
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass("dragstart", false);
$(self.FileBase.selections.entries[selectedItems[i]]).toggleClass("dragover", false);
}
// remove potentially set css classes from item on which drop occurs (= target)
node.toggleClass("stop-pointer-events", false);
node.toggleClass("dragstart", false);
node.toggleClass("dragover", false);
// get file which was dragged and now dropped
var fileToBeMoved = (event.originalEvent.dataTransfer.getData("dataName"));
// if transfered data empty: upload file
// if transfered data empty: no drag but upload
var path = "";
if (fileToBeMoved === "") {
// set path of file/folder to move
// path = data.type == "d" ? self.FileBase.workflow.path + "/" + data.name : self.FileBase.workflow.path;
// path = (data.type == "d" ? (self.FileBase.workflow.path + "/" + data.name) : self.FileBase.workflow.path);
if (data.type == "d") {
path = self.FileBase.workflow.path + "/" + data.name;
} else {
......@@ -281,11 +281,22 @@ var FileBaseEvents = Class.extend({
// if transfered data not empty: move file
else {
if (data.type == "d") {
var source = self.FileBase.workflow.path + "/" + fileToBeMoved;
var destination = self.FileBase.workflow.path + "/" + data.name;
if (source != destination) {
// var destination = self.FileBase.workflow.path + "/" + data.name;
var destination = self.FileBase.helper.abspath(data.name);
var source = [];
for (var k = 0; k < selectedItems.length; k++) {
var name = self.FileBase.selections.entries[selectedItems[k]].data("data").name;
var sourceItem = self.FileBase.helper.abspath(name);
if (sourceItem != destination) {
source.push(self.FileBase.helper.abspath(name));
}
}
// move
if (source.length > 0) {
self.FileBase.actions.move(source, destination);
}
// clear file to be moved
fileToBeMoved = "";
}
}
});
......
......@@ -97,6 +97,7 @@ var FileBaseSelections = Class.extend({
var selectbox = $(":checkbox", selectp);
if (!selectbox.is(":checked")) {
allSelected = false;
break;
}
}
if (allSelected === true) {
......
......@@ -300,10 +300,15 @@ class FileSystem(object):
os.remove(path)
def move(self, source, destination):
source = self.expand(source)
destination = self.expand(destination)
if os.path.isdir(destination):
shutil.move(source, destination)
if isinstance(source, list):
for s in source:
self.move(s, destination)
else:
#source = self.handle_file_name_collision(source, path)
source = self.expand(source)
destination = self.expand(destination)
if os.path.isdir(destination):
shutil.move(source, destination)
def compress(self, path, paths, name):
# paths has to be a list of strings
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment