Skip to content

Commit d8b7545

Browse files
committed
confirmation for deletion
1 parent 735eb9d commit d8b7545

File tree

1 file changed

+54
-49
lines changed

1 file changed

+54
-49
lines changed

services/static-webserver/client/source/class/osparc/file/FileLabelWithActions.js

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -156,81 +156,86 @@ qx.Class.define("osparc.file.FileLabelWithActions", {
156156
}
157157
},
158158

159+
__retrieveURLAndDownloadFile: function(file) {
160+
const fileId = file.getFileId();
161+
const locationId = file.getLocation();
162+
osparc.utils.Utils.retrieveURLAndDownload(locationId, fileId)
163+
.then(data => {
164+
if (data) {
165+
osparc.DownloadLinkTracker.getInstance().downloadLinkUnattended(data.link, data.fileName);
166+
}
167+
});
168+
},
169+
159170
__deleteSelected: function() {
171+
const toBeDeleted = [];
172+
let isFolderSelected = false;
160173
if (this.isMultiSelect()) {
161-
const requests = [];
162174
this.__selection.forEach(selection => {
163175
if (selection) {
164-
let request = null;
165-
if (osparc.file.FilesTree.isFile(selection)) {
166-
request = this.__deleteFile(selection);
167-
} else {
168-
request = this.__deleteFolder(selection);
169-
}
170-
if (request) {
171-
requests.push(request);
176+
toBeDeleted.push(selection);
177+
if (osparc.file.FilesTree.isDir(selection)) {
178+
isFolderSelected = true;
172179
}
173180
}
174181
});
175-
Promise.all(requests)
176-
.then(datas => {
177-
if (datas.length) {
178-
this.fireDataEvent("fileDeleted", datas[0]);
179-
osparc.FlashMessenger.getInstance().logAs(this.tr("Items successfully deleted"), "INFO");
180-
}
181-
});
182-
requests
183182
} else if (this.__selection.length) {
184183
const selection = this.__selection[0];
184+
if (selection) {
185+
if (osparc.file.FilesTree.isDir(selection)) {
186+
isFolderSelected = true;
187+
}
188+
}
189+
}
190+
191+
let msg = this.tr("This operation cannot be undone.");
192+
msg += isFolderSelected ? ("<br>"+this.tr("All the content of the folders will be deleted.")) : "";
193+
msg += "<br>" + this.tr("Do you want to proceed?");
194+
const confirmationWin = new osparc.ui.window.Confirmation(msg).set({
195+
caption: this.tr("Delete"),
196+
confirmText: this.tr("Delete"),
197+
confirmAction: "delete"
198+
});
199+
confirmationWin.center();
200+
confirmationWin.open();
201+
confirmationWin.addListener("close", () => {
202+
if (confirmationWin.getConfirmed()) {
203+
this.__doDeleteSelected(toBeDeleted);
204+
}
205+
}, this);
206+
},
207+
208+
__doDeleteSelected: function(toBeDeleted) {
209+
const requests = [];
210+
toBeDeleted.forEach(selection => {
185211
if (selection) {
186212
let request = null;
187213
if (osparc.file.FilesTree.isFile(selection)) {
188-
request = this.__deleteFile(selection);
214+
request = this.__deleteItem(selection.getFileId(), selection.getLocation());
189215
} else {
190-
request = this.__deleteFolder(selection);
216+
request = this.__deleteItem(selection.getPath(), selection.getLocation());
191217
}
192218
if (request) {
193-
request
194-
.then(data => {
195-
this.fireDataEvent("fileDeleted", data);
196-
osparc.FlashMessenger.getInstance().logAs(this.tr("Item successfully deleted"), "INFO");
197-
});
219+
requests.push(request);
198220
}
199221
}
200-
}
201-
},
202-
203-
__retrieveURLAndDownloadFile: function(file) {
204-
const fileId = file.getFileId();
205-
const locationId = file.getLocation();
206-
osparc.utils.Utils.retrieveURLAndDownload(locationId, fileId)
207-
.then(data => {
208-
if (data) {
209-
osparc.DownloadLinkTracker.getInstance().downloadLinkUnattended(data.link, data.fileName);
222+
});
223+
Promise.all(requests)
224+
.then(datas => {
225+
if (datas.length) {
226+
this.fireDataEvent("fileDeleted", datas[0]);
227+
osparc.FlashMessenger.getInstance().logAs(this.tr("Items successfully deleted"), "INFO");
210228
}
211229
});
212230
},
213231

214-
__deleteFile: function(file) {
215-
const fileId = file.getFileId();
216-
const locationId = file.getLocation();
217-
if (locationId !== 0 && locationId !== "0") {
218-
osparc.FlashMessenger.getInstance().logAs(this.tr("Only items in simcore.s3 can be deleted"));
219-
return null;
220-
}
221-
const dataStore = osparc.store.Data.getInstance();
222-
return dataStore.deleteFile(locationId, fileId);
223-
},
224-
225-
__deleteFolder: function(folder) {
226-
const path = folder.getPath();
227-
const locationId = folder.getLocation();
232+
__deleteItem: function(itemId, locationId) {
228233
if (locationId !== 0 && locationId !== "0") {
229234
osparc.FlashMessenger.getInstance().logAs(this.tr("Only items in simcore.s3 can be deleted"));
230235
return null;
231236
}
232237
const dataStore = osparc.store.Data.getInstance();
233-
return dataStore.deleteFile(locationId, path);
238+
return dataStore.deleteFile(locationId, itemId);
234239
},
235240
}
236241
});

0 commit comments

Comments
 (0)