avoid multiple clicks of selfcheck logout link
[Evergreen.git] / Open-ILS / web / js / ui / default / circ / selfcheck / payment.js
1 function PaymentForm() {}
2 var proto = (typeof(SelfCheckManager) == "undefined" ?
3     PaymentForm : SelfCheckManager).prototype;
4
5 proto.drawPayFinesPage = function(patron, total, xacts, onPaymentSubmit) {
6     if (typeof(this.authtoken) == "undefined")
7         this.authtoken = patron.session;
8
9     dojo.query("span", "oils-selfck-cc-payment-summary")[0].innerHTML = total;
10
11     oilsSelfckCCNumber.attr('value', '');
12     oilsSelfckCCCVV.attr('value', '');
13     oilsSelfckCCMonth.attr('value', '01');
14     oilsSelfckCCYear.attr('value', new Date().getFullYear());
15     oilsSelfckCCFName.attr('value', patron.first_given_name());
16     oilsSelfckCCLName.attr('value', patron.family_name());
17
18     var addr = patron.billing_address() || patron.mailing_address();
19
20     if (typeof(addr) != "object") {
21         /* still don't have usable address? try getting better user object. */
22         fieldmapper.standardRequest(
23             ["open-ils.actor", "open-ils.actor.user.fleshed.retrieve"], {
24                 "params": [
25                     patron.session, patron.id(), [
26                         "billing_address", "mailing_address"
27                     ]
28                 ],
29                 "async": false,
30                 "oncomplete": function(r) {
31                     var usr = openils.Util.readResponse(r);
32                     if (usr)
33                         addr = usr.billing_address() || usr.mailing_address();
34                 }
35             }
36         );
37     }
38
39     if (addr) {
40         oilsSelfckCCStreet.attr('value', addr.street1()+' '+addr.street2());
41         oilsSelfckCCCity.attr('value', addr.city());
42         oilsSelfckCCState.attr('value', addr.state());
43         oilsSelfckCCZip.attr('value', addr.post_code());
44     }
45
46     dojo.connect(oilsSelfckEditDetails, 'onChange',
47         function(newVal) {
48             dojo.forEach(
49                 [   oilsSelfckCCFName,
50                     oilsSelfckCCLName,
51                     oilsSelfckCCStreet,
52                     oilsSelfckCCCity,
53                     oilsSelfckCCState,
54                     oilsSelfckCCZip
55                 ],
56                 function(dij) { dij.attr('disabled', !newVal); }
57             );
58         }
59     );
60
61
62     var self = this;
63     dojo.connect(oilsSelfckCCSubmit, 'onClick',
64         function() {
65             /* XXX better to replace this check on progressDialog with some
66              * kind of passed-in function to support different use cases */
67             if (typeof(progressDialog) != "undefined")
68                 progressDialog.show(true);
69
70             self.sendCCPayment(patron, xacts, onPaymentSubmit);
71         }
72     );
73 }
74
75 // In this form, this code only supports global on/off credit card
76 // payments and does not dissallow payments to transactions that started
77 // at remote locations or transactions that have accumulated billings at
78 // remote locations that dissalow credit card payments.
79 // TODO add per-transaction blocks for orgs that do not support CC payments
80
81 proto.sendCCPayment = function(patron, xacts, onPaymentSubmit) {
82
83     var args = {
84         userid : patron.id(),
85         payment_type : 'credit_card_payment',
86         payments : xacts,
87         cc_args : {
88             where_process : 1,
89             //type : oilsSelfckCCType.attr('value'),
90             number : oilsSelfckCCNumber.attr('value'),
91             cvv2 : oilsSelfckCCCVV.attr('value'),
92             expire_year : oilsSelfckCCYear.attr('value'),
93             expire_month : oilsSelfckCCMonth.attr('value'),
94             billing_first : oilsSelfckCCFName.attr('value'),
95             billing_last : oilsSelfckCCLName.attr('value'),
96             billing_address : oilsSelfckCCStreet.attr('value'),
97             billing_city : oilsSelfckCCCity.attr('value'),
98             billing_state : oilsSelfckCCState.attr('value'),
99             billing_zip : oilsSelfckCCZip.attr('value')
100         }
101     }
102
103     var resp = fieldmapper.standardRequest(
104         ['open-ils.circ', 'open-ils.circ.money.payment'],
105         {params : [this.authtoken, args, patron.last_xact_id()]}
106     );
107
108     if (typeof(progressDialog) != "undefined")
109         progressDialog.hide();
110
111     if (typeof(onPaymentSubmit) == "function") {
112         onPaymentSubmit(resp);
113     } else {
114         var evt = openils.Event.parse(resp);
115         if (evt) alert(evt);
116     }
117 }