util_srv.ts 1.3 KB

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