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)
committerDan Wells <dbw2@calvin.edu>
Wed, 14 Aug 2019 13:04:47 +0000 (09:04 -0400)
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 0fa3d29..6e3f950 100644 (file)
@@ -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);
                     }
                 }}
             );