TPac: Submit search on sort/limit change
authorBill Erickson <berick@esilibrary.com>
Fri, 2 Sep 2011 14:48:46 +0000 (10:48 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 2 Sep 2011 16:26:49 +0000 (12:26 -0400)
By popular demand, when the user changes the search sort or
limit-to-available options, the form is immediately resubmitted via
JavaScript.  Fails gracefully in the absence of JS.

Minor JS cleanup.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/opac/parts/filtersort.tt2
Open-ILS/src/templates/opac/results.tt2
Open-ILS/web/js/ui/default/opac/simple.js

index 428626c..664be17 100644 (file)
@@ -1,4 +1,5 @@
-<select class="results_header_sel" id='opac.result.sort' name="sort">
+<select class="results_header_sel" id='opac.result.sort' name="sort"
+    [% IF submit_on_change %]onchange='this.form.submit()'[% END %]>
     <option value=''>[% l("Sort by Relevance") %]</option>
     <optgroup label='[% l("Sort by Title") %]'>
         <option value='titlesort'[% value == 'titlesort' ? ' selected="selected"' : '' %]>[% l("Title: A to Z") %]</option>
index 803a070..35eb883 100644 (file)
@@ -46,7 +46,7 @@
                 [% END %]
                 <div class="results_header_div"></div>
                     <div class="results_header_lbl">[% l('Sort by') %]</div>
-                    [% INCLUDE "opac/parts/filtersort.tt2" value=CGI.param('sort') %]
+                    [% INCLUDE "opac/parts/filtersort.tt2" value=CGI.param('sort') submit_on_change=1 %]
                     <div class="results_header_div"></div>
 
                     <div class='results_header_sel' id='simple-detail-view-links'>
@@ -59,7 +59,7 @@
                     <div class="results_header_div"></div>
 
                     <input type="checkbox" id="limit_to_available" name="modifier" value="available"
-                        onchange="avail_change_adv_search(this)"
+                        onchange="limit_to_avail_onchange(this, true)"
                         [% CGI.param('modifier').grep('available').size ? ' checked="checked"' : '' %] />
 
                     <label for="limit_to_available" class="results_header_lbl">
index c120e4b..6e3d29f 100644 (file)
@@ -46,7 +46,7 @@ function killRowIfAtLeast(min, link) {
 }
 function print_node(node_id) {
     var iframe = document.createElement("iframe");
-    var source_node = document.getElementById(node_id);
+    var source_node = $(node_id);
     source_node.parentNode.appendChild(iframe);
 
     var iwin = iframe.contentWindow;
@@ -73,9 +73,14 @@ function select_all_checkboxes(name, checked) {
         }
     }
 }
-function avail_change_adv_search(checkbox) {
+
+function limit_to_avail_onchange(checkbox, submitOnChange) {
     if (checkbox.form._adv && !checkbox.checked) {
-        var search_box = document.getElementById("search_box");
+        var search_box = $('search_box');
         search_box.value = search_box.value.replace(/#available ?/g, "");
     }
+
+    if (submitOnChange) {  
+        checkbox.form.submit(); 
+    }
 }