From 758cdcf4e5463649a1a54bec69971cc548499bda Mon Sep 17 00:00:00 2001 From: Remington Steed Date: Thu, 2 May 2019 09:15:30 -0400 Subject: [PATCH] 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 Signed-off-by: Galen Charlton Conflicts: Open-ILS/web/js/ui/default/staff/reporter/template/app.js Signed-off-by: Dan Wells --- .../ui/default/staff/reporter/template/app.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 0fa3d29a99..6e3f9501d4 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 @@ -513,7 +513,7 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , } else { 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); }} ); } @@ -521,6 +521,30 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , 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]; @@ -572,6 +596,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); } }} ); -- 2.43.2