Bug 13891: DataTables server-side processing - Fix regressions
authorJonathan Druart <jonathan.druart@biblibre.com>
Mon, 23 Mar 2015 09:43:11 +0000 (10:43 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Mon, 13 Apr 2015 13:55:30 +0000 (10:55 -0300)
This patch fixes the regressions introduced by the previous patches.
If you have tested all in once, you didn't see them.

It introduces library, category and "first letter" filters.

Test plan:
1/ On all pages impacted by previous patches + new order empty (link patron to
an order) + guarantor search
2/ Add / Select patron to the list
3/ Use the filters
4/ Confirm there is no regression

Tested together with other patches.
Signed-off-by: Marc Veron <veron@veron.ch>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
acqui/add_user_search.pl
admin/add_user_search.pl
koha-tmpl/intranet-tmpl/prog/en/modules/common/patron_search.tt
members/guarantor_search.pl
patroncards/add_user_search.pl
serials/add_user_search.pl

index e86b0e4..7b8b969 100755 (executable)
@@ -21,6 +21,8 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use C4::Auth;
+use C4::Branch qw( GetBranches );
+use C4::Category;
 use C4::Output;
 use C4::Members;
 
@@ -49,11 +51,17 @@ my $search_patrons_with_acq_perm_only =
     ( $referer =~ m|acqui/basket.pl| )
         ? 1 : 0;
 
+my $onlymine = C4::Branch::onlymine;
+my $branches = C4::Branch::GetBranches( $onlymine );
+
 $template->param(
     patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
     view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
     columns => ['cardnumber', 'name', 'branch', 'category', 'action'],
     json_template => 'acqui/tables/members_results.tt',
     selection_type => 'add',
+    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
+    categories      => [ C4::Category->all ],
+    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
 );
 output_html_with_http_headers( $input, $cookie, $template->output );
index 33fb6ac..bafc9e1 100755 (executable)
@@ -21,6 +21,8 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use C4::Auth;
+use C4::Branch qw( GetBranches );
+use C4::Category;
 use C4::Output;
 use C4::Members;
 
@@ -50,11 +52,17 @@ my $search_patrons_with_acq_perm_only =
     ( $referer =~ m|admin/aqbudgets.pl| )
         ? 1 : 0;
 
+my $onlymine = C4::Branch::onlymine;
+my $branches = C4::Branch::GetBranches( $onlymine );
+
 $template->param(
     patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
     view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
     columns => ['cardnumber', 'name', 'branch', 'category', 'action'],
     json_template => 'acqui/tables/members_results.tt',
     selection_type => $selection_type,
+    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
+    categories      => [ C4::Category->all ],
+    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
 );
 output_html_with_http_headers( $input, $cookie, $template->output );
index e182688..b65d3f8 100644 (file)
@@ -18,9 +18,6 @@ $(document).ready(function(){
         search = 0;
     [% END %]
 
-    $("#searchmember_filter").on('keyup', function(){
-        filter();
-    });
     // Apply DataTables on the results table
     dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
         'bServerSide': true,
@@ -32,6 +29,15 @@ $(document).ready(function(){
             aoData.push({
                 'name': 'searchmember',
                 'value': $("#searchmember_filter").val()
+            },{
+                'name': 'firstletter',
+                'value': $("#firstletter_filter").val()
+            },{
+                'name': 'categorycode',
+                'value': $("#categorycode_filter").val()
+            },{
+                'name': 'branchcode',
+                'value': $("#branchcode_filter").val()
             },{
                 'name': 'name_sorton',
                 'value': 'borrowers.surname borrowers.firstname'
@@ -87,31 +93,27 @@ $(document).ready(function(){
         'bFilter': false,
         'bProcessing': true,
     }));
-    dtMemberResults.fnAddFilters("filter", 750);
-});
 
-var delay = (function(){
-  var timer = 0;
-  return function(callback, ms){
-    clearTimeout (timer);
-    timer = setTimeout(callback, ms);
-  };
-})();
+    $("#searchform").on('submit', filter);
+});
 
 function filter() {
     search = 1;
-
+    $("#firstletter_filter").val('');
     $("#searchresults").show();
-
-    if ( $("#searchmember_filter").val().length > 0 ) {
-        delay(function(){
-            dtMemberResults.fnDraw();
-        }, 1000);
-    }
-
+    dtMemberResults.fnDraw();
     return false;
 }
 
+// User has clicked on a letter
+function filterByFirstLetterSurname(letter) {
+    $("#firstletter_filter").val(letter);
+    search = 1;
+    $("#searchresults").show();
+    dtMemberResults.fnDraw();
+}
+
+
     // modify parent window owner element
     [% IF selection_type == 'add' %]
         function add_user(borrowernumber, borrowername) {
@@ -152,18 +154,56 @@ function filter() {
   <div id="bd">
     <div class="yui-g">
 
-        <h3>Search for patron</h3>
-
-          <label for="searchmember_filter">Search:</label>
-          <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
+        <form id="searchform">
+            <fieldset class="brief">
+                <h3>Search for patron</h3>
+                <ol>
+                    <li>
+                        <label for="searchmember_filter">Search:</label>
+                        <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
+                    </li>
+                    <li>
+                        <label for="categorycode_filter">Category:</label>
+                        <select id="categorycode_filter">
+                            <option value="">Any</option>
+                            [% FOREACH category IN categories %]
+                                <option value="[% category.categorycode %]">[% category.description %]</option>
+                            [% END %]
+                        </select>
+                    </li>
+                    <li>
+                        <label for="branchcode_filter">Library:</label>
+                        <select id="branchcode_filter">
+                            [% IF branches.size != 1 %]
+                                <option value="">Any</option>
+                            [% END %]
+                            [% FOREACH branch IN branches %]
+                                <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
+                            [% END %]
+                        </select>
+                    </li>
+                </ol>
+                <fieldset class="action">
+                    <input type="submit" value="Search" />
+                </fieldset>
+            </fieldset>
+        <form>
 
         [% IF patrons_with_acq_perm_only %]
             <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div>
         [% END %]
 
+        <div class="browse">
+            Browse by last name:
+            [% FOREACH letter IN alphabet.split(' ') %]
+                <a style="cursor:pointer" onclick="filterByFirstLetterSurname('[% letter %]');">[% letter %]</a>
+            [% END %]
+        </div>
+
         <div id="info" class="dialog message"></div>
         <div id="error" class="dialog alert"></div>
 
+        <input type="hidden" id="firstletter_filter" value="" />
         <div id="searchresults">
             <table id="memberresultst">
                 <thead>
index 6e4e6ab..ac9d1ce 100755 (executable)
@@ -21,6 +21,8 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use C4::Auth;
+use C4::Branch qw( GetBranches );
+use C4::Category;
 use C4::Output;
 use C4::Members;
 
@@ -42,10 +44,16 @@ my $op = $input->param('op') || '';
 
 my $referer = $input->referer();
 
+my $onlymine = C4::Branch::onlymine;
+my $branches = C4::Branch::GetBranches( $onlymine );
+
 $template->param(
     view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
     columns => ['cardnumber', 'name', 'dateofbirth', 'address', 'action' ],
     json_template => 'members/tables/guarantor_search.tt',
     selection_type => 'select',
+    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
+    categories      => [ C4::Category->all ],
+    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
 );
 output_html_with_http_headers( $input, $cookie, $template->output );
index 2953dcf..bc86076 100755 (executable)
@@ -21,6 +21,8 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use C4::Auth;
+use C4::Branch qw( GetBranches );
+use C4::Category;
 use C4::Output;
 use C4::Members;
 
@@ -42,10 +44,16 @@ my $op = $input->param('op') || '';
 
 my $referer = $input->referer();
 
+my $onlymine = C4::Branch::onlymine;
+my $branches = C4::Branch::GetBranches( $onlymine );
+
 $template->param(
-    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
-    columns => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'],
-    json_template => 'patroncards/tables/members_results.tt',
-    selection_type => 'add',
+    view            => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
+    columns         => ['cardnumber', 'name', 'category', 'branch', 'dateexpiry', 'borrowernotes', 'action'],
+    json_template   => 'patroncards/tables/members_results.tt',
+    selection_type  => 'add',
+    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
+    categories      => [ C4::Category->all ],
+    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
 );
 output_html_with_http_headers( $input, $cookie, $template->output );
index 50d63bd..8fc15af 100755 (executable)
@@ -21,6 +21,8 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use C4::Auth;
+use C4::Branch qw( GetBranches );
+use C4::Category;
 use C4::Output;
 use C4::Members;
 
@@ -42,10 +44,16 @@ my $op = $input->param('op') || '';
 
 my $referer = $input->referer();
 
+my $onlymine = C4::Branch::onlymine;
+my $branches = C4::Branch::GetBranches( $onlymine );
+
 $template->param(
     view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
     columns => ['cardnumber', 'name', 'branch', 'action'],
     json_template => 'serials/tables/members_results.tt',
     selection_type => 'add',
+    alphabet        => ( C4::Context->preference('alphabet') || join ' ', 'A' .. 'Z' ),
+    categories      => [ C4::Category->all ],
+    branches        => [ map { { branchcode => $_->{branchcode}, branchname => $_->{branchname} } } values %$branches ],
 );
 output_html_with_http_headers( $input, $cookie, $template->output );