TPAC: Preserve loc, query, qtype, and sort params
authorDan Scott <dan@coffeecode.net>
Fri, 6 Jan 2012 03:51:00 +0000 (22:51 -0500)
committerBill Erickson <berick@esilibrary.com>
Wed, 18 Jan 2012 21:54:15 +0000 (16:54 -0500)
In some cases, mkurl() is not enough to preserve our desired CGI params
- such as when redirects are triggered from within a Perl module, or
forms are submitted. Accordingly, the following changes address these
cases where the chosen location / query / query type was being dropped:

* Switching between account preferences
* Creating / deleting / sharing / editing bookbags
* Moving items from temporary list to bookbags
* Adding notes to items in a bookbag
* Placing holds

The primary mechanism for forms is the "preserve_params.tt2" block that
can accept a "params" list of the CGI params that you want to preserve,
but which defaults to location/query/qtype/sort. Similarly, we add the
same preservation steps to the OpenILS::WWW::EGCatLoader::Account module
for most actions.

Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/myopac/lists.tt2
Open-ILS/src/templates/opac/parts/anon_list.tt2
Open-ILS/src/templates/opac/parts/myopac/prefs_base.tt2
Open-ILS/src/templates/opac/parts/preserve_params.tt2 [new file with mode: 0644]
Open-ILS/src/templates/opac/parts/record/summary.tt2
Open-ILS/src/templates/opac/results.tt2

index 7f00cb6..7b0c1a1 100644 (file)
@@ -536,6 +536,11 @@ sub handle_hold_update {
             $e->authtoken, undef, \@vals
         )->gather(1);   # LFW XXX test for failure
         $url = 'https://' . $self->apache->hostname . $self->ctx->{opac_root} . '/myopac/holds';
+        foreach my $param (('loc', 'qtype', 'query')) {
+            if ($self->cgi->param($param)) {
+                $url .= ";$param=" . uri_escape($self->cgi->param($param));
+            }
+        }
     }
 
     $circ->kill_me;
@@ -1574,9 +1579,10 @@ sub load_myopac_bookbags {
                 my $url = $self->ctx->{opac_root} . '/myopac/lists?id=' .
                     $bookbag->id;
 
-                # Keep it if we've got it
-                if ($self->cgi->param("sort")) {
-                    $url .= ";sort=" . $self->cgi->param("sort");
+                foreach my $param (('loc', 'qtype', 'query', 'sort')) {
+                    if ($self->cgi->param($param)) {
+                        $url .= ";$param=" . uri_escape($self->cgi->param($param));
+                    }
                 }
 
                 return $self->generic_redirect($url);
@@ -1636,7 +1642,11 @@ sub load_myopac_bookbag_update {
     my $url = "https://" . $self->apache->hostname .
         $self->ctx->{opac_root} . "/myopac/lists?";
 
-    $url .= 'sort=' . uri_escape($cgi->param("sort")) if $cgi->param("sort");
+    foreach my $param (('loc', 'qtype', 'query', 'sort')) {
+        if ($cgi->param($param)) {
+            $url .= "$param=" . uri_escape($cgi->param($param)) . ";";
+        }
+    }
 
     if ($action eq 'create') {
         $list = Fieldmapper::container::biblio_record_entry_bucket->new;
@@ -1663,6 +1673,11 @@ sub load_myopac_bookbag_update {
 
         my $url = $self->ctx->{opac_root} . '/place_hold?hold_type=T';
         $url .= ';hold_target=' . $_ for @hold_recs;
+        foreach my $param (('loc', 'qtype', 'query')) {
+            if ($cgi->param($param)) {
+                $url .= ";$param=" . uri_escape($cgi->param($param));
+            }
+        }
         return $self->generic_redirect($url);
 
     } else {
index 2a9b774..ffab0b3 100644 (file)
@@ -13,6 +13,7 @@
                     <label for="list_create_name">[% l('Enter the name of the new list:') %]</label>
                 </td>
                 <td>
+                    [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                     <input id="list_create_name" type="text" name="name" />
                     <input type="hidden" name="action" value="create" />
                 </td>
                 <h2 class="bookbag-name"><a title="[% ltitle %]" href="[% url %]">[% bbag.name | html %]</a></h2>
                 [% IF bbag.description %]<div class="bookbag-description">[% bbag.description | html %]</div>[% END %]
             </div>
-            <form action="[% ctx.opac_root %]/myopac/list/update" method="POST">
+            <form action="[% mkurl(ctx.opac_root _ '/myopac/list/update') %]" method="POST">
                 <div class="bookbag-share">
                     <input type="hidden" name="list" value="[% bbag.id %]" />
+                    [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                     [% IF bbag.pub != 't' %]
                     <input type="hidden" name="action" value="show" />
                     <input class="fixed" type="submit" value="[% l('Share') %]" />
                     [% END %]
                 </div>
             </form>
-            <form action="[% ctx.opac_root %]/myopac/list/update" method="POST">
+            <form action="[% mkurl(ctx.opac_root _ '/myopac/list/update') %]" method="POST">
                 <div class="bookbag-controls">
                     <input type="hidden" name="list" value="[% bbag.id %]" />
                     <input type="hidden" name="action" value="delete" />
+                    [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                     <input type="submit" value="[% l('Delete List') %]" />
                 </div>
             </form>
-            <form action="[% ctx.opac_root %]/myopac/list/print" method="POST">
+            <form action="[% mkurl(ctx.opac_root _ '/myopac/list/print') %]" method="POST">
                 <div class="bookbag-controls">
                     <input type="hidden" name="list" value="[% bbag.id %]" />
                     <input type="hidden" name="sort" value="[% CGI.param('sort') | html %]" />
+                    [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                     <input type="submit" value="[% l('Download CSV') %]" />
                 </div>
             </form>
             <div class="sort">
                 <form method="GET">
                     <label for="opac.result.sort">[% l("Sort list items by: ") %]</label>
+                    [%- INCLUDE "opac/parts/preserve_params.tt2" params=['loc', 'query', 'qtype']; %]
                     [% INCLUDE "opac/parts/filtersort.tt2"
                         value=CGI.param('sort') mode='bookbag' %]
                     <input type="hidden" name="id"
                 <form method="POST">
                     <input type="hidden" name="id" value="[% bbag.id %]" />
                     <input type="hidden" name="action" value="editmeta" />
-                    <input type="hidden" name="sort" value="[% CGI.param('sort') | html %]" />
+                    [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                     <table id="bbag-name-desc-form">
                         <tr>
                             <th>
             </div>
         </div>
         <br class="clear-both" />
-        <form action="[% ctx.opac_root %]/myopac/list/update" method="POST">
+        <form action="[% mkurl(ctx.opac_root _ '/myopac/list/update') %]" method="POST">
         <input type="hidden" name="list" value="[% bbag.id %]" />
         <input type="hidden" name="sort" value="[% CGI.param('sort') | uri %]" />
         <table class="bookbag-specific" cellpadding='0' cellspacing='0' border='0'>
                             <option value="place_hold">[% l('Place hold') %]</option>
                             <option value="del_item">[% l('Remove from list') %]</option>
                         </select>
+                        [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                         <input type="submit" value="[% l('Go') %]" />
                     </td>
                 </tr>
                 <tr>
                     <td colspan="3"><!-- All space left of notes column --></td>
                     <td class="save-notes">
+                        [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                         <input type="hidden" name="id" value="[% CGI.param('id') | html %]" />
                         <input type="submit" name="save_notes" value="[% l('Save Notes') %]" />
                     </td>
index 4a96558..00a898d 100644 (file)
@@ -6,13 +6,12 @@
                     id="anonsort" name="anonsort" value=CGI.param("anonsort") %]
                 <input type="hidden" name="id"
                     value="[% CGI.param('id') | html %]" />
-                <!-- just preserve this --><input type="hidden" name="sort"
-                    value="[% CGI.param('sort') | html %]" />
+                [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                 <input type="submit" value="[% l('Sort') %]" />
             </form>
         </div>
 
-        <form action="[% ctx.opac_root %]/mylist/move" method="POST">
+        <form action="[% mkurl(ctx.opac_root _ '/mylist/move') %]" method="GET">
         <div>
             <p class="big-strong">[% l('Temporary List') %]</p>
             <table cellpadding='0' cellspacing='0' border='0'>
@@ -39,6 +38,7 @@
                                 </optgroup>
                                 [% END %]
                             </select>
+                            [%- INCLUDE "opac/parts/preserve_params.tt2"; %]
                             <input type="submit" value="[% l('Go') %]" />
                         </td>
                     </tr>
index aeec099..b6a1194 100644 (file)
                 <a href='#'>[% l("Personal Information") %]</a>
             </div>
             <div class="align">
-                <a href='prefs_notify'>[% l("Notification Preferences") %]</a>
+                <a href='[% mkurl('prefs_notify') %]'>[% l("Notification Preferences") %]</a>
             </div>
             <div class="align">
-                <a href='prefs_settings'>[% l("Search Preferences") %]</a>
+                <a href='[% mkurl('prefs_settings') %]'>[% l("Search Preferences") %]</a>
             </div>
         [% ELSIF prefs_page == 'notify' %]
             <div class="align">
-                <a href='prefs'>[% l("Personal Information") %]</a>
+                <a href='[% mkurl('prefs') %]'>[% l("Personal Information") %]</a>
             </div>
             <div class="align selected">
                 <a href='#'>[% l("Notification Preferences") %]</a>
             </div>
             <div class="align" >
-                <a href='prefs_settings'>[% l("Search Preferences") %]</a>
+                <a href='[% mkurl('prefs_settings') %]'>[% l("Search Preferences") %]</a>
             </div>
         [% ELSE %]
             <div class="align">
-                <a href='prefs'>[% l("Personal Information") %]</a>
+                <a href='[% mkurl('prefs') %]'>[% l("Personal Information") %]</a>
             </div>
             <div class="align">
-                <a href='prefs_notify'>[% l("Notification Preferences") %]</a>
+                <a href='[% mkurl('prefs_notify') %]'>[% l("Notification Preferences") %]</a>
             </div>
             <div class="align selected" >
                 <a href='#'>[% l("Search Preferences") %]</a>
diff --git a/Open-ILS/src/templates/opac/parts/preserve_params.tt2 b/Open-ILS/src/templates/opac/parts/preserve_params.tt2
new file mode 100644 (file)
index 0000000..14fe5be
--- /dev/null
@@ -0,0 +1,9 @@
+[%- 
+UNLESS params;
+    params = ['loc', 'query', 'qtype', 'sort'];
+END;
+FOR param IN params;
+    IF CGI.param(param); %]
+    <input type="hidden" name="[% param %]" value="[% CGI.param(param) | html %]" />
+    [%- END;
+END; %]
index c67d0ef..7867036 100644 (file)
@@ -34,7 +34,7 @@
             operation = ctx.mylist.grep(ctx.bre_id).size ? "delete" : "add";
             label = (operation == "add") ? l("Add to my list") : l("Remove from my list"); 
         %]
-            <a href="[% ctx.opac_root %]/mylist/[% operation %]?record=[% ctx.bre_id %]" class="no-dec">
+            <a href="[% mkurl(ctx.opac_root _ '/mylist/' _ operation, {record => ctx.bre_id}) %]" class="no-dec">
                 <img src="[% ctx.media_prefix %]/images/clipboard.png" alt="" />
                 [% label %]
             </a>
index 17fddab..566936a 100644 (file)
                 </div>
                 [% IF ctx.mylist.size %]
                 <div class="results_header_btns cached_list_div">
-                    <a href="[% ctx.opac_root; ctx.user ? '/myopac/lists' : '/mylist' %]">[% l('View My List') %]</a>
+                    [%- IF ctx.user; %]
+                    <a href="[% mkurl(ctx.opac_root _ '/myopac/lists') %]">[% l('View My List') %]</a>
+                    [%- ELSE %]
+                    <a href="[% mkurl(ctx.opac_root _ '/mylist') %]">[% l('View My List') %]</a>
+                    [%- END %]
                 </div>
                 [% END %]
                 <div class="results_header_div"></div>