Make the sort-by and limit-to-available controls appear after adv search
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 22 Aug 2011 22:28:18 +0000 (18:28 -0400)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Mon, 22 Aug 2011 22:28:18 +0000 (18:28 -0400)
This is hackish and suboptimal until we leverage the parsed queries soon
to be returned by QP.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Search.pm
Open-ILS/web/js/ui/default/opac/simple.js
Open-ILS/web/templates/default/opac/results.tt2

index d97ac96..d15c722 100644 (file)
@@ -54,7 +54,10 @@ sub _prepare_biblio_search {
 
     my $query = _prepare_biblio_search_basics($cgi) || '';
 
-    $query = ('#' . $_ . ' ' . $query) foreach ($cgi->param('modifier'));
+    foreach ($cgi->param('modifier')) {
+        # The unless bit is to avoid stacking modifiers.
+        $query = ('#' . $_ . ' ' . $query) unless $query =~ qr/\#\Q$_/;
+    }
 
     # filters
     foreach (grep /^fi:/, $cgi->param) {
@@ -63,10 +66,16 @@ sub _prepare_biblio_search {
         $query .= " $1($term)" if length $term;
     }
 
+    # sort is treated specially, even though it's actually a filter
     if ($cgi->param('sort')) {
+        $query =~ s/sort\([^\)]*\)//g;  # override existing sort(). no stacking.
         my ($axis, $desc) = split /\./, $cgi->param('sort');
         $query .= " sort($axis)";
-        $query .= '#descending' if $desc;
+        if ($desc and not $query =~ /\#descending/) {
+            $query .= '#descending';
+        } elsif (not $desc) {
+            $query =~ s/\#descending//;
+        }
     }
 
     if ($cgi->param('pubdate') && $cgi->param('date1')) {
@@ -204,6 +213,7 @@ sub load_rresults {
     $ctx->{search_facets} = {};
     $ctx->{page_size} = $limit;
     $ctx->{hit_count} = $results->{count};
+    $ctx->{parsed_query} = $results->{parsed_query};
 
     return Apache2::Const::OK if @$rec_ids == 0;
 
index eaa11e2..c120e4b 100644 (file)
@@ -73,3 +73,9 @@ function select_all_checkboxes(name, checked) {
         }
     }
 }
+function avail_change_adv_search(checkbox) {
+    if (checkbox.form._adv && !checkbox.checked) {
+        var search_box = document.getElementById("search_box");
+        search_box.value = search_box.value.replace(/#available ?/g, "");
+    }
+}
index d368a70..bfe9633 100644 (file)
@@ -45,7 +45,6 @@
                 </div>
                 [% END %]
                 <div class="results_header_div"></div>
-                [% UNLESS is_advanced || is_special %]
                     <div class="results_header_lbl">[% l('Sort by') %]</div>
                     [% INCLUDE "default/opac/parts/filtersort.tt2" value=CGI.param('sort') %]
                     <div class="results_header_div"></div>
                     <div class="results_header_div"></div>
 
                     <input type="checkbox" id="limit_to_available" name="modifier" value="available"
+                        onchange="avail_change_adv_search(this)"
                         [% CGI.param('modifier').grep('available').size ? ' checked="checked"' : '' %] />
 
                     <label for="limit_to_available" class="results_header_lbl">
                         [% l('Limit to available items') %]
                     </label>
-                [% END %]
                 <div class="clear-both"></div>
             </div>
         </div>