util_srv.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ///<reference path="../../headers/common.d.ts" />
  2. import config from 'app/core/config';
  3. import _ from 'lodash';
  4. import $ from 'jquery';
  5. import coreModule from 'app/core/core_module';
  6. import appEvents from 'app/core/app_events';
  7. export class UtilSrv {
  8. modalScope: any;
  9. /** @ngInject */
  10. constructor(private $rootScope, private $modal) {
  11. }
  12. init() {
  13. appEvents.on('show-modal', this.showModal.bind(this), this.$rootScope);
  14. }
  15. showModal(options) {
  16. if (this.modalScope && this.modalScope.dismiss) {
  17. this.modalScope.dismiss();
  18. }
  19. this.modalScope = options.scope;
  20. if (options.model) {
  21. this.modalScope = this.$rootScope.$new();
  22. this.modalScope.model = options.model;
  23. } else if (!this.modalScope) {
  24. this.modalScope = this.$rootScope.$new();
  25. }
  26. var modal = this.$modal({
  27. modalClass: options.modalClass,
  28. template: options.src,
  29. templateHtml: options.templateHtml,
  30. persist: false,
  31. show: false,
  32. scope: this.modalScope,
  33. keyboard: false,
  34. backdrop: options.backdrop
  35. });
  36. Promise.resolve(modal).then(function(modalEl) {
  37. modalEl.modal('show');
  38. });
  39. }
  40. }
  41. coreModule.service('utilSrv', UtilSrv);