From bcb3f7afbfd44af78fb3b28be2970db5d3301dc7 Mon Sep 17 00:00:00 2001 From: senator Date: Mon, 24 May 2010 16:04:42 +0000 Subject: [PATCH] Separate payment form code from the rest of the self check interface This will facilitate the borrowing of the same code for re-use in the OPAC, and potentially elsewhere. git-svn-id: svn://svn.open-ils.org/ILS/trunk@16486 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../web/js/ui/default/circ/selfcheck/payment.js | 115 ++++++++++++++++++ .../web/js/ui/default/circ/selfcheck/selfcheck.js | 128 ++------------------- .../web/templates/default/circ/selfcheck/main.tt2 | 1 + .../templates/default/circ/selfcheck/payment.tt2 | 4 +- 4 files changed, 128 insertions(+), 120 deletions(-) create mode 100644 Open-ILS/web/js/ui/default/circ/selfcheck/payment.js diff --git a/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js b/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js new file mode 100644 index 0000000000..a8cbbce485 --- /dev/null +++ b/Open-ILS/web/js/ui/default/circ/selfcheck/payment.js @@ -0,0 +1,115 @@ +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); + + dojo.query("span", "oils-selfck-cc-payment-summary")[0].innerHTML = total; + + oilsSelfckCCNumber.attr('value', ''); + oilsSelfckCCMonth.attr('value', '01'); + 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) { + oilsSelfckCCStreet.attr('value', addr.street1()+' '+addr.street2()); + oilsSelfckCCCity.attr('value', addr.city()); + oilsSelfckCCState.attr('value', addr.state()); + oilsSelfckCCZip.attr('value', addr.post_code()); + } + + dojo.connect(oilsSelfckEditDetails, 'onChange', + function(newVal) { + dojo.forEach( + [ oilsSelfckCCFName, + oilsSelfckCCLName, + oilsSelfckCCStreet, + oilsSelfckCCCity, + oilsSelfckCCState, + oilsSelfckCCZip + ], + function(dij) { dij.attr('disabled', !newVal); } + ); + } + ); + + + var self = this; + dojo.connect(oilsSelfckCCSubmit, 'onClick', + function() { + progressDialog.show(true); + self.sendCCPayment(onPaymentSubmit); + } + ); +} + +// In this form, this code only supports global on/off credit card +// payments and does not dissallow payments to transactions that started +// at remote locations or transactions that have accumulated billings at +// remote locations that dissalow credit card payments. +// TODO add per-transaction blocks for orgs that do not support CC payments + +proto.sendCCPayment = function(onPaymentSubmit) { + + var args = { + userid : this.patron.id(), + payment_type : 'credit_card_payment', + payments : [], + cc_args : { + where_process : 1, + number : oilsSelfckCCNumber.attr('value'), + expire_year : oilsSelfckCCYear.attr('value'), + expire_month : oilsSelfckCCMonth.attr('value'), + billing_first : oilsSelfckCCFName.attr('value'), + billing_last : oilsSelfckCCLName.attr('value'), + billing_address : oilsSelfckCCStreet.attr('value'), + billing_city : oilsSelfckCCCity.attr('value'), + billing_state : oilsSelfckCCState.attr('value'), + billing_zip : oilsSelfckCCZip.attr('value') + } + } + + + // 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(); + + var evt = openils.Event.parse(resp); + if (evt) + alert(evt); + else if (typeof(onPaymentSubmit) == "function") + onPaymentSubmit(); +} 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 e411485dba..61c2d0b091 100644 --- a/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js +++ b/Open-ILS/web/js/ui/default/circ/selfcheck/selfcheck.js @@ -100,7 +100,15 @@ SelfCheckManager.prototype.init = function() { var linkHandlers = { 'oils-selfck-hold-details-link' : function() { self.drawHoldsPage(); }, 'oils-selfck-view-fines-link' : function() { self.drawFinesPage(); }, - 'oils-selfck-pay-fines-link' : function() { self.drawPayFinesPage(); }, + 'oils-selfck-pay-fines-link' : function() { + self.goToTab("payment"); + self.drawPayFinesPage( + self.patron, function() { + self.updateFinesSummary(); + self.drawFinesPage(); + } + ); + }, 'oils-selfck-nav-home' : function() { self.drawCircPage(); }, 'oils-selfck-nav-logout' : function() { self.logoutPatron(); }, 'oils-selfck-nav-logout-print' : function() { self.logoutPatron(true); }, @@ -667,124 +675,6 @@ SelfCheckManager.prototype.drawHolds = function(holds) { } -SelfCheckManager.prototype.drawPayFinesPage = function() { - this.goToTab('payment'); - - // 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); - - dojo.byId('oils-selfck-cc-payment-summary').innerHTML = - dojo.string.substitute( - localeStrings.CC_PAYABLE_BALANCE, - [total] - ); - - oilsSelfckCCNumber.attr('value', ''); - oilsSelfckCCMonth.attr('value', '01'); - oilsSelfckCCYear.attr('value', new Date().getFullYear()); - oilsSelfckCCFName.attr('value', this.patron.first_given_name()); - oilsSelfckCCLName.attr('value', this.patron.family_name()); - var addr = this.patron.billing_address() || this.patron.mailing_address(); - - if(addr) { - oilsSelfckCCStreet.attr('value', addr.street1()+' '+addr.street2()); - oilsSelfckCCCity.attr('value', addr.city()); - oilsSelfckCCState.attr('value', addr.state()); - oilsSelfckCCZip.attr('value', addr.post_code()); - } - - dojo.connect(oilsSelfckEditDetails, 'onChange', - function(newVal) { - dojo.forEach( - [ oilsSelfckCCFName, - oilsSelfckCCLName, - oilsSelfckCCStreet, - oilsSelfckCCCity, - oilsSelfckCCState, - oilsSelfckCCZip - ], - function(dij) { dij.attr('disabled', !newVal); } - ); - } - ); - - - var self = this; - dojo.connect(oilsSelfckCCSubmit, 'onClick', - function() { - progressDialog.show(true); - self.sendCCPayment(); - } - ); -} - - -// In this form, this code only supports global on/off credit card -// payments and does not dissallow payments to transactions that started -// at remote locations or transactions that have accumulated billings at -// remote locations that dissalow credit card payments. -// TODO add per-transaction blocks for orgs that do not support CC payments - -SelfCheckManager.prototype.sendCCPayment = function() { - - var args = { - userid : this.patron.id(), - payment_type : 'credit_card_payment', - payments : [], - cc_args : { - where_process : 1, - number : oilsSelfckCCNumber.attr('value'), - expire_year : oilsSelfckCCYear.attr('value'), - expire_month : oilsSelfckCCMonth.attr('value'), - billing_first : oilsSelfckCCFName.attr('value'), - billing_last : oilsSelfckCCLName.attr('value'), - billing_address : oilsSelfckCCStreet.attr('value'), - billing_city : oilsSelfckCCCity.attr('value'), - billing_state : oilsSelfckCCState.attr('value'), - billing_zip : oilsSelfckCCZip.attr('value') - } - } - - - // 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(); - - var evt = openils.Event.parse(resp); - if(evt) { - alert(evt); - } else { - this.updateFinesSummary(); - this.drawFinesPage(); - } -} - - SelfCheckManager.prototype.drawFinesPage = function() { // TODO add option to hid scanBox diff --git a/Open-ILS/web/templates/default/circ/selfcheck/main.tt2 b/Open-ILS/web/templates/default/circ/selfcheck/main.tt2 index 23574ab025..7ce03842dd 100644 --- a/Open-ILS/web/templates/default/circ/selfcheck/main.tt2 +++ b/Open-ILS/web/templates/default/circ/selfcheck/main.tt2 @@ -1,6 +1,7 @@ [% ctx.page_title = 'Self Checkout' %] [% WRAPPER default/base.tt2 %] + [% INCLUDE 'default/circ/selfcheck/audio_config.tt2' %] diff --git a/Open-ILS/web/templates/default/circ/selfcheck/payment.tt2 b/Open-ILS/web/templates/default/circ/selfcheck/payment.tt2 index e34958c198..616020efe2 100644 --- a/Open-ILS/web/templates/default/circ/selfcheck/payment.tt2 +++ b/Open-ILS/web/templates/default/circ/selfcheck/payment.tt2 @@ -1,4 +1,6 @@ -
+
+ Total amount to pay: $ +
-- 2.11.0