0de36de019f99b2479b034424f6f4feea496643e
[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                 net.simple_request('FM_AU_ID_RETRIEVE_VIA_BARCODE_OR_USERNAME',[ ses(), barcode, null ],
97                     function(req) {
98                         document.getElementById('progress').setAttribute('hidden','true');
99                         tb.disabled = false; tb.select(); tb.focus(); ;
100                         var robj = req.getResultObject();
101                         if (typeof robj.ilsevent != 'undefined') {
102                             sound.bad();
103                             switch(Number(robj.ilsevent)) {
104                                 case 1002 /* ACTOR_USER_NOT_FOUND */: 
105                                     add_msg($("patronStrings").getFormattedString('staff.patron.barcode_entry.barcode_not_found', [barcode]));
106                                 break;
107                                 default:
108                                     add_msg($("patronStrings").getFormattedString('staff.patron.barcode_entry.barcode_retrieval_problem', [barcode, js2JSON(robj)]));
109                             }
110                             return;
111                         }
112
113                         if (g.data.user_org_unit_opt_in_enabled) {
114                             var r = net.simple_request('USER_ORG_UNIT_OPT_IN_CHECK',[ ses(), robj ]);
115                             if (typeof r.ilsevent != 'undefined') {
116                                 throw(r);
117                             } else {
118
119                                 if (r == 0) {
120
121                                     JSAN.use('patron.util');
122                                     var parts = patron.util.retrieve_name_via_id( ses(), robj );
123     
124                                     if (0 != g.error.yns_alert(
125                                             $("patronStrings").getFormattedString('staff.patron.barcode_entry.consent_from_patron',
126                                                 [parts[0], parts[1] + (parts[2] ? ' ' + parts[2] : ''), g.data.hash.aou[ parts[3] ].name(), g.data.hash.aou[ parts[3] ].shortname()]),
127                                             $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_title'),
128                                             $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_accept'),
129                                             $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_deny'), null,
130                                             $("patronStrings").getString('staff.patron.barcode_entry.patron_consent_confirm')
131                                         )
132                                     ) {
133                                         tb.select(); tb.focus();
134                                         return;
135                                     } else {
136                                         var c = net.simple_request('USER_ORG_UNIT_OPT_IN_CREATE',[ ses(), robj ]);
137                                         if (typeof c.ilsevent != 'undefined') throw(r);
138                                     }
139                                 }
140     
141                                 sound.good();
142                                 spawn(barcode);
143                             }
144                         } else {
145                             sound.good();
146                             spawn(barcode);
147                         }
148                     }
149                 );
150             } catch(E) {
151                 tb.select(); tb.focus();
152                 g.error.standard_unexpected_error_alert('barcode_entry.xul',E);
153             }
154         }
155
156         function add_msg(text) {
157             var x = document.getElementById('status');
158             var d = document.createElement('description');
159             x.appendChild(d);
160             d.appendChild( document.createTextNode( text ) );
161             d.setAttribute('style','color: red');
162         }
163
164         function spawn(barcode) {
165             if (xul_param('perm_editor')) { spawn_perm_editor(barcode); } else { spawn_checkout(barcode); }
166         }
167
168         function spawn_checkout(barcode) {
169             try {
170                 var horizontal_interface = String( g.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
171                 var loc = xulG.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
172                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab == 'function') {
173                     window.xulG.set_tab( loc, {}, { 'barcode' : barcode } );
174                 } else {
175                     location.href = loc + '?barcode=' + window.escape(barcode);
176                 }
177             } catch(E) {
178                 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.barcode_entry.patron_display_error'),E);
179             }
180         }
181
182         function spawn_perm_editor(barcode) {
183             try {
184                 JSAN.use('patron.util'); var patron_obj = patron.util.retrieve_fleshed_au_via_barcode( ses(), barcode );
185                 var loc = urls.XUL_USER_PERM_EDITOR + '?ses=' + window.escape(ses()) + '&usr=' + patron_obj.id();
186                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab == 'function') {
187                     window.xulG.set_tab( loc, {}, {} );
188                 } else {
189                     location.href = loc;
190                 }
191             } catch(E) {
192                 g.error.standard_unexpected_error_alert($("patronStrings").getString('staff.patron.barcode_entry.user_perm_display_error'),E);
193             }
194         }
195
196
197         function default_focus() { try { setTimeout( function() { document.getElementById('barcode_tb').focus(); }, 0); } catch(E) {} }
198     ]]>
199     </script>
200     
201     <messagecatalog id="patronStrings" src="/xul/server/locale/<!--#echo var='locale'-->/patron.properties" />
202
203     <vbox flex="1" class="my_overflow">
204         <groupbox orient="vertical" flex="1">
205             <caption label="&staff.pat.barcode_entry.retrieve_patron.label;" />
206             <hbox>
207                 <label value="&staff.pat.barcode_entry.barcode.label;" accesskey="&staff.pat.barcode_entry.barcode.accesskey;" control="barcode_tb"/>
208                 <textbox id="barcode_tb"  context="clipboard"/>
209                 <button label="&staff.pat.barcode_entry.submit_btn.label;" accesskey="&staff.pat.barcode_entry.submit_btn.accesskey;" oncommand="submit();"/>
210             </hbox>
211             <label value="&staff.pat.barcode_entry.retrieving.label;" style="color: green" id="progress" hidden="true"/>
212             <vbox id="status">
213             </vbox>
214         </groupbox>
215     </vbox>
216
217 </window>
218