directives.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*jshint globalstrict:true */
  2. /*global angular:true */
  3. 'use strict';
  4. angular.module('kibana.directives', [])
  5. .directive('kibanaPanel', function($compile) {
  6. return {
  7. restrict: 'E',
  8. link: function(scope, elem, attrs) {
  9. var template = '<img src="common/img/load.gif" class="panel-loading" ng-show="panel.loading == true">'+
  10. ' <span class="editlink panelextra pointer" style="right:15px;top:0px" bs-modal="\'partials/paneleditor.html\'" ng-show="panel.editable != false">'+
  11. '<span class="small">{{panel.type}}</span> <i class="icon-cog pointer"></i> '+
  12. '</span><h4>{{panel.title}}</h4>';
  13. elem.prepend($compile(angular.element(template))(scope));
  14. }
  15. };
  16. })
  17. .directive('addPanel', function($compile) {
  18. return {
  19. restrict: 'A',
  20. link: function(scope, elem, attrs) {
  21. scope.$watch('panel.type', function(n,o) {
  22. if(!_.isUndefined(scope.panel.type)) {
  23. var template = '<div ng-controller="'+scope.panel.type+'" ng-include src="\''+scope.edit_path(scope.panel.type)+'\'"></div>';
  24. elem.html($compile(angular.element(template))(scope));
  25. }
  26. })
  27. }
  28. };
  29. })
  30. .directive('arrayJoin', function() {
  31. return {
  32. restrict: 'A',
  33. require: 'ngModel',
  34. link: function(scope, element, attr, ngModel) {
  35. function split_array(text) {
  36. return (text || '').split(',');
  37. }
  38. function join_array(text) {
  39. if(_.isArray(text))
  40. return (text || '').join(',');
  41. else
  42. return text
  43. }
  44. ngModel.$parsers.push(split_array);
  45. ngModel.$formatters.push(join_array);
  46. }
  47. };
  48. })
  49. .directive('ngModelOnblur', function() {
  50. return {
  51. restrict: 'A',
  52. require: 'ngModel',
  53. link: function(scope, elm, attr, ngModelCtrl) {
  54. if (attr.type === 'radio' || attr.type === 'checkbox') return;
  55. elm.unbind('input').unbind('keydown').unbind('change');
  56. elm.bind('blur', function() {
  57. scope.$apply(function() {
  58. ngModelCtrl.$setViewValue(elm.val());
  59. });
  60. });
  61. }
  62. };
  63. });
  64. ;