]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/patron/barcode_entry.xul
Switch to .authoritative version of some methods
[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="chrome://open_ils_staff_client/skin/global.css" type="text/css"?>
9 <?xml-stylesheet href="/xul/server/skin/global.css" type="text/css"?>
10
11 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
12 <!-- LOCALIZATION -->
13 <!DOCTYPE window PUBLIC "" ""[
14         <!--#include virtual="/opac/locale/en-US/lang.dtd"-->
15 ]>
16
17 <!-- ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
18 <!-- OVERLAYS -->
19 <?xul-overlay href="/xul/server/OpenILS/util_overlay.xul"?>
20
21 <window id="patron_barcode_entry_win" 
22         onload="try { my_init(); font_helper(); } 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 my_init() {
34                         try {
35                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
36                                 if (typeof JSAN == 'undefined') { throw( "The JSAN library object is 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('User Permission Editor'); } catch(E) { alert(E); }
63                     } else {
64                                         try { window.xulG.set_tab_name('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 = "!! This software has encountered an error.  Please tell your friendly " +
75                                         "system administrator or software developer the following:\n" + E + '\n';
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('No barcode entered.'); 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('PATRON_BARCODE_EXISTS.authoritative',[ ses(), barcode ],
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                                                         add_msg('Problem retrieving ' + barcode + '.  Please report this message: \n' + js2JSON(robj));
104                                                         return;
105                                                 } else if (robj == 0) {
106                                                         sound.bad(); 
107                                                         add_msg('Barcode ' + barcode + ' not found.');
108                                                         return;
109                                                 }
110
111                         if (g.data.user_org_unit_opt_in_enabled) {
112                             var r = net.simple_request('USER_ORG_UNIT_OPT_IN_CHECK',[ ses(), robj ]);
113                             if (typeof r.ilsevent != 'undefined') {
114                                 throw(r);
115                             } else {
116     
117                                 if (r == 0) {
118                                 
119                                     JSAN.use('patron.util');
120                                     var parts = patron.util.retrieve_name_via_id( ses(), robj );
121     
122                                     if (0 != g.error.yns_alert(
123                                         'Does patron ' + parts[0] + ', ' + parts[1] + (parts[2] ? ' ' + parts[2] : '') + ' from ' + g.data.hash.aou[ parts[3] ].name() + ' (' + g.data.hash.aou[ parts[3] ].shortname() + ') consent to having their personal information shared with your library?',
124                                         'Patron/Library Opt-In Confirmation',
125                                         'Accept', 'Deny', null, 'Check here to confirm this message'
126                                         )
127                                     ) {
128                                         tb.select(); tb.focus();
129                                         return;
130                                     } else {
131                                         var c = net.simple_request('USER_ORG_UNIT_OPT_IN_CREATE',[ ses(), robj ]);
132                                         if (typeof c.ilsevent != 'undefined') throw(r);
133                                     }
134                                 }
135     
136                                                     sound.good();
137                                                     spawn(barcode);
138                             }
139                         } else {
140                                                     sound.good();
141                                                     spawn(barcode);
142                         }
143                                         }
144                                 );
145                         } catch(E) {
146                                 tb.select(); tb.focus();
147                                 g.error.standard_unexpected_error_alert('barcode_entry.xul',E);
148                         }
149                 }
150
151                 function add_msg(text) {
152                         var x = document.getElementById('status');
153                         var d = document.createElement('description');
154                         x.appendChild(d);
155                         d.appendChild( document.createTextNode( text ) );
156                         d.setAttribute('style','color: red');
157                 }
158
159                 function spawn(barcode) {
160             if (xul_param('perm_editor')) { spawn_perm_editor(barcode); } else { spawn_checkout(barcode); }
161         }
162
163                 function spawn_checkout(barcode) {
164                         try {
165                                 var loc = urls.XUL_PATRON_DISPLAY; // + '?barcode=' + window.escape(barcode);
166                                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab == 'function') {
167                                         window.xulG.set_tab( loc, {}, { 'barcode' : barcode } );
168                                 } else {
169                                         location.href = loc + '?barcode=' + window.escape(barcode);
170                                 }
171                         } catch(E) {
172                                 g.error.standard_unexpected_error_alert('spawning patron display',E);
173                         }
174                 }
175
176                 function spawn_perm_editor(barcode) {
177                         try {
178                                 JSAN.use('patron.util'); var patron_obj = patron.util.retrieve_fleshed_au_via_barcode( ses(), barcode );
179                                 var loc = urls.XUL_USER_PERM_EDITOR + '?ses=' + window.escape(ses()) + '&usr=' + patron_obj.id();
180                                 if (typeof window.xulG == 'object' && typeof window.xulG.set_tab == 'function') {
181                                         window.xulG.set_tab( loc, {}, {} );
182                                 } else {
183                                         location.href = loc;
184                                 }
185                         } catch(E) {
186                                 g.error.standard_unexpected_error_alert('spawning user perm editor',E);
187                         }
188                 }
189
190
191                 function default_focus() { try { setTimeout( function() { document.getElementById('barcode_tb').focus(); }, 0); } catch(E) {} }
192         ]]>
193         </script>
194
195         <vbox flex="1" class="my_overflow">
196                 <groupbox orient="vertical" flex="1">
197                         <caption label="Retrieve Patron" />
198                         <hbox>
199                                 <label value="Barcode:" accesskey="B" control="barcode_tb"/>
200                                 <textbox id="barcode_tb" />
201                                 <button label="Submit" accesskey="S" oncommand="submit();"/>
202                         </hbox>
203                         <label value="Retrieving..." style="color: green" id="progress" hidden="true"/>
204                         <vbox id="status">
205                         </vbox>
206                 </groupbox>
207         </vbox>
208
209 </window>
210