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