Show a confirmation message, if you delete parts via part table select.

This commit is contained in:
Jan Böhmer 2022-08-01 00:50:05 +02:00
parent 452f0a8362
commit 4c574316c8
3 changed files with 66 additions and 1 deletions

View file

@ -1,5 +1,7 @@
import DatatablesController from "./datatables_controller.js";
import * as bootbox from "bootbox";
/**
* This is the datatables controller for parts lists
*/
@ -7,6 +9,8 @@ export default class extends DatatablesController {
static targets = ['dt', 'selectPanel', 'selectIDs', 'selectCount', 'selectTargetPicker'];
_confirmed = false;
isSelectable() {
//Parts controller is always selectable
return true;
@ -79,5 +83,46 @@ export default class extends DatatablesController {
$(select_target).selectpicker('hide');
}
}
confirmDeletionAtSubmit(event) {
//Only show the dialog when selected action is delete
if (event.target.elements["action"].value !== "delete") {
return;
}
//If a user has not already confirmed the deletion, just let turbo do its work
if(this._confirmed) {
this._confirmed = false;
return;
}
//Prevent turbo from doing its work
event.preventDefault();
const message = this.element.dataset.deleteMessage;
const title = this.element.dataset.deleteTitle;
const form = this.element;
const that = this;
//Create a clone of the event with the same submitter, so we can redispatch it if needed
//We need to do this that way, as we need the submitter info, just calling form.submit() would not work
this._our_event = new SubmitEvent('submit', {
submitter: event.submitter,
bubbles: true, //This line is important, otherwise Turbo will not receive the event
});
const confirm = bootbox.confirm({
message: message, title: title, callback: function (result) {
//If the dialog was confirmed, then submit the form.
if (result) {
that._confirmed = true;
form.dispatchEvent(that._our_event);
} else {
that._confirmed = false;
}
}
});
}
}