-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;
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());
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);
}
);
}
// 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'),
}
}
-
- // 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);
}
'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();
}
}
+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
*/
var allowPendingAddr = false;
var myopacEnableRefWorks = false;
var myopacRefWorksHost = 'http://www.refworks.com';
+var paymentForm = new PaymentForm();
function clearNodes( node, keepArray ) {
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) {
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 ) {
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;
<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>
<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">
+ [ <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>
</div>
-->
+ <div id="myopac_payment_div"></div>
<!-- Table for circulation transactions only -->
<div id='myopac_circ_trans_div' class='hide_me'>