config_modal.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. define([
  2. 'lodash',
  3. 'jquery',
  4. '../core_module',
  5. ],
  6. function (_, $, coreModule) {
  7. 'use strict';
  8. coreModule.default.directive('configModal', function($modal, $q, $timeout) {
  9. return {
  10. restrict: 'A',
  11. link: function(scope, elem, attrs) {
  12. var partial = attrs.configModal;
  13. var id = '#' + partial.replace('.html', '').replace(/[\/|\.|:]/g, '-') + '-' + scope.$id;
  14. elem.bind('click',function() {
  15. if ($(id).length) {
  16. elem.attr('data-target', id).attr('data-toggle', 'modal');
  17. scope.$apply(function() { scope.$broadcast('modal-opened'); });
  18. return;
  19. }
  20. var panelModal = $modal({
  21. template: partial,
  22. persist: false,
  23. show: false,
  24. scope: scope.$new(),
  25. keyboard: false
  26. });
  27. $q.when(panelModal).then(function(modalEl) {
  28. elem.attr('data-target', id).attr('data-toggle', 'modal');
  29. $timeout(function () {
  30. if (!modalEl.data('modal').isShown) {
  31. modalEl.modal('show');
  32. }
  33. }, 50);
  34. });
  35. scope.$apply();
  36. });
  37. }
  38. };
  39. });
  40. });