LP#1785061: Split filter value on comma for "in list" and the like
authorRemington Steed <rjs7@calvin.edu>
Thu, 2 May 2019 13:15:30 +0000 (09:15 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Mon, 16 Dec 2019 17:02:39 +0000 (12:02 -0500)
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 <rjs7@calvin.edu>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Conflicts:
Open-ILS/web/js/ui/default/staff/reporter/template/app.js

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/web/js/ui/default/staff/reporter/template/app.js

index c79a54b..6e3f950 100644 (file)
@@ -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);
                     }
                 }}
             );