2013-01-26 12:10:28 +08:00
|
|
|
/*jshint globalstrict:true */
|
|
|
|
|
/*global angular:true */
|
|
|
|
|
'use strict';
|
|
|
|
|
|
2013-01-29 03:28:12 +08:00
|
|
|
angular.module('kibana.directives', [])
|
2013-02-08 23:42:37 +08:00
|
|
|
.directive('kibanaPanel', function($compile) {
|
2013-01-26 12:10:28 +08:00
|
|
|
return {
|
2013-02-08 23:42:37 +08:00
|
|
|
restrict: 'E',
|
|
|
|
|
link: function(scope, elem, attrs) {
|
2013-03-12 08:13:47 +08:00
|
|
|
var template = '<img src="common/img/load.gif" class="panel-loading" ng-show="panel.loading == true">'+
|
|
|
|
|
'<span class="editlink panelextra pointer" style="right:15px;top:0px" bs-modal="\'partials/paneleditor.html\'" ng-show="panel.editable != false">'+
|
|
|
|
|
'<span class="small">{{panel.type}}</span> <i class="icon-edit pointer"></i>'+
|
|
|
|
|
'</span><h4>{{panel.title}}</h4>';
|
2013-02-08 23:42:37 +08:00
|
|
|
elem.prepend($compile(angular.element(template))(scope));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
})
|
2013-02-08 06:05:55 +08:00
|
|
|
.directive('arrayJoin', function() {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
require: 'ngModel',
|
|
|
|
|
link: function(scope, element, attr, ngModel) {
|
|
|
|
|
|
|
|
|
|
function split_array(text) {
|
|
|
|
|
return (text || '').split(',');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function join_array(text) {
|
|
|
|
|
if(_.isArray(text))
|
|
|
|
|
return (text || '').join(',');
|
|
|
|
|
else
|
|
|
|
|
return text
|
|
|
|
|
}
|
|
|
|
|
ngModel.$parsers.push(split_array);
|
|
|
|
|
ngModel.$formatters.push(join_array);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
})
|
2013-02-12 23:42:31 +08:00
|
|
|
.directive('upload', function(timer){
|
2013-01-26 12:10:28 +08:00
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
link: function(scope, elem, attrs) {
|
|
|
|
|
function file_selected(evt) {
|
|
|
|
|
var files = evt.target.files; // FileList object
|
|
|
|
|
|
|
|
|
|
// files is a FileList of File objects. List some properties.
|
|
|
|
|
var output = [];
|
|
|
|
|
for (var i = 0, f; f = files[i]; i++) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.onload = (function(theFile) {
|
|
|
|
|
return function(e) {
|
|
|
|
|
// Render thumbnail.
|
|
|
|
|
scope.dashboards = JSON.parse(e.target.result)
|
2013-02-12 23:42:31 +08:00
|
|
|
timer.cancel_all();
|
2013-01-26 12:10:28 +08:00
|
|
|
scope.$apply();
|
|
|
|
|
};
|
|
|
|
|
})(f);
|
|
|
|
|
reader.readAsText(f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check for the various File API support.
|
|
|
|
|
if (window.File && window.FileReader && window.FileList && window.Blob) {
|
|
|
|
|
// Something
|
|
|
|
|
document.getElementById('upload').addEventListener('change', file_selected, false);
|
|
|
|
|
} else {
|
|
|
|
|
alert('Sorry, the HTML5 File APIs are not fully supported in this browser.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-22 06:26:48 +08:00
|
|
|
}).directive('ngModelOnblur', function() {
|
|
|
|
|
return {
|
|
|
|
|
restrict: 'A',
|
|
|
|
|
require: 'ngModel',
|
|
|
|
|
link: function(scope, elm, attr, ngModelCtrl) {
|
|
|
|
|
if (attr.type === 'radio' || attr.type === 'checkbox') return;
|
|
|
|
|
|
|
|
|
|
elm.unbind('input').unbind('keydown').unbind('change');
|
|
|
|
|
elm.bind('blur', function() {
|
|
|
|
|
scope.$apply(function() {
|
|
|
|
|
ngModelCtrl.$setViewValue(elm.val());
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-01-26 12:10:28 +08:00
|
|
|
});
|
2013-02-22 06:26:48 +08:00
|
|
|
;
|
2013-01-26 12:10:28 +08:00
|
|
|
|