From 21e950e7bf338aff70b83806ea6cb4b459b7c76e Mon Sep 17 00:00:00 2001 From: senator Date: Tue, 1 Jun 2010 15:59:25 +0000 Subject: [PATCH] Incorporate CC payment interface into OPAC fines page (rough) git-svn-id: svn://svn.open-ils.org/ILS/trunk@16542 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/ui/default/circ/selfcheck/payment.js | 87 ++++++++++------------ .../web/js/ui/default/circ/selfcheck/selfcheck.js | 30 +++++++- Open-ILS/web/opac/skin/default/js/myopac.js | 51 ++++++++++++- .../web/opac/skin/default/xml/common/js_common.xml | 7 +- .../opac/skin/default/xml/myopac/myopac_fines.xml | 10 ++- 5 files changed, 133 insertions(+), 52 deletions(-) diff --git a/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js b/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js index bfceb904e8..0f2d2f6a85 100644 --- a/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js +++ b/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js @@ -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); } diff --git a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js index 7075c575b4..4df1595b61 100644 --- a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js +++ b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js @@ -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 */ diff --git a/Open-ILS/web/opac/skin/default/js/myopac.js b/Open-ILS/web/opac/skin/default/js/myopac.js index db04a34a25..42cdb1ae41 100644 --- a/Open-ILS/web/opac/skin/default/js/myopac.js +++ b/Open-ILS/web/opac/skin/default/js/myopac.js @@ -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; diff --git a/Open-ILS/web/opac/skin/default/xml/common/js_common.xml b/Open-ILS/web/opac/skin/default/xml/common/js_common.xml index fa20116129..b6f4f5582b 100644 --- a/Open-ILS/web/opac/skin/default/xml/common/js_common.xml +++ b/Open-ILS/web/opac/skin/default/xml/common/js_common.xml @@ -57,15 +57,20 @@ - + + diff --git a/Open-ILS/web/opac/skin/default/xml/myopac/myopac_fines.xml b/Open-ILS/web/opac/skin/default/xml/myopac/myopac_fines.xml index db129c0162..8f99c5aa50 100644 --- a/Open-ILS/web/opac/skin/default/xml/myopac/myopac_fines.xml +++ b/Open-ILS/web/opac/skin/default/xml/myopac/myopac_fines.xml @@ -17,7 +17,14 @@ &common.currency; &common.currency; - &common.currency; + + &common.currency; +   + [ Pay this online + Cancel payment ] + + @@ -30,6 +37,7 @@ --> +
-- 2.11.0