popover_srv.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. /** @ngInject **/
  7. function popoverSrv($templateCache, $timeout, $q, $http, $compile) {
  8. this.getTemplate = function(url) {
  9. return $q.when($templateCache.get(url) || $http.get(url, {cache: true}));
  10. };
  11. this.show = function(options) {
  12. options.scope.dismiss = function() {
  13. var popover = options.element.data('popover');
  14. if (popover) {
  15. popover.destroy();
  16. }
  17. options.scope.$destroy();
  18. };
  19. this.getTemplate(options.templateUrl).then(function(result) {
  20. $timeout(function() {
  21. var template = _.isString(result) ? result : result.data;
  22. options.element.popover({
  23. content: template,
  24. placement: options.placement || 'bottom',
  25. html: true
  26. });
  27. var popover = options.element.data('popover');
  28. popover.hasContent = function () {
  29. return template;
  30. };
  31. popover.toggle();
  32. popover.scope = options.scope;
  33. $compile(popover.$tip)(popover.scope);
  34. }, 1);
  35. });
  36. };
  37. }
  38. coreModule.service('popoverSrv', popoverSrv);