github.com/DerekStrickland/consul@v1.4.5/ui-v2/app/components/confirmation-dialog.js (about) 1 /*eslint ember/closure-actions: "warn"*/ 2 import Component from '@ember/component'; 3 4 import SlotsMixin from 'block-slots'; 5 import { get, set } from '@ember/object'; 6 import { inject as service } from '@ember/service'; 7 8 const cancel = function() { 9 set(this, 'confirming', false); 10 }; 11 const execute = function() { 12 this.sendAction(...['actionName', ...get(this, 'arguments')]); 13 }; 14 const confirm = function() { 15 const [action, ...args] = arguments; 16 set(this, 'actionName', action); 17 set(this, 'arguments', args); 18 if (this._isRegistered('dialog')) { 19 set(this, 'confirming', true); 20 } else { 21 get(this, 'confirm') 22 .execute(get(this, 'message')) 23 .then(confirmed => { 24 if (confirmed) { 25 this.execute(); 26 } 27 }) 28 .catch(function() { 29 return get(this, 'error').execute(...arguments); 30 }); 31 } 32 }; 33 export default Component.extend(SlotsMixin, { 34 classNameBindings: ['confirming'], 35 confirm: service('confirm'), 36 error: service('error'), 37 classNames: ['with-confirmation'], 38 message: 'Are you sure?', 39 confirming: false, 40 permanent: false, 41 init: function() { 42 this._super(...arguments); 43 this.cancel = cancel.bind(this); 44 this.execute = execute.bind(this); 45 this.confirm = confirm.bind(this); 46 }, 47 });