Bug 31028: (follow-up) Remove special:undefined
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 7 Mar 2023 14:36:18 +0000 (14:36 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 7 Mar 2023 17:54:38 +0000 (14:54 -0300)
There's a cleaner way to achieve this now using `additional_filters` and
passing a function.

This patch removes the `special:undefined` handling, replacing it with a
single field filter passed as a function via additional_filters.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt
koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt
koha-tmpl/intranet-tmpl/prog/js/datatables.js

index 6aa948a..707a5d7 100644 (file)
@@ -1353,6 +1353,18 @@ Note that permanent location is a code, and location may be an authval.
             $(document).ready(function() {
                 var table_settings = [% TablesSettings.GetTableSettings( 'cataloguing', 'concerns', 'table_concerns', 'json' ) | $raw %];
 
+                var filtered = false;
+                let additional_filters = {
+                    resolved_date: function(){
+                        if ( filtered ) {
+                            return { "=": null };
+                        } else {
+                            return;
+                        }
+                    },
+                    biblio_id: [% biblionumber | uri %]
+                };
+
                 var tickets_url = '/api/v1/tickets';
                 var tickets = $("#table_concerns").kohaTable({
                     "ajax": {
@@ -1434,15 +1446,16 @@ Note that permanent location is a code, and location may be an authval.
                             "orderable": false
                         },
                     ]
-                }, table_settings, 0, { biblio_id: [% biblionumber | uri %]});
+                }, table_settings, 0, additional_filters);
 
-                $('#hideResolved').on( "click", function() {
-                    // It would be great if we could pass null here but it gets stringified
-                    concerns.DataTable().columns('3').search('special:undefined').draw();
+                $('#hideResolved').on("click", function() {
+                    filtered = true;
+                    tickets.DataTable().draw();
                 });
 
-                $('#showAll').on( "click", function() {
-                    concerns.DataTable().columns('3').search('').draw();
+                $('#showAll').on("click", function() {
+                    filtered = false;
+                    tickets.DataTable().draw();
                 });
             });
         </script>
index 0da6646..21231d6 100644 (file)
 
             var table_settings = [% TablesSettings.GetTableSettings('cataloguing', 'concerns', 'table_concerns', 'json') | $raw %];
 
+            var filtered = false;
+            let additional_filters = {
+                resolved_date: function(){
+                    if ( filtered ) {
+                        return { "=": null };
+                    } else {
+                        return;
+                    }
+                }
+            };
+
             var tickets_url = '/api/v1/tickets';
             var tickets = $("#table_concerns").kohaTable({
                 "ajax": {
                         "orderable": false
                     },
                 ]
-            }, table_settings, 1);
+            }, table_settings, 1, additional_filters);
 
             $('#hideResolved').on("click", function() {
-                // It would be great if we could pass null here but it gets stringified
-                tickets.DataTable().columns('3').search('special:undefined').draw();
+                filtered = true;
+                tickets.DataTable().draw();
             });
 
             $('#showAll').on("click", function() {
-                tickets.DataTable().columns('3').search('').draw();
+                filtered = false;
+                tickets.DataTable().draw();
             });
         });
     </script>
index d2fa6c9..9b32ab2 100644 (file)
@@ -586,18 +586,12 @@ jQuery.fn.dataTable.ext.errMode = function(settings, note, message) {
                                         var part = {};
                                         var attr = attributes[i];
                                         let criteria = options.criteria;
-                                        if ( value === 'special:undefined' ) {
-                                            value = null;
+                                        if ( value.match(/^\^(.*)\$$/) ) {
+                                            value = value.replace(/^\^/, '').replace(/\$$/, '');
                                             criteria = "exact";
-                                        }
-                                        if ( value !== null ) {
-                                            if ( value.match(/^\^(.*)\$$/) ) {
-                                                value = value.replace(/^\^/, '').replace(/\$$/, '');
-                                                criteria = "exact";
-                                            } else {
-                                                // escape SQL LIKE special characters %
-                                                value = value.replace(/(\%|\\)/g, "\\$1");
-                                            }
+                                        } else {
+                                            // escape SQL LIKE special characters %
+                                            value = value.replace(/(\%|\\)/g, "\\$1");
                                         }
                                         part[!attr.includes('.')?'me.'+attr:attr] = criteria === 'exact'
                                             ? value