2022-08-15 16:06:30 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import { assert } from '@ember/debug';
|
2022-08-18 16:53:56 +00:00
|
|
|
import { tracked } from '@glimmer/tracking';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
2019-04-03 21:06:20 +00:00
|
|
|
/**
|
|
|
|
* @module ConfirmAction
|
2019-08-27 22:50:53 +00:00
|
|
|
* `ConfirmAction` is a button followed by a pop up confirmation message and button used to prevent users from performing actions they do not intend to.
|
2019-04-03 21:06:20 +00:00
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* ```js
|
|
|
|
* <ConfirmAction
|
|
|
|
* @onConfirmAction={{ () => { console.log('Action!') } }}
|
|
|
|
* @confirmMessage="Are you sure you want to delete this config?">
|
|
|
|
* Delete
|
|
|
|
* </ConfirmAction>
|
|
|
|
* ```
|
|
|
|
*
|
2022-08-15 16:06:30 +00:00
|
|
|
* @param {Func} [onConfirmAction=null] - The action to take upon confirming.
|
|
|
|
* @param {String} [confirmTitle=Delete this?] - The title to display when confirming.
|
|
|
|
* @param {String} [confirmMessage=You will not be able to recover it later.] - The message to display when confirming.
|
|
|
|
* @param {String} [confirmButtonText=Delete] - The confirm button text.
|
|
|
|
* @param {String} [cancelButtonText=Cancel] - The cancel button text.
|
|
|
|
* @param {String} [buttonClasses] - A string to indicate the button class.
|
|
|
|
* @param {String} [horizontalPosition=auto-right] - For the position of the dropdown.
|
|
|
|
* @param {String} [verticalPosition=below] - For the position of the dropdown.
|
|
|
|
* @param {Boolean} [isRunning=false] - If action is still running disable the confirm.
|
|
|
|
* @param {Boolean} [disable=false] - To disable the confirm action.
|
2019-04-03 21:06:20 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-15 16:06:30 +00:00
|
|
|
export default class ConfirmActionComponent extends Component {
|
2022-08-18 16:53:56 +00:00
|
|
|
@tracked showConfirm = false;
|
|
|
|
|
2022-08-15 16:06:30 +00:00
|
|
|
get horizontalPosition() {
|
|
|
|
return this.args.horizontalPosition || 'auto-right';
|
|
|
|
}
|
|
|
|
|
|
|
|
get verticalPosition() {
|
|
|
|
return this.args.verticalPosition || 'below';
|
|
|
|
}
|
|
|
|
|
|
|
|
get isRunning() {
|
|
|
|
return this.args.isRunning || false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get disabled() {
|
|
|
|
return this.args.disabled || false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get confirmTitle() {
|
|
|
|
return this.args.confirmTitle || 'Delete this?';
|
|
|
|
}
|
|
|
|
|
|
|
|
get confirmMessage() {
|
|
|
|
return this.args.confirmMessage || 'You will not be able to recover it later.';
|
|
|
|
}
|
|
|
|
|
|
|
|
get confirmButtonText() {
|
|
|
|
return this.args.confirmButtonText || 'Delete';
|
|
|
|
}
|
|
|
|
|
|
|
|
get cancelButtonText() {
|
|
|
|
return this.args.cancelButtonText || 'Cancel';
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
toggleConfirm() {
|
|
|
|
// toggle
|
|
|
|
this.showConfirm = !this.showConfirm;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
2022-08-18 16:53:56 +00:00
|
|
|
onConfirm(actions) {
|
2022-08-15 16:06:30 +00:00
|
|
|
const confirmAction = this.args.onConfirmAction;
|
|
|
|
|
|
|
|
if (typeof confirmAction !== 'function') {
|
|
|
|
assert('confirm-action components expects `onConfirmAction` attr to be a function');
|
|
|
|
} else {
|
|
|
|
confirmAction();
|
2022-08-18 16:53:56 +00:00
|
|
|
// close the dropdown content
|
|
|
|
actions.close();
|
2022-08-15 16:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|