items out mark lost / don't display alt circs as needed
authorBill Erickson <berick@esilibrary.com>
Tue, 1 Jul 2014 14:33:05 +0000 (10:33 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 1 Jul 2014 14:33:05 +0000 (10:33 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/patron/t_items_out.tt2
Open-ILS/web/js/ui/default/staff/circ/patron/app.js
Open-ILS/web/js/ui/default/staff/circ/patron/items_out.js
Open-ILS/web/js/ui/default/staff/circ/services/circ.js
Open-ILS/web/js/ui/default/staff/services/grid.js

index 887d433..f23e719 100644 (file)
     handler="edit_due_date"
     label="[% l('Edit Due Date') %]">
   </eg-grid-action>
+  <eg-grid-action 
+    handler="mark_lost"
+    label="[% l('Mark Lost (By Patron)') %]">
+  </eg-grid-action>
 
   <eg-grid-field label="[% l('Circ ID') %]" path='id'></eg-grid-field>
   <eg-grid-field label="[% l('Barcode') %]" path='target_copy.barcode'>
index 343bb5c..86a762d 100644 (file)
@@ -205,12 +205,22 @@ function($q , $timeout , $location , egCore,  egUser , $locale) {
     }
     service.resetPatronLists();  // initialize
 
+    // shortcut to force-reload the current primary
+    service.refreshPrimary = function() {
+        return service.setPrimary(null, service.current, true);
+    }
+
     // sets the primary display user, fetching data as necessary.
     service.setPrimary = function(id, user, force) {
         var user_id = id ? id : (user ? user.id() : null);
 
         console.debug('setting primary user to: ' + user_id);
-        egCore.hatch.setLocalItem('eg.circ.last_patron', user_id);
+
+        if (!user_id) return $q.reject();
+
+        // when loading a new patron, update the last patron setting
+        if (!service.current || service.current.id() != user_id)
+            egCore.hatch.setLocalItem('eg.circ.last_patron', user_id);
 
         // avoid running multiple retrievals for the same patron, which
         // can happen during dbl-click by maintaining a single running
index cc3767e..ffa9d05 100644 (file)
@@ -4,11 +4,27 @@
 
 angular.module('egPatronApp').controller('PatronItemsOutCtrl',
 
-       ['$scope','$q','$routeParams','egCore','egUser','patronSvc','egGridDataProvider','$modal',
-function($scope,  $q,  $routeParams,  egCore , egUser,  patronSvc , egGridDataProvider , $modal) {
+       ['$scope','$q','$routeParams','egCore','egUser','patronSvc',
+        'egGridDataProvider','$modal','egCirc',
+function($scope,  $q,  $routeParams,  egCore , egUser,  patronSvc , 
+         egGridDataProvider , $modal , egCirc) {
 
     $scope.initTab('items_out', $routeParams.id);
-    
+
+    var display_lost, display_lo, display_cr;
+
+    // items out display settings
+    // NOTE:  
+    egCore.org.settings([
+        'ui.circ.items_out.lost',
+        'ui.circ.items_out.longoverdue',
+        'ui.circ.items_out.claimsreturned'])
+    .then(function(set) {
+        display_lost = Number(set['ui.circ.items_out.lost']) || 2;
+        display_lo   = Number(set['ui.circ.items_out.longoverdue']) || 2;
+        display_cr   = Number(set['ui.circ.items_out.claimsreturned']) || 2;
+    });
+
     var provider = egGridDataProvider.instance({});
     $scope.gridDataProvider = provider;
 
@@ -78,11 +94,26 @@ function($scope,  $q,  $routeParams,  egCore , egUser,  patronSvc , egGridDataPr
 
         ).then(function(outs) {
 
-            patronSvc.items_out_ids = outs.out
-                .concat(outs.overdue)
-                .concat(outs.long_overdue)
-                .concat(outs.lost)
-                .concat(outs.claims_returned)
+            patronSvc.items_out_ids = outs.out.concat(outs.overdue);
+
+            // When rendering the items still checked out list, only
+            // show "alternate" circulations whose bitmask is 1 
+            // (i.e. has a value of 1 or 5).
+
+            if (display_lo & 1) {
+                patronSvc.items_out_ids = 
+                    patronSvc.items_out_ids.concat(outs.long_overdue);
+            }
+
+            if (display_lost & 1) {
+                patronSvc.items_out_ids = 
+                    patronSvc.items_out_ids.concat(outs.lost);
+            }
+
+            if (display_cr & 1) {
+                patronSvc.items_out_ids = 
+                    patronSvc.items_out_ids.concat(outs.claims_returned);
+            }
 
             // no item out
             if (!patronSvc.items_out_ids.length) {
@@ -90,9 +121,12 @@ function($scope,  $q,  $routeParams,  egCore , egUser,  patronSvc , egGridDataPr
                 return;
             }
 
-            // relay the notified circs back to the grid through
-            // our promise
-            fetchCircs(offset, count).then(null, null, deferred.notify);
+            // relay the notified circs back to the grid through our promise
+            fetchCircs(offset, count).then(
+                deferred.resolve,
+                null, 
+                deferred.notify
+            );
         });
 
         return deferred.promise;
@@ -185,5 +219,25 @@ function($scope,  $q,  $routeParams,  egCore , egUser,  patronSvc , egGridDataPr
         });
     }
 
+    $scope.mark_lost = function(items) {
+        if (!items.length) return;
+
+        var barcodes = items.map(function(circ) {
+            return circ.target_copy().barcode()
+        });
+
+        egCirc.mark_lost(barcodes)
+        .then(function() { 
+            // reload the user to pick up changes in items out, fines, etc.
+            patronSvc.refreshPrimary();
+
+            // reload circs since LOST items may no longer be applicable
+            // for display.
+            patronSvc.items_out = []; 
+            patronSvc.items_out_ids = [];
+            provider.refresh() 
+        });
+    }
+
 }]);
 
index a18f050..8998b52 100644 (file)
@@ -886,6 +886,34 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         });
     }
 
+    // Mark circulations as lost via copy barcode.  As each item is 
+    // processed, the returned promise is notified of the barcode.
+    // No confirmation dialog is presented.
+    service.mark_lost = function(copy_barcodes) {
+        var deferred = $q.defer();
+        var promises = [];
+
+        angular.forEach(copy_barcodes, function(barcode) {
+            promises.push(
+                egCore.net.request(
+                    'open-ils.circ',
+                    'open-ils.circ.circulation.set_lost',
+                    egCore.auth.token(), {barcode : barcode}
+                ).then(function(resp) {
+                    if (evt = egCore.evt.parse(resp)) {
+                        console.error("Mark lost failed: " + evt.toString());
+                        return;
+                    }
+                    // inform the caller as each item is processed
+                    deferred.notify(barcode);
+                })
+            );
+        });
+
+        $q.all(promises).then(function() {deferred.resolve()});
+        return deferred.promise;
+    }
+
     service.abort_transits = function(transit_ids) {
         return egConfirmDialog.open(
             egCore.strings.ABORT_TRANSIT_CONFIRM, '',
index 545312c..836ea3c 100644 (file)
@@ -750,16 +750,21 @@ angular.module('egGridMod',
                 // avoid firing the collect if there is nothing to collect.
                 if (grid.selfManagedData && !grid.dataProvider.query) return;
 
-                if (grid.collecting) return; // avoid parallel collects()
+                if (grid.collecting) return; // avoid parallel collect()
+                grid.collecting = true;
+
+                console.debug('egGrid.collect() offset=' 
+                    + grid.offset + '; limit=' + grid.limit);
 
                 // ensure all of our dropdowns are closed
+                // TODO: git rid of these and just use dropdown-toggle, 
+                // which is more reliable.
                 $scope.gridColumnPickerIsOpen = false;
                 $scope.gridRowCountIsOpen = false;
                 $scope.gridPageSelectIsOpen = false;
 
                 $scope.items = [];
                 $scope.selected = {};
-                grid.collecting = true;
                 grid.dataProvider.get(grid.offset, grid.limit).then(
                 function() {
                     if (grid.controls.allItemsRetrieved)
@@ -772,7 +777,10 @@ angular.module('egGridMod',
                         if (grid.controls.itemRetrieved)
                             grid.controls.itemRetrieved(item);
                     }
-                })['finally'](function() { grid.collecting = false })
+                }).finally(function() { 
+                    console.debug('egGrid.collect() complete');
+                    grid.collecting = false 
+                });
             }
 
             grid.init();