util_srv.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. if (options.model) {
  20. options.scope = this.modalScope = this.$rootScope.$new();
  21. options.scope.model = options.model;
  22. } else {
  23. this.modalScope = options.scope;
  24. }
  25. var modal = this.$modal({
  26. modalClass: options.modalClass,
  27. template: options.src,
  28. templateHtml: options.templateHtml,
  29. persist: false,
  30. show: false,
  31. scope: options.scope,
  32. keyboard: false,
  33. backdrop: options.backdrop
  34. });
  35. Promise.resolve(modal).then(function(modalEl) {
  36. modalEl.modal('show');
  37. });
  38. }
  39. }
  40. coreModule.service('utilSrv', UtilSrv);