Bug 30055: (QA follow-up) Minor QA fixes
[srvgit] / koha-tmpl / intranet-tmpl / prog / en / modules / members / search.tt
index c1b16a8..7422381 100644 (file)
@@ -76,7 +76,7 @@
         </div>
 
         <div id="info" class="dialog message" style="display: none;"></div>
-        <div id="error" class="dialog alert" style="dispay: none;"></div>
+        <div id="error" class="dialog alert" style="display: none;"></div>
 
         <input type="hidden" id="firstletter_filter" value="" />
         <div id="searchresults" style="display:none;">
                     if (!start_with) return "";
                     return { "like": start_with + "%" }
                 },
-                [% IF Koha.Preference('ExtendedPatronAttributes') %]
-                "-or": function(){
+                "-and": function(){
                     let filter = $("#searchmember_filter").val();
                     if (!filter) return "";
+                    [% SET search_fields = Koha.Preference('DefaultPatronSearchFields') || 'surname,firstname,othernames,cardnumber,userid' %]
                     return [
+                        [% FOR search_field IN search_fields.split(',') %]
+                        {"me.[% search_field | html %]":{"like":"%"+filter+"%"}},
+                        [% END %]
+                        [% IF Koha.Preference('ExtendedPatronAttributes') %]
                         {
-                            "extended_attributes.value": { "like": "%" + filter + "%" }
-                        },
-                        {
+                            "extended_attributes.value": { "like": "%" + filter + "%" },
                             "extended_attributes.code": extended_attribute_types
                         }
+                        [% END %]
                     ];
                 },
-                [% END %]
             };
+            [% SET default_sort_column = "name" %]
+            [% SET order_column_index = 0 %]
             patrons_table = $("#memberresultst").kohaTable({
                 "ajax": {
                     [% SWITCH filter %]
                     [% END %]
                 },
                 embed: ['extended_attributes'],
-                "order": [[ 1, "asc" ]],
                 "iDeferLoading": 0,
                 "columns": [
                     [% FOR column IN columns %]
+                        [% IF default_sort_column == column %]
+                            [% order_column_index = loop.count - 1%]
+                        [% END %]
                         [% SWITCH column %]
                             [% CASE 'cardnumber' %]
                             {
                             }
                             [% CASE 'name' %]
                             {
-                                "data": "me.firstname:me.surname",
+                                "data": "me.firstname:me.surname:me.othernames",
                                 "searchable": true,
                                 "orderable": true,
                                 "render": function( data, type, row, meta ) {
                         [% UNLESS loop.last %],[% END %]
                     [% END %]
                 ],
+                "order": [[ [% order_column_index | html %], "asc" ]],
                 'bAutoWidth': false,
                 'sPaginationType': 'full_numbers',
                 "iDisplayLength": [% Koha.Preference('PatronsPerPage') | html %],
                 [% CASE 'branch' %]
                     let library_id = $("#branchcode_filter").val();
                     patrons_table.find('thead tr:eq(1) th[data-filter="libraries"] select').val(library_id);
-                    table_dt.column([% loop.count - 1 %]).search(library_id);
+                    table_dt.column([% loop.count - 1 %]).search(library_id ? '^'+library_id+'$' : '');
                 [% CASE 'category' %]
                     let category_id = $("#categorycode_filter").val();
                     patrons_table.find('thead tr:eq(1) th[data-filter="categories"] select').val(category_id);
-                    table_dt.column([% loop.count - 1 %]).search(category_id);
+                    table_dt.column([% loop.count - 1 %]).search(category_id ? '^'+category_id+'$' : '');
                 [% END %]
             [% END %]
-            table_dt.search($("#searchmember_filter").val());
+            table_dt.search("");
             table_dt.draw();
             return false;
         }