configModal.js 1.3 KB

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