webstaff: Book Items Now from Item Status collab/phasefx/booking
authorJason Etheridge <jason@esilibrary.com>
Mon, 13 Feb 2017 16:49:58 +0000 (11:49 -0500)
committerJason Etheridge <jason@esilibrary.com>
Mon, 13 Feb 2017 16:49:58 +0000 (11:49 -0500)
FIXME

We can't do what we did with Make Items Bookable, consolidating the items into
one call and invoking a single interface; we get "Can't book multiple resource
types at once".  Easiest solution may be to disable the menu entry if multiple
items are selected.  Alternately, we could open the first resource in the modal
UI and open new tabs for the extras, but then we're stuck using query params
instead of xulG

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Open-ILS/web/js/ui/default/staff/cat/item/app.js

index 8958081..1476dd5 100644 (file)
@@ -393,6 +393,75 @@ function($scope , $q , $routeParams , $location , $timeout , $window , egCore ,
         });
     }
 
+    $scope.book_copies_now = function() {
+        var copies_by_record = {};
+        var record_list = [];
+        angular.forEach(
+            copyGrid.selectedItems(),
+            function (item) {
+                var record_id = item['call_number.record.id'];
+                if (typeof copies_by_record[ record_id ] == 'undefined') {
+                    copies_by_record[ record_id ] = [];
+                    record_list.push( record_id );
+                }
+                copies_by_record[ record_id ].push(item.id);
+            }
+        );
+
+        var promises = [];
+        var combined_brt = [];
+        var combined_brsrc = [];
+        angular.forEach(record_list, function(record_id) {
+            promises.push(
+                egCore.net.request(
+                    'open-ils.booking',
+                    'open-ils.booking.resources.create_from_copies',
+                    egCore.auth.token(),
+                    copies_by_record[record_id]
+                ).then(function(results) {
+                    if (results && results['brt']) {
+                        combined_brt = combined_brt.concat(results['brt']);
+                    }
+                    if (results && results['brsrc']) {
+                        combined_brsrc = combined_brsrc.concat(results['brsrc']);
+                    }
+                })
+            );
+        });
+
+        $q.all(promises).then(function() {
+            if (combined_brt.length > 0 || combined_brsrc.length > 0) {
+                $uibModal.open({
+                    template: '<eg-embed-frame url="booking_admin_url" handlers="funcs"></eg-embed-frame>',
+                    animation: true,
+                    size: 'md',
+                    controller:
+                           ['$scope','$location','egCore','$uibModalInstance',
+                    function($scope , $location , egCore , $uibModalInstance) {
+
+                        $scope.funcs = {
+                            ses : egCore.auth.token(),
+                            bresv_interface_opts : {
+                                booking_results : {
+                                     brt : combined_brt
+                                    ,brsrc : combined_brsrc
+                                }
+                            }
+                        }
+
+                        var booking_path = '/eg/booking/reservation';
+
+                        $scope.booking_admin_url =
+                            $location.absUrl().replace(/\/eg\/staff.*/, booking_path);
+
+                        console.log('Loading Admin Booking URL: ' + $scope.booking_admin_url);
+                        console.log('funcs = ',$scope.funcs);
+
+                    }]
+                });
+            }
+        });
+    }
 
     $scope.requestItems = function() {
         var copy_list = gatherSelectedHoldingsIds();