Bug 13891: DataTables server-side processing - patron cards
[srvgit] / koha-tmpl / intranet-tmpl / prog / en / modules / common / patron_search.tt
index 2a7233f..e182688 100644 (file)
@@ -32,10 +32,21 @@ $(document).ready(function(){
             aoData.push({
                 'name': 'searchmember',
                 'value': $("#searchmember_filter").val()
-            },
-            {
+            },{
+                'name': 'name_sorton',
+                'value': 'borrowers.surname borrowers.firstname'
+            },{
+                'name': 'category_sorton',
+                'value': 'categories.description',
+            },{
+                'name': 'branch_sorton',
+                'value': 'branches.branchname'
+            },{
                 'name': 'template_path',
-                'value': 'acqui/tables/members_results.tt',
+                'value': '[% json_template %]',
+            },{
+                'name': 'selection_type',
+                'value': '[% selection_type %]',
             }
             [% IF patrons_with_acq_perm_only %]
             ,{
@@ -55,11 +66,16 @@ $(document).ready(function(){
             });
         },
         'aoColumns':[
-            { 'mDataProp': 'dt_cardnumber' },
-            { 'mDataProp': 'dt_name' },
-            { 'mDataProp': 'dt_branch' },
-            { 'mDataProp': 'dt_category' },
-            { 'mDataProp': 'dt_action', 'bSortable': false }
+            [% FOR column IN columns %]
+                [% IF column == 'action' %]
+                    { 'mDataProp': 'dt_action', 'bSortable': false }
+                [% ELSIF column == 'address' %]
+                    { 'mDataProp': 'dt_address', 'bSortable': false }
+                [% ELSE %]
+                    { 'mDataProp': 'dt_[% column %]' }
+                [% END %]
+                [% UNLESS loop.last %],[% END %]
+            [% END %]
         ],
         'bAutoWidth': false,
         [% IF patrons_with_acq_perm_only %]
@@ -97,19 +113,36 @@ function filter() {
 }
 
     // modify parent window owner element
-    function add_user(borrowernumber, borrowername) {
-        var p = window.opener;
-        $("#info").hide();
-        $("#error").hide();
-        if ( p.add_user(borrowernumber, borrowername) < 0 ) {
-            $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
-            $("#error").show();
-        } else {
-            $("#info").html(_("Borrower '%s' added.").format(borrowername));
-            $("#info").show();
-
+    [% IF selection_type == 'add' %]
+        function add_user(borrowernumber, borrowername) {
+            var p = window.opener;
+            // In one place (serials/routing.tt), the page is reload on every add
+            // We have to wait for the page to be there
+            function wait_for_opener () {
+                if ( ! $(opener.document).find('body').size() ) {
+                    setTimeout(wait_for_opener, 500);
+                } else {
+                    [%# Note that add_user could sent data instead of borrowername too %]
+                    $("#info").hide();
+                    $("#error").hide();
+                    if ( p.add_user(borrowernumber, borrowername) < 0 ) {
+                        $("#error").html(_("Borrower '%s' is already in the list.").format(borrowername));
+                        $("#error").show();
+                    } else {
+                        $("#info").html(_("Borrower '%s' added.").format(borrowername));
+                        $("#info").show();
+                    }
+                }
+            }
+            wait_for_opener();
         }
-    }
+    [% ELSIF selection_type == 'select' %]
+        function select_user(borrowernumber, data) {
+            var p = window.opener;
+            p.select_user(borrowernumber, data);
+            window.close();
+        }
+    [% END %]
 //]]>
 </script>
 
@@ -135,11 +168,19 @@ function filter() {
             <table id="memberresultst">
                 <thead>
                     <tr>
-                        <th>Card</th>
-                        <th>Name</th>
-                        <th>Library</th>
-                        <th>Category</th>
-                        <th>&nbsp;</th>
+                        [% FOR column IN columns %]
+                            [% SWITCH column %]
+                                [% CASE 'cardnumber' %]<th>Card</th>
+                                [% CASE 'dateofbirth' %]<th>Date of birth</th>
+                                [% CASE 'address' %]<th>Address</th>
+                                [% CASE 'name' %]<th>Name</th>
+                                [% CASE 'branch' %]<th>Library</th>
+                                [% CASE 'category' %]<th>Category</th>
+                                [% CASE 'dateexpiry' %]<th>Expires on</td>
+                                [% CASE 'borrowernotes' %]<th>Notes</th>
+                                [% CASE 'action' %]<th>&nbsp;</th>
+                            [% END %]
+                        [% END %]
                     </tr>
                   </thead>
                 <tbody></tbody>