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