2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from '../core_module';
|
2015-09-11 03:54:56 -05:00
|
|
|
|
2015-09-12 04:49:14 -05:00
|
|
|
export function arrayJoin() {
|
2017-12-20 05:33:33 -06:00
|
|
|
'use strict';
|
2015-09-11 14:04:02 -05:00
|
|
|
|
2015-09-11 03:54:56 -05:00
|
|
|
return {
|
2017-12-20 05:33:33 -06:00
|
|
|
restrict: 'A',
|
|
|
|
require: 'ngModel',
|
2015-09-11 03:54:56 -05:00
|
|
|
link: function(scope, element, attr, ngModel) {
|
|
|
|
function split_array(text) {
|
2017-12-20 05:33:33 -06:00
|
|
|
return (text || '').split(',');
|
2015-09-11 03:54:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function join_array(text) {
|
2015-09-11 14:04:02 -05:00
|
|
|
if (_.isArray(text)) {
|
2017-12-20 05:33:33 -06:00
|
|
|
return (text || '').join(',');
|
2015-09-11 03:54:56 -05:00
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngModel.$parsers.push(split_array);
|
|
|
|
ngModel.$formatters.push(join_array);
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2015-09-11 03:54:56 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
coreModule.directive('arrayJoin', arrayJoin);
|