mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Added new confirm-dialog component, both view and logic
This commit is contained in:
53
resources/js/components/confirm-dialog.js
Normal file
53
resources/js/components/confirm-dialog.js
Normal file
@ -0,0 +1,53 @@
|
||||
import {onSelect} from "../services/dom";
|
||||
|
||||
/**
|
||||
* Custom equivalent of window.confirm() using our popup component.
|
||||
* Is promise based so can be used like so:
|
||||
* `const result = await dialog.show()`
|
||||
* @extends {Component}
|
||||
*/
|
||||
class ConfirmDialog {
|
||||
|
||||
setup() {
|
||||
this.container = this.$el;
|
||||
this.confirmButton = this.$refs.confirm;
|
||||
|
||||
this.res = null;
|
||||
|
||||
onSelect(this.confirmButton, () => {
|
||||
this.sendResult(true);
|
||||
this.getPopup().hide();
|
||||
});
|
||||
}
|
||||
|
||||
show() {
|
||||
this.getPopup().show(null, () => {
|
||||
this.sendResult(false);
|
||||
});
|
||||
|
||||
return new Promise((res, rej) => {
|
||||
this.res = res;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Popup}
|
||||
*/
|
||||
getPopup() {
|
||||
return this.container.components.popup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Boolean} result
|
||||
*/
|
||||
sendResult(result) {
|
||||
if (this.res) {
|
||||
console.log('sending result', result);
|
||||
this.res(result)
|
||||
this.res = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ConfirmDialog;
|
Reference in New Issue
Block a user