util_srv.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. appEvents.on('hide-modal', this.hideModal.bind(this), this.$rootScope);
  15. }
  16. hideModal() {
  17. if (this.modalScope && this.modalScope.dismiss) {
  18. this.modalScope.dismiss();
  19. }
  20. }
  21. showModal(options) {
  22. if (this.modalScope && this.modalScope.dismiss) {
  23. this.modalScope.dismiss();
  24. }
  25. this.modalScope = options.scope;
  26. if (options.model) {
  27. this.modalScope = this.$rootScope.$new();
  28. this.modalScope.model = options.model;
  29. } else if (!this.modalScope) {
  30. this.modalScope = this.$rootScope.$new();
  31. }
  32. var modal = this.$modal({
  33. modalClass: options.modalClass,
  34. template: options.src,
  35. templateHtml: options.templateHtml,
  36. persist: false,
  37. show: false,
  38. scope: this.modalScope,
  39. keyboard: false,
  40. backdrop: options.backdrop
  41. });
  42. Promise.resolve(modal).then(function(modalEl) {
  43. modalEl.modal('show');
  44. });
  45. }
  46. }
  47. coreModule.service('utilSrv', UtilSrv);