webstaff: Add Request Items to copy buckets
authorMike Rylander <mrylander@gmail.com>
Thu, 3 Sep 2015 18:24:16 +0000 (14:24 -0400)
committerJason Stephenson <jstephenson@mvlc.org>
Mon, 14 Sep 2015 19:44:19 +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/bucket/copy/t_view.tt2
Open-ILS/web/js/ui/default/staff/cat/bucket/copy/app.js

index a226dca..420dd80 100644 (file)
@@ -10,6 +10,8 @@
 
   [% INCLUDE 'staff/cat/bucket/copy/t_grid_menu.tt2' %]
 
+  <eg-grid-action label="[% l('Request Selected Copies') %]" 
+    handler="requestItems"></eg-grid-action>
   <eg-grid-action label="[% l('Edit Selected Copies') %]" 
     handler="spawnHoldingsEdit"></eg-grid-action>
   <eg-grid-action label="[% l('Remove Selected Copies') %]" 
index 4291211..c866a65 100644 (file)
@@ -13,7 +13,7 @@
  */
 
 angular.module('egCatCopyBuckets', 
-    ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod'])
+    ['ngRoute', 'ui.bootstrap', 'egCoreMod', 'egUiMod', 'egGridMod', 'egUserMod'])
 
 .config(function($routeProvider, $locationProvider, $compileProvider) {
     $locationProvider.html5Mode(true);
@@ -401,9 +401,9 @@ function($scope,  $routeParams,  bucketSvc , egGridDataProvider,   egCore) {
 }])
 
 .controller('ViewCtrl',
-       ['$scope','$q','$routeParams','$timeout','$window','bucketSvc','egCore',
+       ['$scope','$q','$routeParams','$timeout','$window','$modal','bucketSvc','egCore','egUser',
         'egConfirmDialog',
-function($scope,  $q , $routeParams , $timeout , $window , bucketSvc , egCore,
+function($scope,  $q , $routeParams , $timeout , $window , $modal , bucketSvc , egCore , egUser ,
          egConfirmDialog) {
 
     $scope.setTab('view');
@@ -477,6 +477,80 @@ function($scope,  $q , $routeParams , $timeout , $window , bucketSvc , egCore,
         });
     }
 
+    $scope.requestItems = function() {
+        var copy_list = $scope.gridControls.selectedItems().map(
+            function (i) {
+                i.id;
+            }
+        );
+
+        if (copy_list.length == 0) return;
+
+        return $modal.open({
+            templateUrl: './cat/catalog/t_request_items',
+            animation: true,
+            controller:
+                   ['$scope','$modalInstance',
+            function($scope , $modalInstance) {
+                $scope.user = null;
+                $scope.first_user_fetch = true;
+
+                $scope.hold_data = {
+                    hold_type : 'C',
+                    copy_list : copy_list,
+                    pickup_lib: egCore.org.get(egCore.auth.user().ws_ou()),
+                    user      : egCore.auth.user().id()
+                };
+
+                egUser.get( $scope.hold_data.user ).then(function(u) {
+                    $scope.user = u;
+                    $scope.barcode = u.card().barcode();
+                    $scope.user_name = egUser.format_name(u);
+                    $scope.hold_data.user = u.id();
+                });
+
+                $scope.user_name = '';
+                $scope.barcode = '';
+                $scope.$watch('barcode', function (n) {
+                    if (!$scope.first_user_fetch) {
+                        egUser.getByBarcode(n).then(function(u) {
+                            $scope.user = u;
+                            $scope.user_name = egUser.format_name(u);
+                            $scope.hold_data.user = u.id();
+                        }, function() {
+                            $scope.user = null;
+                            $scope.user_name = '';
+                            delete $scope.hold_data.user;
+                        });
+                    }
+                    $scope.first_user_fetch = false;
+                });
+
+                $scope.ok = function(h) {
+                    var args = {
+                        patronid  : h.user,
+                        hold_type : h.hold_type,
+                        pickup_lib: h.pickup_lib.id(),
+                        depth     : 0
+                    };
+
+                    egCore.net.request(
+                        'open-ils.circ',
+                        'open-ils.circ.holds.test_and_create.batch.override',
+                        egCore.auth.token(), args, h.copy_list
+                    );
+
+                    $modalInstance.close();
+                }
+
+                $scope.cancel = function($event) {
+                    $modalInstance.dismiss();
+                    $event.preventDefault();
+                }
+            }]
+        });
+    }
+
     $scope.deleteCopiesFromCatalog = function(copies) {
         egConfirmDialog.open(
             egCore.strings.CONFIRM_DELETE_COPY_BUCKET_ITEMS_FROM_CATALOG,