Skip to content

Commit a7e87c0

Browse files
committed
dragOver and drop
1 parent be5def7 commit a7e87c0

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

services/static-webserver/client/source/class/osparc/dashboard/DragDropHelpers.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,43 @@ qx.Class.define("osparc.dashboard.DragDropHelpers", {
3838
// make it semi transparent while being dragged
3939
studyItem.setOpacity(0.2);
4040
},
41+
42+
dragOver: function(event, folderDest, folderItem) {
43+
let compatible = false;
44+
const studyDataOrigin = event.getData("osparc-moveStudy")["studyDataOrigin"];
45+
// Compatibility checks:
46+
// - My workspace
47+
// - None
48+
// - Shared workspace
49+
// - write access on workspace
50+
const workspaceId = studyDataOrigin["workspaceId"];
51+
if (workspaceId) {
52+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
53+
if (workspace) {
54+
compatible = workspace.getMyAccessRights()["write"];
55+
}
56+
} else {
57+
compatible = true;
58+
}
59+
if (compatible) {
60+
folderItem.getChildControl("icon").setTextColor("strong-main");
61+
} else {
62+
folderItem.getChildControl("icon").setTextColor("danger-red");
63+
// do not allow
64+
event.preventDefault();
65+
}
66+
const dragWidget = osparc.dashboard.DragWidget.getInstance();
67+
dragWidget.setDropAllowed(compatible);
68+
},
69+
70+
drop: function(event, folderDest) {
71+
const studyData = event.getData("osparc-moveStudy")["studyDataOrigin"];
72+
const studyToFolderData = {
73+
studyData,
74+
destFolderId: folderDest.getFolderId(),
75+
};
76+
return studyToFolderData;
77+
},
4178
},
4279

4380
moveFolder: {

services/static-webserver/client/source/class/osparc/dashboard/FolderButtonItem.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -176,34 +176,10 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
176176
this.setDroppable(true);
177177

178178
this.addListener("dragover", e => {
179+
const folderDest = this.getFolder();
179180
if (e.supportsType("osparc-moveStudy")) {
180-
let compatible = false;
181-
const studyData = e.getData("osparc-moveStudy")["studyDataOrigin"];
182-
// Compatibility checks:
183-
// - My workspace
184-
// - None
185-
// - Shared workspace
186-
// - write access on workspace
187-
const workspaceId = studyData["workspaceId"];
188-
if (workspaceId) {
189-
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
190-
if (workspace) {
191-
compatible = workspace.getMyAccessRights()["write"];
192-
}
193-
} else {
194-
compatible = true;
195-
}
196-
if (compatible) {
197-
this.getChildControl("icon").setTextColor("strong-main");
198-
} else {
199-
this.getChildControl("icon").setTextColor("danger-red");
200-
// do not allow
201-
e.preventDefault();
202-
}
203-
const dragWidget = osparc.dashboard.DragWidget.getInstance();
204-
dragWidget.setDropAllowed(compatible);
181+
osparc.dashboard.DragDropHelpers.moveStudy.dragOver(e, folderDest, this);
205182
} else if (e.supportsType("osparc-moveFolder")) {
206-
const folderDest = this.getFolder();
207183
osparc.dashboard.DragDropHelpers.moveFolder.dragOver(e, folderDest, this);
208184
}
209185
});
@@ -217,15 +193,11 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
217193
});
218194

219195
this.addListener("drop", e => {
196+
const folderDest = this.getFolder();
220197
if (e.supportsType("osparc-moveStudy")) {
221-
const studyData = e.getData("osparc-moveStudy")["studyDataOrigin"];
222-
const studyToFolderData = {
223-
studyData,
224-
destFolderId: this.getFolderId(),
225-
};
198+
const studyToFolderData = osparc.dashboard.DragDropHelpers.moveStudy.drop(e, folderDest);
226199
this.fireDataEvent("studyToFolderRequested", studyToFolderData);
227200
} else if (e.supportsType("osparc-moveFolder")) {
228-
const folderDest = this.getFolder();
229201
const folderToFolderData = osparc.dashboard.DragDropHelpers.moveFolder.drop(e, folderDest);
230202
this.fireDataEvent("folderToFolderRequested", folderToFolderData);
231203
}

0 commit comments

Comments
 (0)