Incorporate CC payment interface into OPAC fines page (rough)
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 1 Jun 2010 15:59:25 +0000 (15:59 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Tue, 1 Jun 2010 15:59:25 +0000 (15:59 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@16542 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/ui/default/circ/selfcheck/payment.js
Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js
Open-ILS/web/opac/skin/default/js/myopac.js
Open-ILS/web/opac/skin/default/xml/common/js_common.xml
Open-ILS/web/opac/skin/default/xml/myopac/myopac_fines.xml

index bfceb90..0f2d2f6 100644 (file)
@@ -1,22 +1,10 @@
-var proto = (
-    (typeof(SelfCheckManager) == "undefined") ?
-        (function PaymentForm() {}) : SelfCheckManager
-).prototype;
-
-proto.drawPayFinesPage = function(patron, onPaymentSubmit) {
-    if (!this.finesTBody)
-        this.finesTBody = dojo.byId("oils-selfck-fines-tbody");
-
-    // find the total selected amount
-    var total = 0;
-    dojo.forEach(
-        dojo.query('[name=selector]', this.finesTbody),
-        function(input) {
-            if(input.checked)
-                total += Number(input.getAttribute('balance_owed'));
-        }
-    );
-    total = total.toFixed(2);
+function PaymentForm() {}
+var proto = (typeof(SelfCheckManager) == "undefined" ?
+    PaymentForm : SelfCheckManager).prototype;
+
+proto.drawPayFinesPage = function(patron, total, xacts, onPaymentSubmit) {
+    if (typeof(this.authtoken) == "undefined")
+        this.authtoken = patron.session;
 
     dojo.query("span", "oils-selfck-cc-payment-summary")[0].innerHTML = total;
 
@@ -26,9 +14,29 @@ proto.drawPayFinesPage = function(patron, onPaymentSubmit) {
     oilsSelfckCCYear.attr('value', new Date().getFullYear());
     oilsSelfckCCFName.attr('value', patron.first_given_name());
     oilsSelfckCCLName.attr('value', patron.family_name());
+
     var addr = patron.billing_address() || patron.mailing_address();
 
-    if(addr) {
+    if (typeof(addr) != "object") {
+        /* still don't have usable address? try getting better user object. */
+        fieldmapper.standardRequest(
+            ["open-ils.actor", "open-ils.actor.user.fleshed.retrieve"], {
+                "params": [
+                    patron.session, patron.id(), [
+                        "billing_address", "mailing_address"
+                    ]
+                ],
+                "async": false,
+                "oncomplete": function(r) {
+                    var usr = openils.Util.readResponse(r);
+                    if (usr)
+                        addr = usr.billing_address() || usr.mailing_address();
+                }
+            }
+        );
+    }
+
+    if (addr) {
         oilsSelfckCCStreet.attr('value', addr.street1()+' '+addr.street2());
         oilsSelfckCCCity.attr('value', addr.city());
         oilsSelfckCCState.attr('value', addr.state());
@@ -54,8 +62,12 @@ proto.drawPayFinesPage = function(patron, onPaymentSubmit) {
     var self = this;
     dojo.connect(oilsSelfckCCSubmit, 'onClick',
         function() {
-            progressDialog.show(true);
-            self.sendCCPayment(onPaymentSubmit);
+            /* XXX better to replace this check on progressDialog with some
+             * kind of passed-in function to support different use cases */
+            if (typeof(progressDialog) != "undefined")
+                progressDialog.show(true);
+
+            self.sendCCPayment(patron, xacts, onPaymentSubmit);
         }
     );
 }
@@ -66,12 +78,12 @@ proto.drawPayFinesPage = function(patron, onPaymentSubmit) {
 // remote locations that dissalow credit card payments.
 // TODO add per-transaction blocks for orgs that do not support CC payments
 
-proto.sendCCPayment = function(onPaymentSubmit) {
+proto.sendCCPayment = function(patron, xacts, onPaymentSubmit) {
 
     var args = {
-        userid : this.patron.id(),
+        userid : patron.id(),
         payment_type : 'credit_card_payment',
-        payments : [],
+        payments : xacts,
         cc_args : {
             where_process : 1,
             number : oilsSelfckCCNumber.attr('value'),
@@ -87,31 +99,14 @@ proto.sendCCPayment = function(onPaymentSubmit) {
         }
     }
 
-
-    // find the selected transactions
-    dojo.forEach(
-        dojo.query('[name=selector]', this.finesTbody),
-        function(input) {
-            if(input.checked) {
-                args.payments.push([
-                    input.getAttribute('xact'),
-                    Number(input.getAttribute('balance_owed')).toFixed(2)
-                ]);
-            }
-        }
-    );
-
-
     var resp = fieldmapper.standardRequest(
         ['open-ils.circ', 'open-ils.circ.money.payment'],
         {params : [this.authtoken, args]}
     );
 
-    progressDialog.hide();
+    if (typeof(progressDialog) != "undefined")
+        progressDialog.hide();
 
-    var evt = openils.Event.parse(resp);
-    if (evt)
-        alert(evt);
-    else if (typeof(onPaymentSubmit) == "function")
-        onPaymentSubmit();
+    if (typeof(onPaymentSubmit) == "function")
+        onPaymentSubmit(resp);
 }
index 7075c57..4df1595 100644 (file)
@@ -103,7 +103,10 @@ SelfCheckManager.prototype.init = function() {
         'oils-selfck-pay-fines-link' : function() {
             self.goToTab("payment");
             self.drawPayFinesPage(
-                self.patron, function() {
+                self.patron,
+                self.getSelectedFinesTotal(),
+                self.getSelectedFineTransactions(),
+                function() {
                     self.updateFinesSummary();
                     self.drawFinesPage();
                 }
@@ -143,6 +146,31 @@ SelfCheckManager.prototype.init = function() {
 }
 
 
+SelfCheckManager.prototype.getSelectedFinesTotal = function() {
+    var total = 0;
+    dojo.forEach(
+        dojo.query("[name=selector]", this.finesTbody),
+        function(input) {
+            if(input.checked)
+                total += Number(input.getAttribute("balance_owed"));
+        }
+    );
+    return total.toFixed(2);
+};
+
+SelfCheckManager.prototype.getSelectedFineTransactions = function() {
+    return dojo.query("[name=selector]", this.finesTbody).
+        filter(function (o) { return o.checked }).
+        map(
+            function (o) {
+                return [
+                    o.getAttribute("xact"),
+                    Number(o.getAttribute("balance_owed")).toFixed(2)
+                ];
+            }
+        );
+};
+
 /**
  * Registers a new workstion
  */
index db04a34..42cdb1a 100644 (file)
@@ -10,6 +10,7 @@ var holdStatusCache = {};
 var allowPendingAddr = false;
 var myopacEnableRefWorks = false;
 var myopacRefWorksHost = 'http://www.refworks.com';
+var paymentForm = new PaymentForm();
 
 
 function clearNodes( node, keepArray ) {
@@ -567,13 +568,52 @@ function _myOPACShowFines(r) {
                balance = _finesFormatNumber(summary.balance_owed());
 
                var req = new Request(FETCH_TRANSACTIONS, G.user.session, G.user.id() );
-               req.callback(myOPACShowTransactions);
+               req.callback(function(r) { myOPACShowTransactions(r, balance); });
                req.send();
        }
 
        $('myopac_fines_summary_total').appendChild(text(total));
        $('myopac_fines_summary_paid').appendChild(text(paid));
-       $('myopac_fines_summary_balance').appendChild(text(balance));
+       $("myopac_fines_summary_balance").appendChild(text(balance));
+
+}
+
+function preparePaymentForm(balance, transactions) {
+       if (Number(balance) > 0) {
+               var cxl_link = $("myopac_fines_payment_cancel_link");
+               var pay_link = $("myopac_fines_payment_link");
+
+               cxl_link.onclick = function() {
+                       hideMe(cxl_link);
+                       unHideMe(pay_link);
+                       unHideMe($("myopac_circ_trans_div"));
+                       $("myopac_payment_div").innerHTML = "";
+               };
+               pay_link.onclick = function() {
+                       dojo.xhrGet({
+                               "url": "/eg/circ/selfcheck/payment",
+                               "load": function(resp) {
+                                       hideMe($("myopac_circ_trans_div"));
+                                       $("myopac_payment_div").innerHTML = resp;
+                                       dojo.parser.parse($("myopac_payment_div"));
+                                       paymentForm.drawPayFinesPage(
+                                               G.user, balance, dojo.map(
+                                                       transactions, function(t) {
+                                                               return [t.id(), Number(t.balance_owed()).toFixed(2)];
+                                                       }
+                                               ),
+                                               function() { alert("Payment registered"); /* LFW XXX */ }
+                                       );
+                                       hideMe(pay_link);
+                                       unHideMe(cxl_link);
+                               },
+                               "error": function(e) {
+                                       alert("Error preparing payment form: " + e); // XXX i18n; user-friendliness
+                               }
+                       });
+               };
+               unHideMe($("myopac_fines_payment"));
+       }
 }
 
 function _finesFormatNumber(num) {
@@ -600,11 +640,12 @@ function _trimSeconds(time) {
     return d.iso8601Format('YMDHM',null,true,true);
 }
 
-function myOPACShowTransactions(r) {
+function myOPACShowTransactions(r, balance) {
 
        if(myopacGenericTransTemplate || myopacCircTransTemplate) return;
 
        var transactions = r.getResultObject();
+       var payment_xacts = [];
 
        for( var idx in transactions ) {
 
@@ -618,12 +659,16 @@ function myOPACShowTransactions(r) {
                else if(trans.xact_type() == 'grocery' ) 
                        myopacShowGenericTransaction( trans );
 
+               payment_xacts.push(trans);
+
 /*      XXX need to copy circulation output function here
                else if(trans.xact_type() == 'reservation' ) 
                        myopacShowReservationTransaction( trans );
 */
 
        }
+
+       preparePaymentForm(balance, payment_xacts);
 }
 
 var myopacGenericTransTemplate;
index fa20116..b6f4f55 100644 (file)
 
        <script type="text/javascript" src='/js/dojo/dojo/dojo.js'></script>
        <script type="text/javascript" src='/js/dojo/dojo/openils_dojo.js'></script>
-    <script type="text/javascript" src='/js/dojo/opensrf/opensrf.js'></script>
+       <script type="text/javascript" src='/js/dojo/opensrf/opensrf.js'></script>
+       <script type="text/javascript" src="/js/ui/default/circ/selfcheck/payment.js"></script>
 
        <script language="javascript" type="text/javascript">
                dojo.addOnLoad(init);
                dojo.require("dijit._Calendar");
                dojo.require("dijit.form.DateTextBox");
+               dojo.require("dijit.form.NumberSpinner");
+               dojo.require("dijit.form.CheckBox");
+               dojo.require("dijit.form.TextBox");
                dojo.require("dijit.form.FilteringSelect");
                dojo.require("dojo.date.locale");
                dojo.require("dojo.date.stamp");
                dojo.require("dojo.parser");
                dojo.require("openils.I18N");
+               dojo.require("openils.Util");
        </script>
index db129c0..8f99c5a 100644 (file)
                        <tr id='myopac_fines_summary_row' class='hide_me'>
                                <td id='myopac_fines_summary_total' >&common.currency;</td>
                                <td id='myopac_fines_summary_paid' >&common.currency;</td>
-                               <td id='myopac_fines_summary_balance' style='color:red;font-weight: bold;'>&common.currency;</td>
+                                        <td style="color:red;font-weight: bold;">
+                                               &common.currency;<span
+                                                       id="myopac_fines_summary_balance"></span>
+                                               <span class="hide_me" id="myopac_fines_payment"> &nbsp;
+                                                       [ <a id="myopac_fines_payment_link" href="javascript:void(0);">Pay this online</a>
+                                                       <a id="myopac_fines_payment_cancel_link" href="javascript:void(0);" class="hide_me">Cancel payment</a> ]
+                                       </span>
+                               </td>
                        </tr>
                </tbody>
        </table>
@@ -30,6 +37,7 @@
        </div>
        -->
 
+       <div id="myopac_payment_div"></div>
 
        <!-- Table for circulation transactions only -->
        <div id='myopac_circ_trans_div' class='hide_me'>