grafana/public/app/core/services/util_srv.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import coreModule from 'app/core/core_module';
import appEvents from 'app/core/app_events';
export class UtilSrv {
modalScope: any;
/** @ngInject */
constructor(private $rootScope, private $modal) {}
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);
}
hideModal() {
if (this.modalScope && this.modalScope.dismiss) {
this.modalScope.dismiss();
}
}
showModal(options) {
if (this.modalScope && this.modalScope.dismiss) {
this.modalScope.dismiss();
}
2016-11-03 14:32:36 -05:00
this.modalScope = options.scope;
if (options.model) {
this.modalScope = this.$rootScope.$new();
this.modalScope.model = options.model;
} else if (!this.modalScope) {
this.modalScope = this.$rootScope.$new();
}
var modal = this.$modal({
modalClass: options.modalClass,
template: options.src,
templateHtml: options.templateHtml,
persist: false,
show: false,
scope: this.modalScope,
2016-05-14 03:00:43 -05:00
keyboard: false,
2017-12-20 05:33:33 -06:00
backdrop: options.backdrop,
});
Promise.resolve(modal).then(function(modalEl) {
2017-12-20 05:33:33 -06:00
modalEl.modal('show');
});
}
}
2017-12-20 05:33:33 -06:00
coreModule.service('utilSrv', UtilSrv);