Bug 12648: Hide the result search on load
authorJonathan Druart <jonathan.druart@biblibre.com>
Wed, 1 Oct 2014 09:17:48 +0000 (11:17 +0200)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 11 Mar 2015 14:47:38 +0000 (11:47 -0300)
When no search has been done yet, it's not necessary to display the
result list.

Signed-off-by: Paola Rossi <paola.rossi@cineca.it>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
acqui/add_user_search.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/add_user_search.tt

index c4717c5..646e217 100755 (executable)
@@ -51,5 +51,6 @@ my $search_patrons_with_acq_perm_only =
 
 $template->param(
     patrons_with_acq_perm_only => $search_patrons_with_acq_perm_only,
+    view => ( $input->request_method() eq "GET" ) ? "show_form" : "show_results",
 );
 output_html_with_http_headers( $input, $cookie, $template->output );
index a61a5be..2a7233f 100644 (file)
@@ -8,15 +8,32 @@
 <script type="text/javascript">
 //<![CDATA[
 
+var search = 1;
 $(document).ready(function(){
     $("#info").hide();
     $("#error").hide();
+
+    [% IF view != "show_results" %]
+        $("#searchresults").hide();
+        search = 0;
+    [% END %]
+
+    $("#searchmember_filter").on('keyup', function(){
+        filter();
+    });
     // Apply DataTables on the results table
     dtMemberResults = $("#memberresultst").dataTable($.extend(true, {}, dataTablesDefaults, {
         'bServerSide': true,
         'sAjaxSource': "/cgi-bin/koha/svc/members/search",
         'fnServerData': function(sSource, aoData, fnCallback) {
+            if ( ! search ) {
+                return;
+            }
             aoData.push({
+                'name': 'searchmember',
+                'value': $("#searchmember_filter").val()
+            },
+            {
                 'name': 'template_path',
                 'value': 'acqui/tables/members_results.tt',
             }
@@ -50,13 +67,35 @@ $(document).ready(function(){
         [% ELSE %]
             'sPaginationType': 'full_numbers',
             "iDisplayLength": [% Koha.Preference('PatronsPerPage') %],
-            "bProcessing": true,
         [% END %]
+        'bFilter': false,
         'bProcessing': true,
     }));
     dtMemberResults.fnAddFilters("filter", 750);
 });
 
+var delay = (function(){
+  var timer = 0;
+  return function(callback, ms){
+    clearTimeout (timer);
+    timer = setTimeout(callback, ms);
+  };
+})();
+
+function filter() {
+    search = 1;
+
+    $("#searchresults").show();
+
+    if ( $("#searchmember_filter").val().length > 0 ) {
+        delay(function(){
+            dtMemberResults.fnDraw();
+        }, 1000);
+    }
+
+    return false;
+}
+
     // modify parent window owner element
     function add_user(borrowernumber, borrowername) {
         var p = window.opener;
@@ -81,6 +120,10 @@ $(document).ready(function(){
     <div class="yui-g">
 
         <h3>Search for patron</h3>
+
+          <label for="searchmember_filter">Search:</label>
+          <input type="text" id="searchmember_filter" value="[% searchmember %]"/>
+
         [% 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 %]
@@ -88,18 +131,20 @@ $(document).ready(function(){
         <div id="info" class="dialog message"></div>
         <div id="error" class="dialog alert"></div>
 
-        <table id="memberresultst">
-          <thead>
-            <tr>
-              <th>Card</th>
-              <th>Name</th>
-              <th>Library</th>
-              <th>Category</th>
-              <th>&nbsp;</th>
-            </tr>
-          </thead>
-          <tbody></tbody>
-        </table>
+        <div id="searchresults">
+            <table id="memberresultst">
+                <thead>
+                    <tr>
+                        <th>Card</th>
+                        <th>Name</th>
+                        <th>Library</th>
+                        <th>Category</th>
+                        <th>&nbsp;</th>
+                    </tr>
+                  </thead>
+                <tbody></tbody>
+            </table>
+        </div>
 
 <div id="closewindow"><a href="#" class="close">Close</a></div>
 </div>