directives.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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(timer){
  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. timer.cancel_all();
  60. scope.$apply();
  61. };
  62. })(f);
  63. reader.readAsText(f);
  64. }
  65. }
  66. // Check for the various File API support.
  67. if (window.File && window.FileReader && window.FileList && window.Blob) {
  68. // Something
  69. document.getElementById('upload').addEventListener('change', file_selected, false);
  70. } else {
  71. alert('Sorry, the HTML5 File APIs are not fully supported in this browser.');
  72. }
  73. }
  74. }
  75. });