sync permit, async checkout
authorpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 12 Oct 2006 21:08:02 +0000 (21:08 +0000)
committerpines <pines@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Thu, 12 Oct 2006 21:08:02 +0000 (21:08 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@6454 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/xul/staff_client/server/circ/checkout.js
Open-ILS/xul/staff_client/server/circ/checkout_overlay.xul

index 37e557f..184ec37 100644 (file)
@@ -219,6 +219,12 @@ circ.checkout.prototype = {
 
                this.check_disable();
 
+               var robj = obj.network.simple_request(
+                       'FM_CIRC_COUNT_RETRIEVE_VIA_USER',
+                       [ ses(), obj.patron_id ]
+               );
+               obj.items_out_count = (robj.out + robj.overdue + robj.claims_returned + robj.long_overdue );
+
        },
 
        'check_disable' : function() {
@@ -293,98 +299,135 @@ circ.checkout.prototype = {
                }
        },
 
-       'checkout' : function(params) {
+       '_checkout' : function(params) {
                var obj = this;
+               try {
+                       /**********************************************************************************************************************/
+                       /* This does the actual checkout/renewal */
+               
+                       var x = document.createElement('label');
+                       x.setAttribute('style','color: green');
+                       x.setAttribute('value',(params.barcode ? params.barcode : 'non-cat' ) + ' checkout pending...');
+                       document.getElementById('msg_area').appendChild(x);
 
-               try { obj.check_date(obj.controller.view.checkout_duedate_menu); } catch(E) { return; }
-               if (obj.controller.view.checkout_duedate_menu.value != 'Normal') {
-                       params.due_date = obj.controller.view.checkout_duedate_menu.value;
-               }
-
-               if (! (params.barcode||params.noncat)) return;
-
-               /**********************************************************************************************************************/
-               /* This does the actual checkout/renewal, but is called after a permit test further below */
-               function check_out(params) {
-
-                       var checkout = obj.network.request(
+                       obj.network.request(
                                api.CHECKOUT.app,
                                api.CHECKOUT.method,
-                               [ ses(), params ]
+                               [ ses(), params, obj.items_out_count ],
+                               function(req) {
+                                       obj._checkout_callback(req,x);
+                               }
                        );
+                       
+                       if (typeof params.noncat == 'undefined') obj.items_out_count++;
 
+               } catch(E) {
+                       x.setAttribute('style','color: red');
+                       x.setAttribute('value',params.barcode + ' failed.');
+                       if (typeof params.noncat == 'undefined') obj.items_out_count--;
+                       obj.error.standard_unexpected_error_alert('Check Out Failed #2',E);
+               }
+       },
+
+       '_checkout_callback' : function(req,x) {
+               var obj = this;
+               try {
+                       var checkout = req.getResultObject();
                        if (checkout.ilsevent == 0) {
 
-                               if (!checkout.payload) checkout.payload = {};
-
-                               if (!checkout.payload.circ) {
-                                       checkout.payload.circ = new aoc();
-                                       /*********************************************************************************************/
-                                       /* Non Cat */
-                                       if (checkout.payload.noncat_circ) {
-                                               checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
-                                               checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
-                                               checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
-                                               
-                                               JSAN.use('util.date');
-                                               var c = checkout.payload.noncat_circ.circ_time();
-                                               var d = c == "now" ? new Date() : util.date.db_date2Date( c );
-                                               var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
-                                               var cd = t.circ_duration() || "14 days";
-                                               var i = util.date.interval_to_seconds( cd ) * 1000;
-                                               d.setTime( Date.parse(d) + i );
-                                               checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
+                       if (!checkout.payload) checkout.payload = {};
 
-                                       }
-                               }
+                       if (!checkout.payload.circ) {
+                               checkout.payload.circ = new aoc();
+                               /*********************************************************************************************/
+                               /* Non Cat */
+                               if (checkout.payload.noncat_circ) {
+                                       checkout.payload.circ.circ_lib( checkout.payload.noncat_circ.circ_lib() );
+                                       checkout.payload.circ.circ_staff( checkout.payload.noncat_circ.staff() );
+                                       checkout.payload.circ.usr( checkout.payload.noncat_circ.patron() );
+                       
+                                       JSAN.use('util.date');
+                                       var c = checkout.payload.noncat_circ.circ_time();
+                                       var d = c == "now" ? new Date() : util.date.db_date2Date( c );
+                                       var t =obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ];
+                                       var cd = t.circ_duration() || "14 days";
+                                       var i = util.date.interval_to_seconds( cd ) * 1000;
+                                       d.setTime( Date.parse(d) + i );
+                                       checkout.payload.circ.due_date( util.date.formatted_date(d,'%F') );
 
-                               if (!checkout.payload.record) {
-                                       checkout.payload.record = new mvr();
-                                       /*********************************************************************************************/
-                                       /* Non Cat */
-                                       if (checkout.payload.noncat_circ) {
-                                               checkout.payload.record.title(
-                                                       obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
-                                               );
-                                       }
                                }
+                       }
 
-                               if (!checkout.payload.copy) {
-                                       checkout.payload.copy = new acp();
-                                       checkout.payload.copy.barcode( '' );
+                       if (!checkout.payload.record) {
+                               checkout.payload.record = new mvr();
+                               /*********************************************************************************************/
+                               /* Non Cat */
+                               if (checkout.payload.noncat_circ) {
+                                       checkout.payload.record.title(
+                                               obj.data.hash.cnct[ checkout.payload.noncat_circ.item_type() ].name()
+                                       );
                                }
+                       }
 
-                               /*********************************************************************************************/
-                               /* Override mvr title/author with dummy title/author for Pre cat */
-                               if (checkout.payload.copy.dummy_title())  checkout.payload.record.title( checkout.payload.copy.dummy_title() );
-                               if (checkout.payload.copy.dummy_author())  checkout.payload.record.author( checkout.payload.copy.dummy_author() );
-
-                               obj.list.append(
-                                       {
-                                               'row' : {
-                                                       'my' : {
-                                                       'circ' : checkout.payload.circ,
-                                                       'mvr' : checkout.payload.record,
-                                                       'acp' : checkout.payload.copy
-                                                       }
+                       if (!checkout.payload.copy) {
+                               checkout.payload.copy = new acp();
+                               checkout.payload.copy.barcode( '' );
+                       }
+
+                       /*********************************************************************************************/
+                       /* Override mvr title/author with dummy title/author for Pre cat */
+                       if (checkout.payload.copy.dummy_title())  checkout.payload.record.title( checkout.payload.copy.dummy_title() );
+                       if (checkout.payload.copy.dummy_author())  checkout.payload.record.author( checkout.payload.copy.dummy_author() );
+
+                       obj.list.append(
+                               {
+                                       'row' : {
+                                               'my' : {
+                                               'circ' : checkout.payload.circ,
+                                               'mvr' : checkout.payload.record,
+                                               'acp' : checkout.payload.copy
                                                }
-                                       //I could override map_row_to_column here
                                        }
-                               );
-                               if (typeof obj.on_checkout == 'function') {
-                                       obj.on_checkout(checkout.payload);
-                               }
-                               if (typeof window.xulG == 'object' && typeof window.xulG.on_list_change == 'function') {
-                                       window.xulG.on_list_change(checkout.payload);
-                               } else {
-                                       obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
+                               //I could override map_row_to_column here
                                }
+                       );
+                       document.getElementById('msg_area').removeChild(x);
+                       /*
+                       if (typeof obj.on_checkout == 'function') {
+                               obj.on_checkout(checkout.payload);
+                       }
+                       */
+                       if (typeof window.xulG == 'object' && typeof window.xulG.on_list_change == 'function') {
+                               window.xulG.on_list_change(checkout.payload);
+                       } else {
+                               obj.error.sdump('D_CIRC','circ.checkout: No external .on_checkout()\n');
+                       }
 
                        } else {
                                throw(checkout);
                        }
+
+               } catch(E) {
+                       x.setAttribute('style','color: red');
+                       x.setAttribute('value',params.barcode + ' failed.');
+                       if (typeof params.noncat == 'undefined') obj.items_out_count--;
+                       obj.error.standard_unexpected_error_alert('Check Out Failed #3',E);
+               }
+       },
+
+       'checkout' : function(params) {
+               var obj = this;
+
+               try { obj.check_date(obj.controller.view.checkout_duedate_menu); } catch(E) { return; }
+               if (obj.controller.view.checkout_duedate_menu.value != 'Normal') {
+                       params.due_date = obj.controller.view.checkout_duedate_menu.value;
                }
 
+               if (typeof obj.on_checkout == 'function') { obj.on_checkout(params); }
+
+               if (! (params.barcode||params.noncat)) return;
+
+
                /**********************************************************************************************************************/
                /* Permissibility test before checkout */
                try {
@@ -394,7 +437,7 @@ circ.checkout.prototype = {
                        var permit = obj.network.request(
                                api.CHECKOUT_PERMIT.app,
                                api.CHECKOUT_PERMIT.method,
-                               [ ses(), params ],
+                               [ ses(), params, obj.items_out_count ],
                                null,
                                {
                                        'title' : 'Override Checkout Failure?',
@@ -449,7 +492,7 @@ circ.checkout.prototype = {
 
                                JSAN.use('util.sound'); var sound = new util.sound(); sound.circ_good();
                                params.permit_key = permit.payload;
-                               check_out( params );
+                               obj._checkout( params ); 
 
                        /**********************************************************************************************************************/
                        /* Item not cataloged or barcode mis-scan.  Prompt for pre-cat option */
@@ -479,7 +522,7 @@ circ.checkout.prototype = {
                                                params.dummy_author = obj.data.dummy_author;
                                                params.precat = 1;
 
-                                               if (params.dummy_title != '') { check_out( params ); } else { throw('Checkout cancelled'); }
+                                               if (params.dummy_title != '') { obj._checkout( params ); } else { throw('Checkout cancelled'); }
                                        } 
                                };
 
index 34a8789..e23a283 100644 (file)
@@ -17,6 +17,7 @@
        <groupbox id="cmgb1" flex="2">
                <caption label="&staff.patron_navbar.checkout;" />
                <hbox id="checkout_top_ui" />
+               <vbox id="msg_area" />
                <tree id="checkout_list" flex="1" enableColumnDrag="true"/>
                <hbox id="checkout_bottom_ui" />
        </groupbox>