grafana/public/app/directives/arrayJoin.js

36 lines
713 B
JavaScript
Raw Normal View History

2013-09-14 04:52:13 +08:00
define([
'angular',
'app',
2014-08-07 20:35:19 +08:00
'lodash'
2013-09-14 04:52:13 +08:00
],
function (angular, app, _) {
'use strict';
angular
2014-07-29 00:11:52 +08:00
.module('grafana.directives')
2013-09-14 04:52:13 +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);
}
};
});
2015-01-12 21:31:15 +08:00
});