more checkout / checkin event handling
authorBill Erickson <berick@esilibrary.com>
Tue, 17 Jun 2014 20:16:05 +0000 (16:16 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 17 Jun 2014 20:16:05 +0000 (16:16 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/staff/circ/checkin/index.tt2
Open-ILS/src/templates/staff/circ/patron/index.tt2
Open-ILS/src/templates/staff/circ/share/circ_strings.tt2
Open-ILS/web/js/ui/default/staff/circ/services/circ.js
Open-ILS/web/js/ui/default/staff/services/idl.js

index 2432bd2..6bd7f1c 100644 (file)
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/ui.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/services/user.js"></script>
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/circ/services/circ.js"></script>
+[% INCLUDE 'staff/circ/share/circ_strings.tt2' %]
 <script src="[% ctx.media_prefix %]/js/ui/default/staff/circ/checkin/app.js"></script>
-<script>
-angular.module('egCoreMod').run(['egStrings', function(s) {
-s.UNCAT_ALERT_DIALOG =
-    '[% l('Copy "{{copy_barcode}}" was mis-scanned or is not cataloged') %]';
-s.COPY_ALERT_MSG_DIALOG_TITLE = 
-    '[% l('Copy Alert Message for {{copy_barcode}}') %]';
-}]);
-</script>
 [% END %]
 
 <!-- checkin form -->
index 2102e77..2cb6b7b 100644 (file)
@@ -30,7 +30,6 @@
 
 <script>
 angular.module('egCoreMod').run(['egStrings', function(s) {
-  console.log('HERE index');
   s.ANNOTATE_PAYMENT_MSG = "[% l('Please annotate this payment') %]";
   s.CONFIRM_REFUND_PAYMENT = 
     "[% |l('{{xactIds}}') -%]Are you sure you would like to refund excess payment on bills [_1]?  This action will simply put the amount in the Payment Pending column as a negative value.  You must still select Apply Payment!  Certain types of payments may not be refunded.  The refund may be applied to checked transactions that follow the refunded transaction.[% END %]";
index 5b86806..2bc8be2 100644 (file)
@@ -3,13 +3,17 @@
 <script>
 angular.module('egCoreMod').run(['egStrings', function(s) {
 s.PATRON_CARD_INACTIVE=
-"[% l('The card used to retrieve this account is inactive and may not be used to circulate items.') %]";
+  "[% l('The card used to retrieve this account is inactive and may not be used to circulate items.') %]";
 s.PATRON_INACTIVE=
-"[% l('This account is inactive and may not circulate items.') %]";
+  "[% l('This account is inactive and may not circulate items.') %]";
 s.PATRON_ACCOUNT_EXPIRED=
-"[% l('This account has expired and may not circulate items.') %]";
+  "[% l('This account has expired and may not circulate items.') %]";
 s.CHECKOUT_FAILED_GENERIC=
-"[% l('Unable to checkout copy [_1] : [_2]', '{{barcode}}', '{{textcode}}') %]"
+  "[% l('Unable to checkout copy [_1] : [_2]', '{{barcode}}', '{{textcode}}') %]"
+s.COPY_ALERT_MSG_DIALOG_TITLE=
+    '[% l('Copy Alert Message for {{copy_barcode}}') %]';
+s.UNCAT_ALERT_DIALOG =
+    '[% l('Copy "{{copy_barcode}}" was mis-scanned or is not cataloged') %]';
 }]);
 </script>
 
index 2ebebab..3bf61ea 100644 (file)
@@ -30,7 +30,7 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         'ITEM_RENTAL_FEE_REQUIRED',
         'PATRON_EXCEEDS_LOST_COUNT',
         'COPY_CIRC_NOT_ALLOWED',
-        'COPY_NOT_AVAILABLE', // HM?
+        'COPY_NOT_AVAILABLE',
         'COPY_IS_REFERENCE',
         'COPY_ALERT_MESSAGE',
         'ITEM_ON_HOLDS_SHELF'                        
@@ -147,13 +147,13 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         switch(evt.textcode) {
             case 'COPY_NOT_AVAILABLE':
                 return service.copy_not_avail_dialog(evt, params, options);
+            case 'COPY_ALERT_MESSAGE':
+                return service.copy_alert_dialog(evt, params, options, 'checkout');
             default: 
                 return service.override_dialog(evt, params, options);
         }
     }
 
-    //TODO: copy_alert_dialog
-
     service.handle_checkout_resp = function(evt, params, options) {
 
         var final_resp = {evt : evt, params : params, options : options};
@@ -184,10 +184,10 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
             case 'PATRON_ACCOUNT_EXPIRED':
                 return service.exit_alert(egCore.strings[evt.textcode]);
 
+
             /* stuff yet to consider 
             PERM_FAILURE
             CIRC_CLAIMS_RETURNED
-            COPY_ALERT_MESSAGE
             */
 
             default:
@@ -372,6 +372,38 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         );
     }
 
+    // find the open transit for the given copy barcode; flesh the org
+    // units locally.
+    service.find_copy_transit = function(evt, params, options) {
+
+        if (evt && evt.payload && (transit = evt.payload.transit)) { // not ==
+            transit.source(egCore.org.get(transit.source()));
+            transit.dest(egCore.org.get(transit.dest()));
+            return $q.when(transit);
+        }
+
+         return egCore.pcrud.search('atc',
+            {   dest_recv_time : null},
+            {   flesh : 1, 
+                flesh_fields : {atc : ['target_copy']},
+                join : {
+                    acp : {
+                        filter : {
+                            barcode : params.copy_barcode,
+                            deleted : 'f'
+                        }
+                    }
+                },
+                limit : 1,
+                order_by : {atc : 'source_send_time desc'}, 
+            }
+        ).then(function(transit) {
+            transit.source(egCore.org.get(transit.source()));
+            transit.dest(egCore.org.get(transit.dest()));
+            return transit;
+        });
+    }
+
     service.copy_in_transit_dialog = function(evt, params, options) {
         return $modal.open({
             templateUrl: './circ/share/t_copy_in_transit_dialog',
@@ -385,26 +417,7 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
             resolve : {
                 // fetch the conflicting open transit w/ fleshed copy
                 transit : function() {
-                    return egCore.pcrud.search('atc',
-                        {   dest_recv_time : null},
-                        {   flesh : 1, 
-                            flesh_fields : {atc : ['target_copy']},
-                            join : {
-                                acp : {
-                                    filter : {
-                                        barcode : params.copy_barcode,
-                                        deleted : 'f'
-                                    }
-                                }
-                            },
-                            limit : 1,
-                            order_by : {atc : 'source_send_time desc'}, 
-                        }
-                    ).then(function(transit) {
-                        transit.source(egCore.org.get(transit.source()));
-                        transit.dest(egCore.org.get(transit.dest()));
-                        return transit;
-                    });
+                    return service.find_copy_transit(evt, params, options);
                 }
             }
         }).result.then(
@@ -489,10 +502,11 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
             case 'SUCCESS':
             case 'NO_CHANGE':
 
-                // inform user if the item is on the local holds shelf
                 if (copy.status() == 8 // on holds shelf
                     && hold 
                     && hold.pickup_lib() == egCore.auth.user().ws_ou()) {
+                    // inform user if the item is on the local holds shelf
+                    
                     return service.route_dialog(
                         './circ/share/t_hold_shelf_dialog', 
                         evt, params, options
@@ -502,41 +516,19 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
                     return $q.when(final_resp);
                 }
                 
-            // show the route dialog
             case 'ROUTE_ITEM':
                 return service.route_dialog(
                     './circ/share/t_transit_dialog', 
                     evt, params, options
                 ).then(function() { return final_resp });
 
-
-            // show the copy not found alert dialog
             case 'ASSET_COPY_NOT_FOUND':
-                // FIXME: where can we put strings that don't live within
-                // a specific page?
                 return egAlertDialog.open(
                     egCore.strings.UNCAT_ALERT_DIALOG, params)
                     .result.then(function() {return final_resp});
 
             case 'COPY_ALERT_MESSAGE':
-                // FIXME: where can we put strings that don't live within
-                // a specific page?
-
-                return egConfirmDialog.open(
-                    egCore.strings.COPY_ALERT_MSG_DIALOG_TITLE, 
-                    evt.payload,  // payload == alert message text
-                    {   copy_barcode : params.copy_barcode,
-                        ok : function() {},
-                        cancel : function() { 
-                            // TODO: do we return the final_resp so
-                            // the user can display the copy even though
-                            // the checkin did not take place?
-                        }
-                    }
-                ).result.then(function() {
-                    options.override = true;
-                    return service.checkin(params, options);
-                });
+                return service.copy_alert_dialog(evt, params, options, 'checkin');
 
             default:
                 console.warn('unhandled checkin response : ' + evt.textcode);
@@ -548,8 +540,8 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
         return $modal.open({
             templateUrl: tmpl,
             controller: [
-                '$scope', '$modalInstance', 'destAddr', 'holdUser',
-                function($scope, $modalInstance, destAddr, holdUser) {
+                        '$scope','$modalInstance','destAddr','holdUser','transit',
+                function($scope , $modalInstance , destAddr , holdUser , transit) {
 
                 // TODO: synchronize scope variables with print context vars.
                 
@@ -563,8 +555,6 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
                 $scope.print = function() {
                     $modalInstance.close();
 
-                    var transit = evt.payload.transit;
-
                     var print_context = {
                         transit : egCore.idl.toHash(transit),
                         title : evt.payload.record.title(),
@@ -602,11 +592,29 @@ function($modal , $q , egCore , egAlertDialog , egConfirmDialog) {
                             flesh_fields : {'au' : ['card']}
                         }
                     );
+                },
+                transit : function() {
+                    return service.find_copy_transit(evt, params, options);
                 }
             }
         }).result;
     }
 
+    // action == what action to take if the user confirms the alert
+    service.copy_alert_dialog = function(evt, params, options, action) {
+        return egConfirmDialog.open(
+            egCore.strings.COPY_ALERT_MSG_DIALOG_TITLE, 
+            evt.payload,  // payload == alert message text
+            {   copy_barcode : params.copy_barcode,
+                ok : function() {},
+                cancel : function() {}
+            }
+        ).result.then(function() {
+            options.override = true;
+            return service[action](params, options);
+        });
+    }
+
     // check the barcode.  If it's no good, show the warning dialog
     // Resolves on success, rejected on error
     service.test_barcode = function(bc) {
index 1fe7129..5d4d5af 100644 (file)
@@ -74,6 +74,7 @@ angular.module('egCoreMod')
      * e.g.  {"call_number.label" : "foo"}
      */
     service.toHash = function(obj, flatten) {
+        if (!obj) return null;
         var hash = {};
         angular.forEach(
             service.classes[obj.classname].fields,