Close modal with esc (#10929)

* added var to check if modal is open and an if for escape fullview

* moved showconfirmmodal to utils, showconfirmmodal now uses showmodal, esc works in textinput

* made esc global
This commit is contained in:
Patrick O'Carroll
2018-02-16 09:14:32 +01:00
committed by Torkel Ödegaard
parent 2c5f3fbc5b
commit 244ae555d9
5 changed files with 80 additions and 134 deletions

View File

@@ -10,6 +10,7 @@ export class UtilSrv {
init() {
appEvents.on('show-modal', this.showModal.bind(this), this.$rootScope);
appEvents.on('hide-modal', this.hideModal.bind(this), this.$rootScope);
appEvents.on('confirm-modal', this.showConfirmModal.bind(this), this.$rootScope);
}
hideModal() {
@@ -47,6 +48,38 @@ export class UtilSrv {
modalEl.modal('show');
});
}
showConfirmModal(payload) {
var scope = this.$rootScope.$new();
scope.onConfirm = function() {
payload.onConfirm();
scope.dismiss();
};
scope.updateConfirmText = function(value) {
scope.confirmTextValid = payload.confirmText.toLowerCase() === value.toLowerCase();
};
scope.title = payload.title;
scope.text = payload.text;
scope.text2 = payload.text2;
scope.confirmText = payload.confirmText;
scope.onConfirm = payload.onConfirm;
scope.onAltAction = payload.onAltAction;
scope.altActionText = payload.altActionText;
scope.icon = payload.icon || 'fa-check';
scope.yesText = payload.yesText || 'Yes';
scope.noText = payload.noText || 'Cancel';
scope.confirmTextValid = scope.confirmText ? false : true;
appEvents.emit('show-modal', {
src: 'public/app/partials/confirm_modal.html',
scope: scope,
modalClass: 'confirm-modal',
});
}
}
coreModule.service('utilSrv', UtilSrv);