teach create new list action how to move contents of cart to it
authorGalen Charlton <gmc@equinoxinitiative.org>
Thu, 7 Jun 2018 21:43:14 +0000 (17:43 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Thu, 7 Jun 2018 21:43:46 +0000 (17:43 -0400)
note that the mkurl macro is now also getting the beginnings of
a hard-coded list of params to always clear so that move_cart_by_default
doesn't travel around unnecessarily

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/templates/opac/myopac/lists.tt2
Open-ILS/src/templates/opac/parts/cart.tt2
Open-ILS/src/templates/opac/parts/header.tt2

index b1c678b..c45a07a 100644 (file)
@@ -2490,6 +2490,7 @@ sub load_myopac_bookbag_update {
     my @add_rec = $cgi->param('add_rec') || $cgi->param('record');
     my @selected_item = $cgi->param('selected_item');
     my $shared = $cgi->param('shared');
+    my $move_cart = $cgi->param('move_cart');
     my $name = $cgi->param('name');
     my $description = $cgi->param('description');
     my $success = 0;
@@ -2518,15 +2519,29 @@ sub load_myopac_bookbag_update {
             $list->pub($shared ? 't' : 'f');
             $success = $U->simplereq('open-ils.actor',
                 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list);
-            if (ref($success) ne 'HASH' && scalar @add_rec) {
-                $list_id = (ref($success)) ? $success->id : $success;
-                foreach my $add_rec (@add_rec) {
-                    my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
-                    $item->bucket($list_id);
-                    $item->target_biblio_record_entry($add_rec);
-                    $success = $U->simplereq('open-ils.actor',
-                                            'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
-                    last unless $success;
+            if (ref($success) ne 'HASH') {
+                if (scalar @add_rec) {
+                    $list_id = (ref($success)) ? $success->id : $success;
+                    foreach my $add_rec (@add_rec) {
+                        my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
+                        $item->bucket($list_id);
+                        $item->target_biblio_record_entry($add_rec);
+                        $success = $U->simplereq('open-ils.actor',
+                                                'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
+                        last unless $success;
+                    }
+                }
+                if ($move_cart) {
+                    my ($cache_key, $list) = $self->fetch_mylist(0, 1);
+                    foreach my $add_rec (@$list) {
+                        my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
+                        $item->bucket($list_id);
+                        $item->target_biblio_record_entry($add_rec);
+                        $success = $U->simplereq('open-ils.actor',
+                                                'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
+                        last unless $success;
+                    }
+                    $self->clear_anon_cache;
                 }
             }
             $url = $cgi->param('where_from') if ($success && $cgi->param('where_from'));
index 53b604a..d46dc34 100644 (file)
                     </a>
                 </td>
             </tr>
+            [% IF ctx.mylist.size %]
+            <tr>
+                <td class="list_create_table_label">
+                    <label for="list_move_cart">[% l('Move contents of cart to this list?') %]</label>
+                </td>
+                <td>
+                    <select name="move_cart" id="list_move_cart">
+                        <option value="0">[% l('No') %]
+                        <option value="1" [% IF CGI.param('move_cart_by_default') %]selected="selected"[% END%]>[% l('Yes') %]
+                    </select>
+                </td>
+            </tr>
+            [% END %]
             <tr>
                 <td>&nbsp;</td>
                 <td class="list-create-table-buttons">
index 43afb30..a89f89d 100644 (file)
@@ -7,7 +7,7 @@
         <li><a href="[% mkurl(ctx.opac_root _ '/mylist/print', {}) %]">[% l('Print Title Details') %]</a></li>
         <li><a href="[% mkurl(ctx.opac_root _ '/mylist/email', {}) %]">[% l('Email Title Details') %]</a></li>
         [% IF !ctx.is_browser_staff %]
-        <li><a href="[% mkurl(ctx.opac_root _ '/myopac/lists', {}) %]">[% l('Add Cart to Saved List') %]</a></li>
+        <li><a href="[% mkurl(ctx.opac_root _ '/myopac/lists', { move_cart_by_default => 1 }) %]">[% l('Add Cart to Saved List') %]</a></li>
         [% END %]
         [% IF ctx.is_browser_staff %]
         <li><a id="add_cart_to_bucket">[% l('Add Cart to Bucket') %]</a></li>
index de933e9..d5c0871 100644 (file)
             cgi.delete_all();
         END;
 
+        # some standing, hardcoded parameters to always clear
+        # because they're used for specific, transitory purposes
+        cgi.delete('move_cart_by_default');
+
         # x and y are artifacts of using <input type="image" /> tags 
         # instead of true submit buttons, and their values are never used.
         cgi.delete('x', 'y');