]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/barcode_entry.xul
Improve Firefox/XULRunner Support
[Evergreen.git] / Open-ILS / xul / staff_client / server / patron / barcode_entry.xul
1 <?xml version="1.0"?>
2 <!-- Application: Evergreen Staff Client -->
3 <!-- Screen: Retrieve Patron By Barcode -->
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
10 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
11 <!-- LOCALIZATION -->
12 <!DOCTYPE window PUBLIC "" ""[
13     <!--#include virtual="/opac/locale/${locale}/lang.dtd"-->
14 ]>
15
16 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
17 <!-- OVERLAYS -->
18 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
19
20 <window id="patron_barcode_entry_win" 
21     onload="try { my_init(); font_helper(); persist_helper(); } catch(E) { alert(E); }"
22     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
23
24     <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
25     <!-- BEHAVIOR -->
26         <script type="text/javascript">var myPackageDir = 'open_ils_staff_client'; var IAMXUL = true; var g = {};</script>
27         <scripts id="openils_util_scripts"/>
28
29     <script type="text/javascript" src="/xul/server/main/JSAN.js"/>
30     <script>
31     <![CDATA[
32         function $(id) { return document.getElementById(id); }
33         
34         function my_init() {
35             try {
36             if (typeof JSAN == 'undefined') { throw( $("commonStrings").getString('common.jsan.missing') ); }
37                 JSAN.errorLevel = "die"; // none, warn, or die
38                 JSAN.addRepository('/xul/server/');
39                 JSAN.use('util.error'); g.error = new util.error();
40                 g.error.sdump('D_TRACE','my_init() for patron/barcode_entry.xul');
41
42                 JSAN.use('OpenILS.data'); g.data = new OpenILS.data(); g.data.init({'via':'stash'});
43
44                 var tb = document.getElementById('barcode_tb');
45                 tb.addEventListener(
46                     'keypress',
47                     function(ev) {
48                         if (ev.keyCode == 13 || ev.keyCode == 77) {
49                             setTimeout(
50                                 function() {
51                                     submit();
52                                 }, 0
53                             );
54                         }
55                     },
56                     false
57                 );
58                 tb.focus();
59     
60                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab_name == 'function') {
61                     if (xul_param('perm_editor')) {
62                         try { window.xulG.set_tab_name($("patronStrings").getString('staff.patron.barcode_entry.user_permission_editor')); } catch(E) { alert(E); }
63                     } else {
64                         try { window.xulG.set_tab_name($("patronStrings").getString('staff.patron.barcode_entry.check_out')); } catch(E) { alert(E); }
65                     }
66                 }
67
68                 if (xul_param('error')) { 
69                     var error = xul_param('error');
70                     alert(error);
71                 }
72
73             } catch(E) {
74                 var err_msg = $("commonStrings").getFormattedString('common.exception', ['patron/barcode_entry.xul', E]);
75                 try { g.error.sdump('D_ERROR',err_msg); } catch(E) { dump(err_msg); }
76                 alert(err_msg);
77             }
78         }
79
80         function submit() {
81             var tb;
82             try {
83                 JSAN.use('util.sound'); var sound = new util.sound();
84                 tb = document.getElementById('barcode_tb');
85                 var barcode = tb.value;
86
87                 barcode = String( barcode ).replace( /\s+/g, '' );
88
89                 if (!barcode) { sound.bad(); add_msg($("patronStrings").getString('staff.patron.barcode_entry.no_barcode')); tb.select(); tb.focus(); return; }
90
91                 JSAN.use('util.network'); var net = new util.network();
92
93                 tb.disabled = true;
94                 document.getElementById('progress').setAttribute('hidden','false');
95                 // Auto-complete the barcode, users only. Handily, looks up all we need to know in the process.
96                 var barcode_object = xulG.get_barcode(window, 'actor', barcode);
97                 document.getElementById('progress').setAttribute('hidden','true');
98                 tb.disabled = false; tb.select(); tb.focus(); ;
99                 // user_false means the user said "None of the above", so abort without further prompts/actions
100                 if(barcode_object == "user_false") return;
101                 if(barcode_object == false) {
102                     // Boolean false means the barcode was not found, and the user wasn't prompted.
103                     sound.bad();
104                     add_msg($("patronStrings").getFormattedString('staff.patron.barcode_entry.barcode_not_found', [barcode]));
105                     return;
106                 }
107                 else if(typeof barcode_object.ilsevent != 'undefined') {
108                     // Getting an ilsevent error otherwise means something, likely permissions issues, went wrong
109                     sound.bad();
110                     add_msg($("patronStrings").getFormattedString('staff.patron.barcode_entry.barcode_retrieval_problem', [barcode, js2JSON(barcode_object)]));
111                     return;
112                 }
113
114                 if (g.data.user_org_unit_opt_in_enabled) {
115                     var r = net.simple_request('USER_ORG_UNIT_OPT_IN_CHECK',[ ses(), barcode_object.id ]);
116                     if (typeof r.ilsevent != 'undefined') {
117                         throw(r);
118                     } else {
119
120                         if (r == 0) {
121
122                             JSAN.use('patron.util');
123                             var parts;
124                             // Handily, if the user was prompted, we should already have the user's name information returned from autocomplete
125                             // Use it if there, as it saves us a network call.
126                             if(barcode_object.request_data) parts = barcode_object.request_data;
127                             // Otherwise, make the network call
128                             else parts = patron.util.retrieve_name_via_id( ses(), barcode_object.id );
129     
130                             if (0 != g.error.yns_alert(
131                                     $("patronStrings").getFormattedString('staff.patron.barcode_entry.consent_from_patron',
132                                         [parts[0], parts[1] + (parts[2] ? ' ' + parts[2] : ''), g.data.hash.aou[ parts[3] ].name(), g.data.hash.aou[ parts[3] ].shortname()]),
133                                     $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_title'),
134                                     $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_accept'),
135                                     $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_deny'), null,
136                                     $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_confirm')
137                                 )
138                             ) {
139                                 tb.select(); tb.focus();
140                                 return;
141                             } else {
142                                 var c = net.simple_request('USER_ORG_UNIT_OPT_IN_CREATE',[ ses(), barcode_object.id ]);
143                                 if (typeof c.ilsevent != 'undefined') throw(r);
144                             }
145                         }
146     
147                         sound.good();
148                         spawn(barcode_object.id, barcode_object.barcode);
149                     }
150                 } else {
151                     sound.good();
152                     spawn(barcode_object.id, barcode_object.barcode);
153                 }
154             } catch(E) {
155                 tb.select(); tb.focus();
156                 g.error.standard_unexpected_error_alert('barcode_entry.xul',E);
157             }
158         }
159
160         function add_msg(text) {
161             var x = document.getElementById('status');
162             var d = document.createElement('description');
163             x.appendChild(d);
164             d.appendChild( document.createTextNode( text ) );
165             d.setAttribute('style','color: red');
166         }
167
168         function spawn(id, barcode) {
169             if (xul_param('perm_editor')) { spawn_perm_editor(id); } else { spawn_checkout(barcode); }
170         }
171
172         function spawn_checkout(barcode) {
173             try {
174                 var horizontal_interface = String( g.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
175                 var loc = xulG.url_prefix( horizontal_interface ? 'XUL_PATRON_HORIZ_DISPLAY' : 'XUL_PATRON_DISPLAY' );
176                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab == 'function') {
177                     window.xulG.set_tab( loc, {}, { 'barcode' : barcode } );
178                 } else {
179                     location.href = loc + '?barcode=' + window.escape(barcode);
180                 }
181             } catch(E) {
182                 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.barcode_entry.patron_display_error'),E);
183             }
184         }
185
186         function spawn_perm_editor(id) {
187             try {
188                 var loc = urls.XUL_USER_PERM_EDITOR + '?ses=' + window.escape(ses()) + '&usr=' + id;
189                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab == 'function') {
190                     window.xulG.set_tab( loc, {}, {} );
191                 } else {
192                     location.href = loc;
193                 }
194             } catch(E) {
195                 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.barcode_entry.user_perm_display_error'),E);
196             }
197         }
198
199
200         function default_focus() { try { setTimeout( function() { document.getElementById('barcode_tb').focus(); }, 0); } catch(E) {} }
201     ]]>
202     </script>
203     
204     <messagecatalog id="patronStrings" src="/xul/server/locale/<!--#echo var='locale'-->/patron.properties" />
205
206     <vbox flex="1" class="my_overflow">
207         <groupbox orient="vertical" flex="1">
208             <caption label="&staff.pat.barcode_entry.retrieve_patron.label;" />
209             <hbox>
210                 <label value="&staff.pat.barcode_entry.barcode.label;" accesskey="&staff.pat.barcode_entry.barcode.accesskey;" control="barcode_tb"/>
211                 <textbox id="barcode_tb"  context="clipboard"/>
212                 <button label="&staff.pat.barcode_entry.submit_btn.label;" accesskey="&staff.pat.barcode_entry.submit_btn.accesskey;" oncommand="submit();"/>
213             </hbox>
214             <label value="&staff.pat.barcode_entry.retrieving.label;" style="color: green" id="progress" hidden="true"/>
215             <vbox id="status">
216             </vbox>
217         </groupbox>
218     </vbox>
219
220 </window>
221