directives.js 2.0 KB

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