]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/bill_cc_info.xul
combined patch from Lebbeous Fogle-Weekley to add option of overriding the default...
[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"
23     onload="try{info_init(); font_helper();refresh_fields();}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['int'],
52             "billing_last":     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             $('billing_address').value = patron.billing_address().street1();
83             var street2 = patron.billing_address().street2();
84             if (street2) {
85                 $('billing_address').value += (' ' + street2);
86             }
87             $('billing_city').value = patron.billing_address().city();
88             $('billing_state').value = patron.billing_address().state();
89             $('billing_zip').value = patron.billing_address().post_code();
90         }
91
92         function info_init() {
93             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
94             if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
95             JSAN.errorLevel = "die"; // none, warn, or die
96             JSAN.addRepository('/xul/server/');
97             JSAN.use('util.error'); g.error = new util.error();
98             JSAN.use('util.network'); g.network = new util.network();
99             g.error.sdump('D_TRACE','my_init() for patron_display.xul');
100             g.OpenILS = {}; JSAN.use('OpenILS.data'); g.OpenILS.data = new OpenILS.data();
101             g.OpenILS.data.init({'via':'stash'});
102             /* 'true' as a string matches the expectations in bills.js */
103             g.payment_blob = { 'cc_args' : {}, 'cancelled' : 'true' };
104             g.OpenILS.data.temp = js2JSON( g.payment_blob );
105             g.OpenILS.data.stash('temp');
106
107             try {
108                 patron = g.network.simple_request(
109                     'FM_AU_FLESHED_RETRIEVE_VIA_ID',
110                     [ses(), xul_param('patron_id', {'modal_xulG': true})]
111                 );
112             } catch (e) {
113                 alert ("Patron retrieval failed");
114                 throw(e);
115             }
116
117             populate_address_fields();
118             document.getElementById('cc_number').focus();
119         }
120
121         function sanity_check() {
122             if ($('where_process').value == show['int']) { // internal process
123                 if ($('cc_number').value.match(/^\s*$/)) {
124                     alert($('patronStrings').getString('staff.patron.bill_cc_info.need_cc_number'));
125                     return false;
126                 }
127             }
128             else {  // external
129                 if ($('approval_code').value.match(/^\s*$/)) {
130                     alert($('patronStrings').getString('staff.patron.bill_cc_info.need_approval_code'));
131                     return false;
132                 }
133             }
134             return true;
135         }
136
137         function info_finish() {
138             /* FIXME -- need unique temp space name */
139
140             /* The following for loop gathers our payment_blob values from
141             the widgets in this window.  This is better than the method of
142             gathering data that was here before (using oncommand attributes
143             to set values in this JS object whenever a field value changed)
144             because (if for no other reason), a select menu, if left at the
145             default value, would never reach the payment_blob, because its
146             oncommand attribute would never fire. */
147             for (var field in fields_of_interest) {
148                 if (is_relevant_here(field)) {
149                     var matches = field.match(/^cc_(.+)$/);
150                     var target_key = matches ? matches[1] : field;
151                     g.payment_blob.cc_args[target_key] = $(field).value;
152                 }
153             }
154             delete( g.payment_blob.cancelled );
155             g.OpenILS.data.temp = js2JSON( g.payment_blob );
156             g.OpenILS.data.stash('temp');
157         }
158
159     ]]>
160     </script>
161
162     <messagecatalog id="patronStrings" src="/xul/server/locale/<!--#echo var='locale'-->/patron.properties" />
163
164     <groupbox>
165         <caption label="&staff.patron.bill_cc_info.info.label;"/>
166         <grid>
167             <columns> <column flex="0" /> <column flex="0" /> </columns>
168             <rows>
169                 <row id="row_where_process">
170                     <label value="&staff.patron.bill_cc_info.where_process.label;"/>
171                     <menulist id="where_process" oncommand="refresh_fields();">
172                         <menupopup>
173                             <menuitem label="&staff.patron.bill_cc_info.process_int.label;" value="1"/>
174                             <menuitem label="&staff.patron.bill_cc_info.process_ext.label;" value="2"/>
175                         </menupopup>
176                     </menulist>
177                 </row>
178                 <row id="row_cc_type">
179                     <label value="&staff.patron.bill_cc_info.type.label;"/>
180                     <menulist id="cc_type">
181                         <menupopup>
182                             <menuitem label="&staff.patron.bill_cc_info.visa.label;" value="VISA"/><!-- capitalization to match CC processors' output -->
183                             <menuitem label="&staff.patron.bill_cc_info.mastercard.label;" value="MasterCard"/><!-- capitalization to match CC processors' output -->
184                             <menuitem label="&staff.patron.bill_cc_info.american_express.label;" value="American Express"/>
185                             <menuitem label="&staff.patron.bill_cc_info.discover.label;" value="Discover"/>
186                             <menuitem label="&staff.patron.bill_cc_info.other.label;" value="Other"/>
187                         </menupopup>
188                     </menulist>
189                 </row>
190                 <row id="row_approval_code">
191                     <label value="&staff.patron.bill_cc_info.approval_code.value;"/>
192                     <textbox id="approval_code" context="clipboard"/>
193                 </row>
194                 <row id="row_cc_number">
195                     <label value="&staff.patron.bill_cc_info.cc_number.value;"/>
196                     <textbox id="cc_number" context="clipboard"/>
197                 </row>
198                 <row id="row_expire_month">
199                     <label value="&staff.patron.bill_cc_info.month_expire.value;"/>
200                     <textbox id="expire_month" context="clipboard"/>
201                 </row>
202                 <row id="row_expire_year">
203                     <label value="&staff.patron.bill_cc_info.year_expire.value;"/>
204                     <textbox id="expire_year" context="clipboard"/>
205                 </row>
206             </rows>
207         </grid>
208     </groupbox>
209     <groupbox>
210         <caption label="Optional fields"/>
211         <grid>
212             <columns><column flex="0" /><column flex="1" /></columns>
213             <rows>
214                 <row id="row_billing_first">
215                     <label value="&staff.patron.bill_cc_info.billing_first.value;"/>
216                     <textbox id="billing_first" context="clipboard"/>
217                 </row>
218                 <row id="row_billing_last">
219                     <label value="&staff.patron.bill_cc_info.billing_last.value;"/>
220                     <textbox id="billing_last" context="clipboard"/>
221                 </row>
222                 <row id="row_billing_address">
223                     <label value="&staff.patron.bill_cc_info.billing_address.value;"/>
224                     <textbox id="billing_address" context="clipboard"/>
225                 </row>
226                 <row id="row_billing_city">
227                     <label value="&staff.patron.bill_cc_info.billing_city.value;"/>
228                     <textbox id="billing_city" context="clipboard"/>
229                 </row>
230                 <row id="row_billing_state">
231                     <label value="&staff.patron.bill_cc_info.billing_state.value;"/>
232                     <textbox id="billing_state" context="clipboard"/>
233                 </row>
234                 <row id="row_billing_zip">
235                     <label value="&staff.patron.bill_cc_info.billing_zip.value;"/>
236                     <textbox cols="12" maxlength="11" id="billing_zip" context="clipboard"/>
237                 </row>
238                 <row id="row_note">
239                     <label value="&staff.patron.bill_cc_info.note.value;"/>
240                     <textbox id="note" multiline="true" context="clipboard"/>
241                 </row>
242             </rows>
243         </grid>
244         <hbox>
245             <spacer flex="1"/>
246             <button label="&staff.patron.bill_cc_info.cancel.label;" oncommand="window.close()" accesskey="&staff.patron.bill_cc_info.cancel.accesskey;"/>
247             <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;"/>
248         </hbox>
249     </groupbox>
250
251 </window>
252