selfcheck checkin
authorBill Erickson <berick@esilibrary.com>
Fri, 1 Feb 2013 20:50:29 +0000 (15:50 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 1 Feb 2013 20:50:29 +0000 (15:50 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/templates/circ/selfcheck/checkin_page.tt2 [new file with mode: 0644]
Open-ILS/src/templates/circ/selfcheck/main.tt2
Open-ILS/src/templates/circ/selfcheck/summary.tt2
Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js

diff --git a/Open-ILS/src/templates/circ/selfcheck/checkin_page.tt2 b/Open-ILS/src/templates/circ/selfcheck/checkin_page.tt2
new file mode 100644 (file)
index 0000000..ade3d0a
--- /dev/null
@@ -0,0 +1,25 @@
+<div id='oils-selfck-checkin-table-div'>
+    <table id='oils-selfck-checkin-table' class='oils-selfck-item-table'>
+        <thead>
+            <tr>
+                <td id='oils-self-checkin-pic-cell'></td>
+                <td>[% l('Barcode') %]</td>
+                <td>[% l('Title') %]</td>
+                <td>[% l('Author') %]</td>
+                <td>[% l('Due Date') %]</td>
+                <td>[% l('Renewals Left') %]</td>
+            </tr>
+        </thead>
+        <tbody id='oils-selfck-checkin-tbody'>
+            <tr id='oils-selfck-checkin-row'>
+                <td><img class='oils-selfck-jacket' name='jacket'/></td>
+                <td name='barcode'></td>
+                <td name='title'></td>
+                <td name='author'></td>
+                <td name='due_date'></td>
+                <td name='remaining'></td>
+            </tr>
+        </tbody>
+        <tbody id='oils-selfck-checkin-out-tbody' class='oils-selfck-item-table'></tbody>
+    </table>
+</div>
index 42aaf49..5b3e19d 100644 (file)
             <!-- Checkout / renewal and items out interface -->
             [% INCLUDE 'circ/selfcheck/circ_page.tt2' %]
         </div>
+        <div id='oils-selfck-checkin-page' class='hidden'>
+            <!-- Checkin interface; Staff only -->
+            [% INCLUDE 'circ/selfcheck/checkin_page.tt2' %]
+        </div>
         <div id='oils-selfck-holds-page' class='hidden'>
             <!-- Patron holds interface -->
             [% INCLUDE 'circ/selfcheck/holds_page.tt2' %]
index 652815c..c67f23a 100644 (file)
@@ -1,6 +1,7 @@
 <div id='oils-selfck-circ-info-div'>
     <div id='oils-selfck-info-nav'>
         <span><a id='oils-selfck-nav-home' href='javascript:void(0);' class='selected'>[% l('Home') %]</a></span>
+        <span class='hidden'><a id='oils-selfck-nav-checkin' href='javascript:void(0);'>[% l('Checkin') %]</a></span>
         <span><a id='oils-selfck-nav-logout-print' href='javascript:void(0);'>[% l('Logout') %]</a></span>
         <span><a id='oils-selfck-nav-logout' href='javascript:void(0);'>[% l('Logout (No Receipt)') %]</a></span>
     </div>
index 0b47be3..5feb557 100644 (file)
@@ -56,6 +56,9 @@ function SelfCheckManager() {
     // dict of org unit settings for "here"
     this.orgSettings = {};
 
+    // true if we are exposing staff-only features (e.g. checkin)
+    this.staffMode = false;
+
     // Construct a mock checkout for debugging purposes
     if(this.mockCheckouts = this.cgi.param('mock-circ')) {
 
@@ -93,12 +96,28 @@ SelfCheckManager.prototype.setupStaffLogin = function(verify) {
  * Fetch the org-unit settings, initialize the display, etc.
  */
 SelfCheckManager.prototype.init = function() {
+    var self = this;
 
     this.setupStaffLogin();
     this.loadOrgSettings();
 
+    // are we in staff mode?
+    new openils.User().getPermOrgList(['SELFCHECK_FULL_THROTTLE'], 
+        function(orglist) {
+            if (orglist.length) {
+                self.staffMode = true;
+                openils.Util.show(
+                    dojo.byId('oils-selfck-nav-checkin').parentNode, 
+                    'inline'
+                );
+            }
+        }
+    );
+
     this.circTbody = dojo.byId('oils-selfck-circ-tbody');
+    this.checkinTbody = dojo.byId('oils-selfck-checkin-tbody');
     this.itemsOutTbody = dojo.byId('oils-selfck-circ-out-tbody');
+    this.itemsCheckinTbody = dojo.byId('oils-selfck-checkin-out-tbody');
 
     // workstation is required but none provided
     if(this.orgSettings[SET_WORKSTATION_REQUIRED] && !this.workstation) {
@@ -108,7 +127,6 @@ SelfCheckManager.prototype.init = function() {
         return;
     }
     
-    var self = this;
     // connect onclick handlers to the various navigation links
     var linkHandlers = {
         'oils-selfck-hold-details-link' : function() { self.drawHoldsPage(); },
@@ -143,6 +161,7 @@ SelfCheckManager.prototype.init = function() {
             );
         },
         'oils-selfck-nav-home' : function() { self.drawCircPage(); },
+        'oils-selfck-nav-checkin' : function() { self.drawCheckinPage(); },
         'oils-selfck-nav-logout' : function() { self.logoutPatron(); },
         'oils-selfck-nav-logout-print' : function() { self.logoutPatron(true); },
         'oils-selfck-items-out-details-link' : function() { self.drawItemsOutPage(); },
@@ -502,6 +521,76 @@ SelfCheckManager.prototype.drawCircPage = function() {
     }
 }
 
+/**
+ * Sets up the checkin page
+ */
+SelfCheckManager.prototype.drawCheckinPage = function() {
+    openils.Util.show('oils-selfck-checkin-tbody', 'table-row-group');
+    this.goToTab('checkin');
+
+    while(this.itemsCheckinTbody.childNodes[0])
+        this.itemsCheckinTbody.removeChild(
+            this.itemsCheckinTbody.childNodes[0]);
+
+    if(!this.checkinTemplate) {
+        this.checkinTemplate = 
+            this.checkinTbody.removeChild(
+                dojo.byId('oils-selfck-checkin-row'));
+    }
+
+    var self = this;
+    this.updateScanBox({
+        msg : 'Please enter an item barcode', // TODO i18n
+        handler : function(barcode) { self.checkin(barcode); }
+    });
+};
+
+
+SelfCheckManager.prototype.checkin = function(barcode) {
+    var self = this;
+
+    var checkinHandler = function(evt) {
+        if(!evt.length) evt = [evt];
+
+        for(var i = 0; i < evt.length; i++) {
+            var tc = evt.textcode;
+            console.log('checkin returned ' + tc);
+
+            switch (tc) {
+                case 'SUCCESS':
+                case 'NO_CHANGE':
+                    continue;
+                    break;
+                default:
+                    self.handleAlert(
+                        // TODO: i18n
+                        'Unhandled checkin event for "' + 
+                            barcode + '"\n' + evt.toString(),
+                        true, 'checkin-failure'
+                    );
+            }
+        }
+
+
+        // TODO checkin would be faster if these were
+        // not updated in real time w/ each checkin
+
+        // fines summary
+        self.updateFinesSummary();
+
+        // holds summary
+        self.updateHoldsSummary();
+
+        // items out summary
+        self.updateCircSummary();
+    };
+
+    this.checkinCopy({
+        barcode : barcode, 
+        onload : checkinHandler
+    });
+};
+
 
 SelfCheckManager.prototype.updateFinesSummary = function() {
     var self = this; 
@@ -582,12 +671,16 @@ SelfCheckManager.prototype.goToTab = function(name) {
     openils.Util.hide('oils-selfck-payment-page');
     openils.Util.hide('oils-selfck-holds-page');
     openils.Util.hide('oils-selfck-circ-page');
+    openils.Util.hide('oils-selfck-checkin-page');
     openils.Util.hide('oils-selfck-pay-fines-link');
     
     switch(name) {
         case 'checkout':
             openils.Util.show('oils-selfck-circ-page');
             break;
+        case 'checkin':
+            openils.Util.show('oils-selfck-checkin-page');
+            break;
         case 'items_out':
             openils.Util.show('oils-selfck-circ-page');
             break;
@@ -869,16 +962,41 @@ SelfCheckManager.prototype.drawFinesPage = function() {
     );
 }
 
-SelfCheckManager.prototype.checkin = function(barcode, abortTransit) {
-
-    var resp = fieldmapper.standardRequest(
-        ['open-ils.circ', 'open-ils.circ.transit.abort'],
-        {params : [this.authtoken, {barcode : barcode}]}
+/** top-level checkin handler */
+SelfCheckManager.prototype.checkinCopy = function(args) {
+    fieldmapper.standardRequest(
+        ['open-ils.circ', 'open-ils.circ.checkin.override'],
+        {   async : true,
+            params : [
+                this.authtoken, {
+                    patron_id : this.patron.id(),
+                    copy_barcode : args.barcode,
+                    // TODO
+                    // amnesty
+                    // backdate
+                }
+            ],
+            oncomplete : function(r) {
+                var resp = openils.Util.readResponse(r, true);
+                args.onload(resp);
+            }
+        }
     );
+};
 
-    // resp == 1 on success
-    if(openils.Event.parse(resp))
-        return false;
+/** used for checkins required to fullfil a checkout */
+SelfCheckManager.prototype.inlineCheckinCopy = function(barcode, abortTransit) {
+
+    if (abortTransit) {
+        var resp = fieldmapper.standardRequest(
+            ['open-ils.circ', 'open-ils.circ.transit.abort'],
+            {params : [this.authtoken, {barcode : barcode}]}
+        );
+    
+        // resp == 1 on success
+        if(openils.Event.parse(resp))
+            return false;
+    }
 
     var resp = fieldmapper.standardRequest(
         ['open-ils.circ', 'open-ils.circ.checkin.override'],
@@ -891,6 +1009,8 @@ SelfCheckManager.prototype.checkin = function(barcode, abortTransit) {
         ]}
     );
 
+    // TODO: staffMode : handle/report events better
+    
     if(!resp.length) resp = [resp];
     for(var i = 0; i < resp.length; i++) {
         var tc = openils.Event.parse(resp[i]).textcode;
@@ -1037,7 +1157,7 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
                 overrideEvents && overrideEvents.length &&
                 overrideEvents.indexOf('COPY_STATUS_LOST') != -1) {
 
-                    if(this.checkin(item)) {
+                    if(this.inlineCheckinCopy(item)) {
                         return { doOver : true };
                     }
             }
@@ -1086,7 +1206,7 @@ SelfCheckManager.prototype.handleXactResult = function(action, item, result) {
 
                 if(result[i].textcode == 'COPY_IN_TRANSIT') {
                     // to override a transit, we have to abort the transit and check it in first
-                    if(this.checkin(item, true)) {
+                    if(this.inlineCheckinCopy(item, true)) {
                         return { doOver : true };
                     } else {
                         override = false;