directives.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = '<span class="pointer editlink" bs-modal="\'partials/paneleditor.html\'" ng-show="panel.editable != false">'+
  10. '<i class="icon-edit"></i></span><h4>{{panel.title}}</h4>';
  11. elem.prepend($compile(angular.element(template))(scope));
  12. }
  13. };
  14. })
  15. .directive('panelEdit', function(){
  16. return {
  17. restrict: 'E',
  18. replace: true,
  19. scope: {
  20. 'panel': '=panel'
  21. },
  22. templateUrl: 'panels/table/editor.html',
  23. //controller: 'ChildElement'
  24. }
  25. })
  26. .directive('arrayJoin', function() {
  27. return {
  28. restrict: 'A',
  29. require: 'ngModel',
  30. link: function(scope, element, attr, ngModel) {
  31. function split_array(text) {
  32. return (text || '').split(',');
  33. }
  34. function join_array(text) {
  35. if(_.isArray(text))
  36. return (text || '').join(',');
  37. else
  38. return text
  39. }
  40. ngModel.$parsers.push(split_array);
  41. ngModel.$formatters.push(join_array);
  42. }
  43. };
  44. })
  45. .directive('upload', function(){
  46. return {
  47. restrict: 'A',
  48. link: function(scope, elem, attrs) {
  49. function file_selected(evt) {
  50. var files = evt.target.files; // FileList object
  51. // files is a FileList of File objects. List some properties.
  52. var output = [];
  53. for (var i = 0, f; f = files[i]; i++) {
  54. var reader = new FileReader();
  55. reader.onload = (function(theFile) {
  56. return function(e) {
  57. // Render thumbnail.
  58. scope.dashboards = JSON.parse(e.target.result)
  59. scope.$apply();
  60. };
  61. })(f);
  62. reader.readAsText(f);
  63. }
  64. }
  65. // Check for the various File API support.
  66. if (window.File && window.FileReader && window.FileList && window.Blob) {
  67. // Something
  68. document.getElementById('upload').addEventListener('change', file_selected, false);
  69. } else {
  70. alert('Sorry, the HTML5 File APIs are not fully supported in this browser.');
  71. }
  72. }
  73. }
  74. });