]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/bill_cc_info.xul
11297bb011349d9b4a6a1f56ce331d1751735001
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / patron / bill_cc_info.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Patron Display -->
4
5 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
6 <!-- STYLESHEETS -->
7 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
8 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/patron_display.css" type="text/css"?>
10
11 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
12 <!-- LOCALIZATION -->
13 <!DOCTYPE window PUBLIC "" ""[
14     <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
15 ]>
16
17 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
18 <!-- OVERLAYS -->
19 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
20
21 <window id="patron_bill" title="&staff.patron.bill_cc_info.title;"
22     orient="vertical" style="overflow: auto" oils_persist="height width sizemode"
23     onload="try{info_init(); font_helper(); refresh_fields(); persist_helper(); }catch(E){alert(E);}"
24     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
25
26     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
27     <!-- BEHAVIOR -->
28     <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
29     <scripts id="openils_util_scripts"/>
30
31     <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
32
33     <script>
34     <![CDATA[
35         function $(id) { return document.getElementById(id); }
36
37         XULElement.prototype.hide = function() {
38             this.style.display = "none";
39         }
40         XULElement.prototype.reveal = function() {
41             this.style.display = "";
42         }
43
44         var patron = {};
45         var show = {'int': 1, 'ext': 2}; // tied to Application::Circ::Money
46         var fields_of_interest = {
47             "cc_type":          show['ext'],
48             "cc_number":        show['int'],
49             "expire_month":     show['int'],
50             "expire_year":      show['int'],
51             "billing_first":    show['ext'] + show['int'],
52             "billing_last":     show['ext'] + show['int'],
53             "billing_address":  show['int'],
54             "billing_city":     show['int'],
55             "billing_state":    show['int'],
56             "billing_zip":      show['int'],
57             "approval_code":    show['ext'],
58             "note":             show['ext'] + show['int'],
59             "where_process":    show['ext'] + show['int']
60         };
61
62         function is_relevant_here(field) {
63             var flag = $('where_process').value;
64             var field_flag = fields_of_interest[field];
65             return ((field_flag & flag) == flag);
66         }
67
68         function refresh_fields() {
69             for (var field in fields_of_interest) {
70                 if (is_relevant_here(field)) {
71                     $('row_' + field).reveal();
72                 }
73                 else {
74                     $('row_' + field).hide();
75                 }
76             }
77         }
78
79         function populate_address_fields() {
80             $('billing_first').value = patron.first_given_name();
81             $('billing_last').value = patron.family_name();
82             if (patron.billing_address()) {
83                 $('billing_address').value = patron.billing_address().street1();
84                 var street2 = patron.billing_address().street2();
85                 if (street2) {
86                     $('billing_address').value += (' ' + street2);
87                 }
88                 $('billing_city').value = patron.billing_address().city();
89                 $('billing_state').value = patron.billing_address().state();
90                 $('billing_zip').value = patron.billing_address().post_code();
91             }
92         }
93
94         function info_init() {
95             if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
96             JSAN.errorLevel = "die"; // none, warn, or die
97             JSAN.addRepository('/xul/server/');
98             JSAN.use('util.error'); g.error = new util.error();
99             JSAN.use('util.network'); g.network = new util.network();
100             g.error.sdump('D_TRACE','my_init() for patron_display.xul');
101             g.OpenILS = {}; JSAN.use('OpenILS.data'); g.OpenILS.data = new OpenILS.data();
102             g.OpenILS.data.init({'via':'stash'});
103             /* 'true' as a string matches the expectations in bill2.js */
104             g.payment_blob = { 'cc_args' : {}, 'cancelled' : 'true' };
105             g.OpenILS.data.temp = js2JSON( g.payment_blob );
106             g.OpenILS.data.stash('temp');
107
108             try {
109                 patron = g.network.simple_request(
110                     'FM_AU_FLESHED_RETRIEVE_VIA_ID',
111                     [ses(), xul_param('patron_id', {'modal_xulG': true})]
112                 );
113             } catch (e) {
114                 alert ("Patron retrieval failed");
115                 throw(e);
116             }
117
118             populate_address_fields();
119             document.getElementById('cc_number').focus();
120         }
121
122         function sanity_check() {
123             if ($('where_process').value == show['int']) { // internal process
124                 if ($('cc_number').value.match(/^\s*$/)) {
125                     alert($('patronStrings').getString('staff.patron.bill_cc_info.need_cc_number'));
126                     return false;
127                 }
128             }
129             else {  // external
130                 if ($('approval_code').value.match(/^\s*$/)) {
131                     alert($('patronStrings').getString('staff.patron.bill_cc_info.need_approval_code'));
132                     return false;
133                 }
134             }
135             return true;
136         }
137
138         function info_finish() {
139             /* FIXME -- need unique temp space name */
140
141             /* The following for loop gathers our payment_blob values from
142             the widgets in this window.  This is better than the method of
143             gathering data that was here before (using oncommand attributes
144             to set values in this JS object whenever a field value changed)
145             because (if for no other reason), a select menu, if left at the
146             default value, would never reach the payment_blob, because its
147             oncommand attribute would never fire. */
148             for (var field in fields_of_interest) {
149                 if (is_relevant_here(field)) {
150                     var matches = field.match(/^cc_(.+)$/);
151                     var target_key = matches ? matches[1] : field;
152                     g.payment_blob.cc_args[target_key] = $(field).value;
153                 }
154             }
155             delete( g.payment_blob.cancelled );
156             g.OpenILS.data.temp = js2JSON( g.payment_blob );
157             g.OpenILS.data.stash('temp');
158         }
159
160     ]]>
161     </script>
162
163     <messagecatalog id="patronStrings" src="/xul/server/locale/<!--#echo var='locale'-->/patron.properties" />
164
165     <groupbox>
166         <caption label="&staff.patron.bill_cc_info.info.label;"/>
167         <grid>
168             <columns> <column flex="0" /> <column flex="0" /> </columns>
169             <rows>
170                 <row id="row_where_process">
171                     <label value="&staff.patron.bill_cc_info.where_process.label;"/>
172                     <menulist id="where_process" oncommand="refresh_fields();">
173                         <menupopup>
174                             <menuitem label="&staff.patron.bill_cc_info.process_int.label;" value="1"/>
175                             <menuitem label="&staff.patron.bill_cc_info.process_ext.label;" value="2"/>
176                         </menupopup>
177                     </menulist>
178                 </row>
179                 <row id="row_cc_type">
180                     <label value="&staff.patron.bill_cc_info.type.label;"/>
181                     <menulist id="cc_type">
182                         <menupopup>
183                             <menuitem label="&staff.patron.bill_cc_info.visa.label;" value="VISA"/><!-- capitalization to match CC processors' output -->
184                             <menuitem label="&staff.patron.bill_cc_info.mastercard.label;" value="MasterCard"/><!-- capitalization to match CC processors' output -->
185                             <menuitem label="&staff.patron.bill_cc_info.american_express.label;" value="American Express"/>
186                             <menuitem label="&staff.patron.bill_cc_info.discover.label;" value="Discover"/>
187                             <menuitem label="&staff.patron.bill_cc_info.other.label;" value="Other"/>
188                         </menupopup>
189                     </menulist>
190                 </row>
191                 <row id="row_approval_code">
192                     <label value="&staff.patron.bill_cc_info.approval_code.value;"/>
193                     <textbox id="approval_code" context="clipboard"/>
194                 </row>
195                 <row id="row_cc_number">
196                     <label value="&staff.patron.bill_cc_info.cc_number.value;"/>
197                     <textbox id="cc_number" context="clipboard"/>
198                 </row>
199                 <row id="row_expire_month">
200                     <label value="&staff.patron.bill_cc_info.month_expire.value;"/>
201                     <textbox id="expire_month" context="clipboard"/>
202                 </row>
203                 <row id="row_expire_year">
204                     <label value="&staff.patron.bill_cc_info.year_expire.value;"/>
205                     <textbox id="expire_year" context="clipboard"/>
206                 </row>
207             </rows>
208         </grid>
209     </groupbox>
210     <groupbox>
211         <caption label="Optional fields"/>
212         <grid>
213             <columns><column flex="0" /><column flex="1" /></columns>
214             <rows>
215                 <row id="row_billing_first">
216                     <label value="&staff.patron.bill_cc_info.billing_first.value;"/>
217                     <textbox id="billing_first" context="clipboard"/>
218                 </row>
219                 <row id="row_billing_last">
220                     <label value="&staff.patron.bill_cc_info.billing_last.value;"/>
221                     <textbox id="billing_last" context="clipboard"/>
222                 </row>
223                 <row id="row_billing_address">
224                     <label value="&staff.patron.bill_cc_info.billing_address.value;"/>
225                     <textbox id="billing_address" context="clipboard"/>
226                 </row>
227                 <row id="row_billing_city">
228                     <label value="&staff.patron.bill_cc_info.billing_city.value;"/>
229                     <textbox id="billing_city" context="clipboard"/>
230                 </row>
231                 <row id="row_billing_state">
232                     <label value="&staff.patron.bill_cc_info.billing_state.value;"/>
233                     <textbox id="billing_state" context="clipboard"/>
234                 </row>
235                 <row id="row_billing_zip">
236                     <label value="&staff.patron.bill_cc_info.billing_zip.value;"/>
237                     <textbox cols="12" maxlength="11" id="billing_zip" context="clipboard"/>
238                 </row>
239                 <row id="row_note">
240                     <label value="&staff.patron.bill_cc_info.note.value;"/>
241                     <textbox id="note" multiline="true" context="clipboard"/>
242                 </row>
243             </rows>
244         </grid>
245         <hbox>
246             <spacer flex="1"/>
247             <button label="&staff.patron.bill_cc_info.cancel.label;" oncommand="window.close()" accesskey="&staff.patron.bill_cc_info.cancel.accesskey;"/>
248             <button label="&staff.patron.bill_cc_info.submit.label;" oncommand="if (sanity_check()) { info_finish(); window.close(); }" accesskey="&staff.patron.bill_cc_info.submit.accesskey;"/>
249         </hbox>
250     </groupbox>
251
252 </window>
253