tip.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. define([
  2. 'angular',
  3. 'kbn'
  4. ],
  5. function (angular, kbn) {
  6. 'use strict';
  7. angular
  8. .module('grafana.directives')
  9. .directive('tip', function($compile) {
  10. return {
  11. restrict: 'E',
  12. link: function(scope, elem, attrs) {
  13. var _t = '<i class="grafana-tip fa fa-'+(attrs.icon||'question-circle')+'" bs-tooltip="\''+
  14. kbn.addslashes(elem.text())+'\'"></i>';
  15. elem.replaceWith($compile(angular.element(_t))(scope));
  16. }
  17. };
  18. });
  19. angular
  20. .module('grafana.directives')
  21. .directive('watchChange', function() {
  22. return {
  23. scope: { onchange: '&watchChange' },
  24. link: function(scope, element) {
  25. element.on('input', function() {
  26. scope.$apply(function () {
  27. scope.onchange({ inputValue: element.val() });
  28. });
  29. });
  30. }
  31. };
  32. });
  33. angular
  34. .module('grafana.directives')
  35. .directive('editorOptBool', function($compile) {
  36. return {
  37. restrict: 'E',
  38. link: function(scope, elem, attrs) {
  39. var ngchange = attrs.change ? (' ng-change="' + attrs.change + '"') : '';
  40. var tip = attrs.tip ? (' <tip>' + attrs.tip + '</tip>') : '';
  41. var showIf = attrs.showIf ? (' ng-show="' + attrs.showIf + '" ') : '';
  42. var template = '<div class="editor-option text-center"' + showIf + '>' +
  43. ' <label for="' + attrs.model + '" class="small">' +
  44. attrs.text + tip + '</label>' +
  45. '<input class="cr1" id="' + attrs.model + '" type="checkbox" ' +
  46. ' ng-model="' + attrs.model + '"' + ngchange +
  47. ' ng-checked="' + attrs.model + '"></input>' +
  48. ' <label for="' + attrs.model + '" class="cr1"></label>';
  49. elem.replaceWith($compile(angular.element(template))(scope));
  50. }
  51. };
  52. });
  53. angular
  54. .module('grafana.directives')
  55. .directive('editorCheckbox', function($compile, $interpolate) {
  56. return {
  57. restrict: 'E',
  58. link: function(scope, elem, attrs) {
  59. var text = $interpolate(attrs.text)(scope);
  60. var ngchange = attrs.change ? (' ng-change="' + attrs.change + '"') : '';
  61. var tip = attrs.tip ? (' <tip>' + attrs.tip + '</tip>') : '';
  62. var label = '<label for="' + scope.$id + attrs.model + '" class="checkbox-label">' +
  63. text + tip + '</label>';
  64. var template = '<input class="cr1" id="' + scope.$id + attrs.model + '" type="checkbox" ' +
  65. ' ng-model="' + attrs.model + '"' + ngchange +
  66. ' ng-checked="' + attrs.model + '"></input>' +
  67. ' <label for="' + scope.$id + attrs.model + '" class="cr1"></label>';
  68. if (attrs.position === "front") {
  69. template = label + template;
  70. } else {
  71. template = template + label;
  72. }
  73. elem.replaceWith($compile(angular.element(template))(scope));
  74. }
  75. };
  76. });
  77. });