LP#1356477: update selfcheck interface
authorMike Rylander <mrylander@gmail.com>
Thu, 4 Aug 2016 14:38:48 +0000 (10:38 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 24 Aug 2016 21:58:52 +0000 (17:58 -0400)
This patch replaces the Logout and Logout with Receipt buttons in
the selfcheck interface with a single Logout button and a set of radio
buttons (whose labels are clickable) that allow the user to specify
whether they want an email receipt, a print receipt, or no receipt upon
logging out.

If the user has no email address, the option to select email receipts
will not be presented to them.

Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/templates/circ/selfcheck/summary.tt2
Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js

index 237c345..7b1487c 100644 (file)
@@ -1,8 +1,13 @@
 <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'><button type="button" class="self-button">[% l('Home') %]</button></a></span>
-        <span><a id='oils-selfck-nav-logout-print' href='javascript:void(0);'><button type="button" class="self-button">[% l('Logout') %]</button></a></span>
-        <span><a id='oils-selfck-nav-logout' href='javascript:void(0);'><button type="button" class="self-button">[% l('Logout (No Receipt)') %]</button></a></span>
+        <span><a id='oils-selfck-nav-logout' href='javascript:void(0);'><button type="button" class="self-button">[% l('Logout') %]</button></a></span>
+    </div>
+    <div id='oils-selfck-info-nav'>
+        <span for='oils-selfck-nav-receipt'>[% l('Receipt:') %] </span>
+        <span class="hidden"><input type="radio" name="receipt_type" id='oils-selfck-receipt-email' value="email"/><label for="oils-selfck-receipt-email"> [% l('Email') %]</label></span>
+        <span><input type="radio" name="receipt_type" id='oils-selfck-receipt-print' value="email" checked/><label for="oils-selfck-receipt-print"> [% l('Print') %]</label></span>
+        <span><input type="radio" name="receipt_type" id='oils-selfck-receipt-none' value="email"/><label for="oils-selfck-receipt-none"> [% l('None') %]</label></span>
     </div>
     <fieldset>
         <legend>[% l('Items Checked Out') %]</legend>
index 03f9dfa..3959fbc 100644 (file)
@@ -202,8 +202,7 @@ SelfCheckManager.prototype.init = function() {
             );
         },
         'oils-selfck-nav-home' : function() { self.drawCircPage(); },
-        'oils-selfck-nav-logout' : function() { self.logoutPatron(); },
-        'oils-selfck-nav-logout-print' : function() { self.logoutPatron(true); },
+        'oils-selfck-nav-logout' : function() { self.logoutPatron(true); },
         'oils-selfck-items-out-details-link' : function() { self.drawItemsOutPage(); },
         'oils-selfck-print-list-link' : function() { self.printList(); }
     }
@@ -466,10 +465,28 @@ SelfCheckManager.prototype.fetchPatron = function(barcode, usrname) {
         this.handleAlert('', false, 'login-success');
         dojo.byId('oils-selfck-user-banner').innerHTML = 
             dojo.string.substitute(localeStrings.WELCOME_BANNER, [this.patron.first_given_name()]);
+
+        if (this.patron.email() && // they have an email address set and ...
+            this.patron.email().match(/.*@.*/).length > 0 // it sorta looks like an email address
+        ) {
+            openils.Util.removeCSSClass( dojo.byId('oils-selfck-receipt-email').parentNode, 'hidden' );
+            if (user_setting_value(this.patron, 'circ.send_email_checkout_receipts') == 'true') // their selected default
+                dojo.byId('oils-selfck-receipt-email').checked = true;
+        }
+
         this.drawCircPage();
     }
 }
 
+function user_setting_value (user, setting) {
+    if (user) {
+        var list = user.settings().filter(function(s){
+            return s.name() == setting;
+        });
+
+        if (list.length) return list[0].value();
+    }
+}
 
 SelfCheckManager.prototype.handleAlert = function(message, shouldPopup, sound) {
 
@@ -1311,6 +1328,40 @@ SelfCheckManager.prototype.initPrinter = function() {
 }
 
 /**
+ * Email a receipt for this session's checkouts
+ */
+SelfCheckManager.prototype.emailSessionReceipt = function(callback) {
+
+    var circIds = [];
+
+    // collect the circs and failure info
+    dojo.forEach(
+        this.checkouts, 
+        function(blob) {
+            circIds.push(blob.circ);
+        }
+    );
+
+    var params = [
+        this.authtoken, 
+        this.patron.id(),
+        circIds
+    ];
+
+    var self = this;
+    fieldmapper.standardRequest(
+        ['open-ils.circ', 'open-ils.circ.checkout.batch_notify.session.atomic'],
+        {   
+            async : true,
+            params : params,
+            oncomplete : function() {
+                if (callback) callback(); // fire and forget
+            }
+        }
+    );
+}
+
+/**
  * Print a receipt for this session's checkouts
  */
 SelfCheckManager.prototype.printSessionReceipt = function(callback) {
@@ -1388,6 +1439,7 @@ SelfCheckManager.prototype.printData = function(data, numItems, callback) {
 }
 
 
+
 /**
  * Print a receipt for this user's items out
  */
@@ -1585,11 +1637,22 @@ SelfCheckManager.prototype.printFinesReceipt = function(callback) {
 SelfCheckManager.prototype.logoutPatron = function(print) {
     progressDialog.show(true); // prevent patron from clicking logout link twice
     if(print && this.checkouts.length) {
-        this.printSessionReceipt(
-            function() {
-                location.href = location.href;
-            }
-        );
+        if (dojo.byId('oils-selfck-receipt-print').checked) {
+            this.printSessionReceipt(
+                function() {
+                    location.href = location.href;
+                }
+            );
+        } else if (dojo.byId('oils-selfck-receipt-email').checked) {
+            this.emailSessionReceipt(
+                function() {
+                    location.href = location.href;
+                }
+            );
+        } else {
+            // user elected to get no receipt
+            location.href = location.href;
+        }
     } else {
         location.href = location.href;
     }