From: Remington Steed Date: Thu, 2 May 2019 13:15:30 +0000 (-0400) Subject: LP#1785061: Split filter value on comma for "in list" and the like X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=refs%2Fheads%2Fuser%2Frsteed%2Flp1785061_reporter_inlist_value_splitting;p=working%2FEvergreen.git LP#1785061: Split filter value on comma for "in list" and the like This commit borrows directly from the XUL reporter code (see function __default_value_event_handler () in Open-ILS/web/reports/xul/template-config.js). Basically, when the filter value is saved, certain cases need special treatment, such as splitting an "in list" value on commas. This commit includes a helper function which does the special treatment and saves the filter value. This helper is called both when the value itself is changed, and when the operator is changed. Signed-off-by: Remington Steed --- diff --git a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js index c79a54bf37..974b5f9e72 100644 --- a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js +++ b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js @@ -499,13 +499,37 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , var l = null; egPromptDialog.open(egCore.strings.TEMPLATE_CONF_DEFAULT, item.value || '', {ok : function(value) { - if (value) egReportTemplateSvc.filter_fields[item.index].value = value; + if (value) _update_filter_value(item, value); }} ); }); fgrid.refresh(); } + _update_filter_value = function(item, value) { + switch (item.operator.op) { + case 'between': + case 'not between': + case 'not in': + case 'in': + //if value isn't an array yet, split into an array for + // operators that need it + if (typeof value === 'string') { + value = value.split(/\s*,\s*/); + } + break; + + default: + //if value was split but shouldn't be, then convert back to + // comma-separated string + if (Array.isArray(value)) { + value = value.toString(); + } + } + + egReportTemplateSvc.filter_fields[item.index].value = value; + } + $scope.changeTransform = function (items) { var f = items[0]; @@ -557,6 +581,10 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , if (value) { var t = egReportTemplateSvc.getFilterByLabel(value); item.operator = { label: value, op : t }; + + //Update the filter value based on the new operator, because + // different operators treat the value differently + _update_filter_value(item, egReportTemplateSvc.filter_fields[item.index].value); } }} );