add an add-to-cart action for the web staff client
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 23 May 2018 22:07:25 +0000 (18:07 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 23 May 2018 22:07:25 +0000 (18:07 -0400)
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/opac/parts/cart.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js

index d8bd69b..3fbfa76 100644 (file)
@@ -7,6 +7,9 @@
         <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>
         <li><a href="[% mkurl(ctx.opac_root _ '/myopac/lists', {}) %]">[% l('Add Cart to Saved List') %]</a></li>
+        [% IF ctx.is_browser_staff %]
+        <li><a id="add_cart_to_bucket">[% l('Add Cart to Bucket') %]</a></li>
+        [% END %]
         <li><a href="[% mkurl(ctx.opac_root _ '/mylist/clear', {}) %]">[% l('Clear Cart') %]</a></li>
       </ul>
     </li>
index 4b3d186..62e4cfc 100644 (file)
@@ -318,8 +318,26 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         }
     }
 
-    $scope.add_to_record_bucket = function() {
-        var recId = $scope.record_id;
+    $scope.add_cart_to_record_bucket = function() {
+        var cartkey = $cookies.get('anoncache');
+        if (!cartkey) return;
+        egCore.net.request(
+            'open-ils.actor',
+            'open-ils.actor.anon_cache.get_value',
+            cartkey,
+            'mylist'
+        ).then(function(list) {
+            list = list.map(function(x) {
+                return parseInt(x);
+            });
+            $scope.add_to_record_bucket(list);
+        });
+    }
+
+    $scope.add_to_record_bucket = function(recs) {
+        if (!angular.isArray(recs)) {
+            recs = [ $scope.record_id ];
+        }
         return $uibModal.open({
             templateUrl: './cat/catalog/t_add_to_bucket',
             backdrop: 'static',
@@ -340,14 +358,18 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                 ).then(function(buckets) { $scope.allBuckets = buckets; });
 
                 $scope.add_to_bucket = function() {
-                    var item = new egCore.idl.cbrebi();
-                    item.bucket($scope.bucket_id);
-                    item.target_biblio_record_entry(recId);
-                    egCore.net.request(
-                        'open-ils.actor',
-                        'open-ils.actor.container.item.create',
-                        egCore.auth.token(), 'biblio', item
-                    ).then(function(resp) {
+                    var promises = [];
+                    angular.forEach(recs, function(recId) {
+                        var item = new egCore.idl.cbrebi();
+                        item.bucket($scope.bucket_id);
+                        item.target_biblio_record_entry(recId);
+                        promises.push(egCore.net.request(
+                            'open-ils.actor',
+                            'open-ils.actor.container.item.create',
+                            egCore.auth.token(), 'biblio', item
+                        ));
+                    });
+                    $q.all(promises).then(function(resp) {
                         $uibModalInstance.close();
                     });
                 }
@@ -583,7 +605,10 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
                     $(doc).find('#hold_usr_input').val(barc);
                     $(doc).find('#hold_usr_input').change();
                 });
-            })
+            });
+            $(doc).find('#add_cart_to_bucket').on('click', function() {
+                $scope.add_cart_to_record_bucket();
+            });
         }
 
     }