(function () { "use strict"; angular.module('app.service') .factory('attribute', ['$filter', function ($filter) { var helpers = { 'numeric': { toNative: function (data, value) { if (null == data || null == data.numericValue && null == value) return null; value = null == value ? data.numericValue : value; return parseFloat(value); }, toText: function (data, value) { if (null == data || null == data.numericValue && null == value) return null; value = null == value ? data.numericValue : value; return parseFloat(value).toFixed(data.decimalRound || 0); }, toAPI: function (data, value) { var result = helpers.numeric.toNative(data, value); return result; } }, 'text': { toNative: function (data, value) { if (null == data || null == data.textValue && null == value) return null; value = null == value ? data.textValue : value; return '' + value; }, toText: function (data, value) { if (null == data || null == data.textValue && null == value) return null; value = null == value ? data.textValue : value; return '' + value; }, toAPI: function (data, value) { var result = helpers.text.toNative(data, value); return result; } }, 'datetime': { toNative: function (data, value) { if (null == data || null == data.datetimeValue && null == value) return null; value = null == value ? data.datetimeValue : value; return value instanceof Date ? value : new Date(value); }, toText: function (data, value) { if (null == data || null == data.datetimeValue && null == value) return null; value = null == value ? data.datetimeValue : value; value = value instanceof Date ? value : new Date(value); return $filter('date')(value, data.datetimeOutputFormatJs || 'yyyy-MM-dd'); }, toAPI: function (data, value) { var result = helpers.datetime.toNative(data, value); return null == result ? result : $filter('date')(result, 'yyyy-MM-dd'); } } }; return { toNative: function (data, value) { return data.dataType in helpers ? helpers[data.dataType].toNative(data, value) : undefined; }, toText: function (data, value) { return data.dataType in helpers ? helpers[data.dataType].toText(data, value) : undefined; }, toAPI: function (data, value) { return data.dataType in helpers ? helpers[data.dataType].toAPI(data, value) : undefined; } }; }]); })();