From 0f238cd7ba0f8d0c229b7148024648978c221068 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 --- .../js/ui/default/staff/reporter/template/app.js | 53 ++++++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) 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..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 @@ -497,15 +497,54 @@ function($scope , $q , $routeParams , $location , $timeout , $window, egCore , $scope.changeFilterValue = function (items) { items.forEach(function(item) { 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 (item.datatype == "bool") { + var displayVal = typeof item.value === "undefined" ? egCore.strings.TEMPLATE_CONF_UNSET : + item.value === 't' ? egCore.strings.TEMPLATE_CONF_TRUE : + item.value === 'f' ? egCore.strings.TEMPLATE_CONF_FALSE : + item.value.toString(); + egConfirmDialog.open(egCore.strings.TEMPLATE_CONF_DEFAULT, displayVal, + {ok : function() { + egReportTemplateSvc.filter_fields[item.index].value = 't'; + }, + cancel : function() { + egReportTemplateSvc.filter_fields[item.index].value = 'f'; + }}, egCore.strings.TEMPLATE_CONF_TRUE, egCore.strings.TEMPLATE_CONF_FALSE + ); + } else { + egPromptDialog.open(egCore.strings.TEMPLATE_CONF_DEFAULT, item.value || '', + {ok : function(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 +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.11.0