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);
|
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();
|
|
|
|
}
|
|
|
|
|
2016-03-25 16:14:29 -05:00
|
|
|
var modal = this.$modal({
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
Promise.resolve(modal).then(function(modalEl) {
|
2017-12-20 05:33:33 -06:00
|
|
|
modalEl.modal('show');
|
2016-03-25 16:14:29 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.service('utilSrv', UtilSrv);
|