2017-12-20 05:33:33 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
import appEvents from 'app/core/app_events';
|
2016-03-25 16:14:29 -05:00
|
|
|
|
|
|
|
export class UtilSrv {
|
2016-11-02 06:55:58 -05:00
|
|
|
modalScope: any;
|
2016-03-25 16:14:29 -05:00
|
|
|
|
|
|
|
/** @ngInject */
|
2017-12-19 09:06:54 -06:00
|
|
|
constructor(private $rootScope, private $modal) {}
|
2016-03-25 16:14:29 -05:00
|
|
|
|
|
|
|
init() {
|
2017-12-20 05:33:33 -06:00
|
|
|
appEvents.on('show-modal', this.showModal.bind(this), this.$rootScope);
|
|
|
|
appEvents.on('hide-modal', this.hideModal.bind(this), this.$rootScope);
|
2018-02-16 02:14:32 -06:00
|
|
|
appEvents.on('confirm-modal', this.showConfirmModal.bind(this), this.$rootScope);
|
2016-11-04 11:19:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
hideModal() {
|
|
|
|
if (this.modalScope && this.modalScope.dismiss) {
|
|
|
|
this.modalScope.dismiss();
|
|
|
|
}
|
2016-03-25 16:14:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
showModal(options) {
|
2016-11-02 06:55:58 -05:00
|
|
|
if (this.modalScope && this.modalScope.dismiss) {
|
|
|
|
this.modalScope.dismiss();
|
|
|
|
}
|
|
|
|
|
2016-11-03 14:32:36 -05:00
|
|
|
this.modalScope = options.scope;
|
|
|
|
|
2016-11-04 05:43:44 -05:00
|
|
|
if (options.model) {
|
|
|
|
this.modalScope = this.$rootScope.$new();
|
|
|
|
this.modalScope.model = options.model;
|
|
|
|
} else if (!this.modalScope) {
|
|
|
|
this.modalScope = this.$rootScope.$new();
|
|
|
|
}
|
|
|
|
|
2018-08-26 14:52:57 -05:00
|
|
|
const modal = this.$modal({
|
2016-03-25 16:14:29 -05:00
|
|
|
modalClass: options.modalClass,
|
|
|
|
template: options.src,
|
2016-05-13 10:39:22 -05:00
|
|
|
templateHtml: options.templateHtml,
|
2016-03-25 16:14:29 -05:00
|
|
|
persist: false,
|
|
|
|
show: false,
|
2016-11-04 05:43:44 -05:00
|
|
|
scope: this.modalScope,
|
2016-05-14 03:00:43 -05:00
|
|
|
keyboard: false,
|
2017-12-20 05:33:33 -06:00
|
|
|
backdrop: options.backdrop,
|
2016-03-25 16:14:29 -05:00
|
|
|
});
|
|
|
|
|
2018-09-05 00:47:30 -05:00
|
|
|
Promise.resolve(modal).then(modalEl => {
|
2017-12-20 05:33:33 -06:00
|
|
|
modalEl.modal('show');
|
2016-03-25 16:14:29 -05:00
|
|
|
});
|
|
|
|
}
|
2018-02-16 02:14:32 -06:00
|
|
|
|
|
|
|
showConfirmModal(payload) {
|
2018-08-26 14:52:57 -05:00
|
|
|
const scope = this.$rootScope.$new();
|
2018-02-16 02:14:32 -06:00
|
|
|
|
2018-09-05 00:47:30 -05:00
|
|
|
scope.onConfirm = () => {
|
2018-02-16 02:14:32 -06:00
|
|
|
payload.onConfirm();
|
|
|
|
scope.dismiss();
|
|
|
|
};
|
|
|
|
|
2018-09-05 00:47:30 -05:00
|
|
|
scope.updateConfirmText = value => {
|
2018-02-16 02:14:32 -06:00
|
|
|
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',
|
|
|
|
});
|
|
|
|
}
|
2016-03-25 16:14:29 -05:00
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.service('utilSrv', UtilSrv);
|