webstaff: Add "add items to bucket" action to holdings maint
authorMike Rylander <mrylander@gmail.com>
Wed, 9 Sep 2015 20:26:44 +0000 (16:26 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:21 +0000 (15:44 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
Open-ILS/src/templates/staff/cat/catalog/t_add_to_bucket.tt2
Open-ILS/src/templates/staff/cat/catalog/t_holdings.tt2
Open-ILS/web/js/ui/default/staff/cat/catalog/app.js

index eb53d04..cbcf35d 100644 (file)
@@ -5,24 +5,29 @@
 </div>
 <div class="modal-body">
   <div class="row">
-    <div class="form-inline">
-      <div class="form-gruop">
-        <label for="select-bucket">[% l('Copy this record into which bucket?') %]</label>
-        <select id="select-bucket" class="form-control" ng-model="bucket_id"
-                ng-options="bucket.name() for bucket in allBuckets track by bucket.id()">
-        </select>
-        <button class="btn btn-primary" ng-class="{disabled : !bucket_id}" 
-                ng-click="add_to_bucket()">[% l('Add To Selected Bucket') %]</button>
-      </div>
+    <div class="col-md-4">
+      <label for="select-bucket">[% l('Name of existing bucket') %]</label>
+    </div>
+    <div class="col-md-4">
+      <select id="select-bucket" class="form-control" ng-model="bucket_id"
+              ng-options="bucket.id() as bucket.name() for bucket in allBuckets | orderBy:bucket.name()">
+      </select>
+    </div>
+    <div class="col-md-4">
+      <button class="btn btn-primary" ng-class="{disabled : !bucket_id}" 
+          ng-click="add_to_bucket()">[% l('Add To Selected Bucket') %]</button>
     </div>
   </div>
-  <div class="row">
-    <div class="form-inline">
-      <div class="form-gruop">
-        <label for="new-bucket-name">[% l('Name For New Bucket') %]</label>
+  <div class="row pad-vert">
+    <div class="col-md-4">
+      <label for="new-bucket-name">[% l('Name For New Bucket') %]</label>
+    </div>
+    <div class="col-md-4">
         <input type="text" class="form-control" id="new-bucket-name" ng-model="newBucketName" />
-        <button class="btn btn-primary" ng-class="{disabled : !newBucketName}"
-                ng-click="add_to_new_bucket()">[% l('Add To New Bucket') %]</button>
+    </div>
+    <div class="col-md-4">
+      <button class="btn btn-primary" ng-class="{disabled : !newBucketName}"
+          ng-click="add_to_new_bucket()">[% l('Add To New Bucket') %]</button>
       </div>
   </div>
   </div>
index 6b79312..84783e8 100644 (file)
@@ -33,6 +33,8 @@
       checkbox="holdings_show_vols"
       checked="holdings_show_vols"/>
 
+    <eg-grid-action handler="add_copies_to_bucket"
+      label="[% l('Add Items to Bucket') %]"></eg-grid-action>
     <eg-grid-action handler="requestItems"
       label="[% l('Request Items') %]"></eg-grid-action>
     <eg-grid-action handler="attach_to_peer_bib"
index 8b84e23..0fb437e 100644 (file)
@@ -462,6 +462,73 @@ function($scope , $routeParams , $location , $window , $q , egCore , egHolds , e
         }
     });
 
+    $scope.add_copies_to_bucket = function() {
+        var copy_list = gatherSelectedHoldingsIds();
+        if (copy_list.length == 0) return;
+
+        return $modal.open({
+            templateUrl: './cat/catalog/t_add_to_bucket',
+            animation: true,
+            size: 'md',
+            controller:
+                   ['$scope','$modalInstance',
+            function($scope , $modalInstance) {
+
+                $scope.bucket_id = 0;
+                $scope.newBucketName = '';
+                $scope.allBuckets = [];
+
+                egCore.net.request(
+                    'open-ils.actor',
+                    'open-ils.actor.container.retrieve_by_class.authoritative',
+                    egCore.auth.token(), egCore.auth.user().id(),
+                    'copy', 'staff_client'
+                ).then(function(buckets) { $scope.allBuckets = buckets; });
+
+                $scope.add_to_bucket = function() {
+                    var promises = [];
+                    angular.forEach(copy_list, function (cp) {
+                        var item = new egCore.idl.ccbi()
+                        item.bucket($scope.bucket_id);
+                        item.target_copy(cp);
+                        promises.push(
+                            egCore.net.request(
+                                'open-ils.actor',
+                                'open-ils.actor.container.item.create',
+                                egCore.auth.token(), 'copy', item
+                            )
+                        );
+
+                        return $q.all(promises).then(function() {
+                            $modalInstance.close();
+                        });
+                    });
+                }
+
+                $scope.add_to_new_bucket = function() {
+                    var bucket = new egCore.idl.ccb();
+                    bucket.owner(egCore.auth.user().id());
+                    bucket.name($scope.newBucketName);
+                    bucket.description('');
+                    bucket.btype('staff_client');
+
+                    return egCore.net.request(
+                        'open-ils.actor',
+                        'open-ils.actor.container.create',
+                        egCore.auth.token(), 'copy', bucket
+                    ).then(function(bucket) {
+                        $scope.bucket_id = bucket;
+                        $scope.add_to_bucket();
+                    });
+                }
+
+                $scope.cancel = function() {
+                    $modalInstance.dismiss();
+                }
+            }]
+        });
+    }
+
     $scope.requestItems = function() {
         var copy_list = gatherSelectedHoldingsIds();
         if (copy_list.length == 0) return;