Lazy Circ (AKA partial barcode lookup)
[working/Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / main / menu.js
1 dump('entering main/menu.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 var offlineStrings;
5
6 if (typeof main == 'undefined') main = {};
7 main.menu = function () {
8
9     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
10     offlineStrings = document.getElementById('offlineStrings');
11     JSAN.use('util.error'); this.error = new util.error();
12     JSAN.use('util.window'); this.window = new util.window();
13     JSAN.use('OpenILS.data'); this.data = new OpenILS.data(); this.data.init({'via':'stash'});
14
15     this.w = window;
16     var x = document.getElementById('network_progress');
17     x.setAttribute('count','0');
18     x.addEventListener(
19         'click',
20         function() {
21             if ( window.confirm(offlineStrings.getString('menu.reset_network_stats')) ) {
22                 var y = document.getElementById('network_progress_rows');
23                 while(y.firstChild) { y.removeChild( y.lastChild ); }
24                 x.setAttribute('mode','determined');
25                 x.setAttribute('count','0');
26             }
27         },
28         false
29     );
30 }
31
32 main.menu.prototype = {
33
34     'id_incr' : 0,
35
36     'toolbar' : 'none',
37     'toolbar_size' : 'large',
38     'toolbar_mode' : 'both',
39     'toolbar_labelpos' : 'side',
40
41     'url_prefix' : function(url) {
42         if (url.match(/^\//)) url = urls.remote + url;
43         if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
44         dump('url_prefix = ' + url + '\n');
45         return url;
46     },
47
48     'init' : function( params ) {
49
50         var obj = this;
51
52         urls.remote = params['server'];
53
54         xulG.get_barcode = this.get_barcode;
55
56         // Pull in local customizations
57         var r = new XMLHttpRequest();
58         r.open("GET", obj.url_prefix('/xul/server/skin/custom.js'), false);
59         r.send(null);
60         if (r.status == 200) {
61             dump('Evaluating /xul/server/skin/custom.js\n');
62             eval( r.responseText );
63         }
64
65         // Try workstation pref for button bar
66         var button_bar = xulG.pref.getCharPref('open-ils.menu.toolbar');
67
68         if (!button_bar) // No workstation pref? Try org unit pref.
69             button_bar = String( obj.data.hash.aous['ui.general.button_bar'] );
70
71         if (button_bar) {
72             var x = document.getElementById('toolbar_' + button_bar);
73             if (x) x.setAttribute('hidden','false');
74             this.toolbar = button_bar;
75         }
76
77         // Check for alternate Size pref
78         var toolbar_size = xulG.pref.getCharPref('open-ils.menu.toolbar.iconsize');
79         if(toolbar_size) this.toolbar_size = toolbar_size;
80         // Check for alternate Mode pref
81         var toolbar_mode = xulG.pref.getCharPref('open-ils.menu.toolbar.mode');
82         if(toolbar_mode) this.toolbar_mode = toolbar_mode;
83         // Check for alternate Label Position pref
84         var toolbar_labelpos = xulG.pref.getBoolPref('open-ils.menu.toolbar.labelbelow');
85         if(toolbar_labelpos) this.toolbar_labelpos = toolbar_labelpos;
86
87         if(button_bar || toolbar_size || toolbar_mode || toolbar_labelpos) {
88             var toolbox = document.getElementById('main_toolbox');
89             var toolbars = toolbox.getElementsByTagName('toolbar');
90             for(var i = 0; i < toolbars.length; i++) {
91                 if(toolbars[i].id == 'toolbar_' + button_bar)
92                     toolbars[i].setAttribute('hidden', 'false');
93                 else
94                     toolbars[i].setAttribute('hidden', 'true');
95                 if(toolbar_mode) toolbars[i].setAttribute('mode', toolbar_mode);
96                 if(toolbar_size) toolbars[i].setAttribute('iconsize', toolbar_size);
97                 if(toolbar_labelpos) addCSSClass(toolbars[i], 'labelbelow');
98             }
99         }
100
101         if(button_bar) {
102             var x = document.getElementById('main.menu.admin.client.toolbars.current.popup');
103             if (x) {
104                 var selectitems = x.getElementsByAttribute('value',button_bar);
105                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
106             }
107         }
108
109         if(toolbar_size) {
110             var x = document.getElementById('main.menu.admin.client.toolbars.size.popup');
111             if (x) {
112                 var selectitems = x.getElementsByAttribute('value',toolbar_size);
113                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
114             }
115         }
116
117         if(toolbar_mode) {
118             var x = document.getElementById('main.menu.admin.client.toolbars.mode.popup');
119             if (x) {
120                 var selectitems = x.getElementsByAttribute('value',toolbar_mode);
121                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
122             }
123         }
124
125         if(toolbar_labelpos) {
126             var x = document.getElementById('main.menu.admin.client.toolbars.label_position.popup');
127             if (x) {
128                 var selectitems = x.getElementsByAttribute('value',"under");
129                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
130             }
131         }
132
133         var network_meter = String( obj.data.hash.aous['ui.network.progress_meter'] ) == 'true';
134         if (! network_meter) {
135             var x = document.getElementById('network_progress');
136             if (x) x.setAttribute('hidden','true');
137             var y = document.getElementById('page_progress');
138             if (y) y.setAttribute('hidden','true');
139         }
140
141         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
142                     getService(Components.interfaces.nsIWindowMediator);
143         var mainwin = wm.getMostRecentWindow('eg_main');
144         mainwin.get_menu_perms(document);
145         var hotkeysets = mainwin.load_hotkey_sets();
146
147         var popupmenu = document.getElementById('main.menu.admin.client.hotkeys.current.popup');
148         
149         for(var i = 0; i < hotkeysets.length; i++) {
150             var keysetname = hotkeysets[i];
151             var menuitem = document.createElement('menuitem');
152             if(offlineStrings.testString('hotkey.' + keysetname))
153                 menuitem.setAttribute('label',offlineStrings.getString('hotkey.' + keysetname));
154             else
155                 menuitem.setAttribute('label',keysetname);
156             menuitem.setAttribute('value',keysetname);
157             menuitem.setAttribute('type','radio');
158             menuitem.setAttribute('name','menu_hotkey_current');
159             menuitem.setAttribute('command','cmd_hotkeys_set');
160             popupmenu.appendChild(menuitem);
161         }
162
163         JSAN.use('util.network');
164         var network = new util.network();
165         network.set_user_status();
166
167         this.set_menu_hotkeys();
168
169         function open_conify_page(path, labelKey, event) {
170
171             // tab label
172             labelKey = labelKey || 'menu.cmd_open_conify.tab';
173             label = offlineStrings.getString(labelKey);
174
175             // URL
176             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.CONIFY) + '/' + path + '.html');
177
178             obj.command_tab(
179                 event,
180                 loc, 
181                 {'tab_name' : label, 'browser' : false }, 
182                 {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons:true} 
183             );
184         }
185
186         function open_admin_page(path, labelKey, addSes, event) {
187
188             // tab label
189             labelKey = labelKey || 'menu.cmd_open_conify.tab';
190             label = offlineStrings.getString(labelKey);
191
192             // URL
193             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_LOCAL_ADMIN_BASE) + '/' + path);
194             if(addSes) loc += window.escape('?ses=' + ses());
195
196             obj.command_tab( 
197                 event,
198                 loc, 
199                 {'tab_name' : label, 'browser' : false }, 
200                 {'no_xulG' : false, 'show_print_button' : true, 'show_nav_buttons' : true } 
201             );
202         }
203
204
205         function open_eg_web_page(path, labelKey, event) {
206             
207             // tab label
208             labelKey = labelKey || 'menu.cmd_open_conify.tab';
209             var label = offlineStrings.getString(labelKey);
210
211             // URL
212             var loc = urls.XUL_BROWSER + '?url=' + window.escape(obj.url_prefix(urls.EG_WEB_BASE) + '/' + path);
213
214             obj.command_tab(
215                 event,
216                 loc, 
217                 {tab_name : label, browser : false }, 
218                 {no_xulG : false, show_print_button : true, show_nav_buttons : true }
219             );
220         }
221
222         var cmd_map = {
223             'cmd_broken' : [
224                 ['oncommand'],
225                 function() { alert(offlineStrings.getString('common.unimplemented')); }
226             ],
227
228             /* File Menu */
229             'cmd_close_window' : [ 
230                 ['oncommand'], 
231                 function() {
232                     JSAN.use('util.widgets');
233                     util.widgets.dispatch('close',window);
234                 }
235             ],
236             'cmd_new_window' : [
237                 ['oncommand'],
238                 function() {
239                     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
240                         getService(Components.interfaces.nsIWindowMediator);
241                     wm.getMostRecentWindow('eg_main').new_tabs(Array('new'));
242                 }
243             ],
244             'cmd_new_tab' : [
245                 ['oncommand'],
246                 function() {
247                     if (obj.new_tab(null,{'focus':true},null) == false)
248                     {
249                         if(window.confirm(offlineStrings.getString('menu.new_tab.max_tab_dialog')))
250                         {
251                             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
252                                 getService(Components.interfaces.nsIWindowMediator);
253                             wm.getMostRecentWindow('eg_main').new_tabs(Array('tab'));
254                         }
255                     }
256                 }
257             ],
258             'cmd_close_tab' : [
259                 ['oncommand'],
260                 function() { obj.close_tab(); }
261             ],
262             'cmd_close_all_tabs' : [
263                 ['oncommand'],
264                 function() { obj.close_all_tabs(); }
265             ],
266
267             /* Edit Menu */
268             'cmd_edit_copy_buckets' : [
269                 ['oncommand'],
270                 function(event) {
271                     obj.data.stash_retrieve();
272                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_copy_buckets.tab')},{});
273                 }
274             ],
275             'cmd_edit_volume_buckets' : [
276                 ['oncommand'],
277                 function(event) {
278                     obj.data.stash_retrieve();
279                     obj.command_tab(event,obj.url_prefix(urls.XUL_VOLUME_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_volume_buckets.tab')},{});
280                 }
281             ],
282             'cmd_edit_record_buckets' : [
283                 ['oncommand'],
284                 function(event) {
285                     obj.data.stash_retrieve();
286                     obj.command_tab(event,obj.url_prefix(urls.XUL_RECORD_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_record_buckets.tab')},{});
287                 }
288             ],
289             'cmd_edit_user_buckets' : [
290                 ['oncommand'],
291                 function(event) {
292                     obj.data.stash_retrieve();
293                     obj.command_tab(event,obj.url_prefix(urls.XUL_USER_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_user_buckets.tab')},{});
294                 }
295             ],
296
297
298             'cmd_replace_barcode' : [
299                 ['oncommand'],
300                 function() {
301                     try {
302                         JSAN.use('util.network');
303                         var network = new util.network();
304
305                         var old_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.label'));
306                         if (!old_bc) return;
307     
308                         var copy;
309                         try {
310                             copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
311                             if (typeof copy.ilsevent != 'undefined') throw(copy); 
312                             if (!copy) throw(copy);
313                         } catch(E) {
314                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n');
315                             return;
316                         }
317     
318                         // Why did I want to do this twice?  Because this copy is more fleshed?
319                         try {
320                             copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
321                             if (typeof copy.ilsevent != 'undefined') throw(copy);
322                             if (!copy) throw(copy);
323                         } catch(E) {
324                             try { alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n' + (typeof E.ilsevent == 'undefined' ? '' : E.textcode + ' : ' + E.desc)); } catch(F) { alert(E + '\n' + F); }
325                             return;
326                         }
327     
328                         var new_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.replacement.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.replacement.label'));
329                         new_bc = String( new_bc ).replace(/\s/g,'');
330                         /* Casting a possibly null input value to a String turns it into "null" */
331                         if (!new_bc || new_bc == 'null') {
332                             alert(offlineStrings.getString('menu.cmd_replace_barcode.blank.error'));
333                             return;
334                         }
335     
336                         var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
337                         if (typeof test.ilsevent == 'undefined') {
338                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.duplicate.error', [new_bc]));
339                             return;
340                         } else {
341                             if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
342                                 obj.error.standard_unexpected_error_alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.testing.error', [new_bc]),test);
343                                 return;
344                             }    
345                         }
346
347                         copy.barcode(new_bc); copy.ischanged('1');
348                         var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
349                         if (typeof r.ilsevent != 'undefined') { 
350                             if (r.ilsevent != 0) {
351                                 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
352                                     alert(offlineStrings.getString('menu.cmd_replace_barcode.permission.error'));
353                                 } else {
354                                     obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.error'),r);
355                                 }
356                             }
357                         }
358                     } catch(E) {
359                         obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.failure'),copy);
360                     }
361                 }
362             ],
363
364             /* Search Menu */
365             'cmd_patron_search' : [
366                 ['oncommand'],
367                 function(event) {
368                     obj.set_patron_tab({},{},event);
369                 }
370             ],
371             'cmd_search_opac' : [
372                 ['oncommand'],
373                 function(event) {
374                     obj.data.stash_retrieve();
375                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
376                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {'tab_name':offlineStrings.getString('menu.cmd_search_opac.tab')}, content_params);
377                 }
378             ],
379             'cmd_search_tcn' : [
380                 ['oncommand'],
381                 function(event) {
382                     var tcn = prompt(offlineStrings.getString('menu.cmd_search_tcn.tab'),'',offlineStrings.getString('menu.cmd_search_tcn.prompt'));
383
384                     function spawn_tcn(r,event) {
385                         for (var i = 0; i < r.count; i++) {
386                             var id = r.ids[i];
387                             var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + id;
388                             obj.data.stash_retrieve();
389                             var content_params = { 
390                                 'session' : ses(), 
391                                 'authtime' : ses('authtime'),
392                                 'opac_url' : opac_url,
393                             };
394                             if (i == 0) {
395                                 obj.command_tab(
396                                     event,
397                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
398                                     {'tab_name':tcn}, 
399                                     content_params
400                                 );
401                             } else {
402                                 obj.new_tab(
403                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
404                                     {'tab_name':tcn}, 
405                                     content_params
406                                 );
407                             }
408                         }
409                     }
410
411                     if (tcn) {
412                         JSAN.use('util.network');
413                         var network = new util.network();
414                         var robj = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn]);
415                         if (robj.count != robj.ids.length) throw('FIXME -- FM_BRE_ID_SEARCH_VIA_TCN = ' + js2JSON(robj));
416                         if (robj.count == 0) {
417                             var robj2 = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn,1]);
418                             if (robj2.count == 0) {
419                                 alert(offlineStrings.getFormattedString('menu.cmd_search_tcn.not_found.error', [tcn]));
420                             } else {
421                                 if ( window.confirm(offlineStrings.getFormattedString('menu.cmd_search_tcn.deleted.error', [tcn])) ) {
422                                     spawn_tcn(robj2,event);
423                                 }
424                             }
425                         } else {
426                             spawn_tcn(robj,event);
427                         }
428                     }
429                 }
430             ],
431             'cmd_search_bib_id' : [
432                 ['oncommand'],
433                 function(event) {
434                     var bib_id = prompt(offlineStrings.getString('menu.cmd_search_bib_id.tab'),'',offlineStrings.getString('menu.cmd_search_bib_id.prompt'));
435                     if (!bib_id) return;
436
437                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + bib_id;
438                     var content_params = { 
439                         'session' : ses(), 
440                         'authtime' : ses('authtime'),
441                         'opac_url' : opac_url,
442                     };
443                     obj.command_tab(
444                         event,
445                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
446                         {'tab_name':'#' + bib_id}, 
447                         content_params
448                     );
449                 }
450             ],
451             'cmd_copy_status' : [
452                 ['oncommand'],
453                 function(event) {
454                     obj.data.stash_retrieve();
455                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_STATUS),{},{});
456                 }
457             ],
458
459             /* Circulation Menu */
460             'cmd_patron_register' : [
461                 ['oncommand'],
462                 function(event) {
463
464                     function log_registration(p) {
465                         try {
466                             obj.error.work_log(
467                                 document.getElementById('offlineStrings').getFormattedString(
468                                     'staff.circ.work_log_patron_registration.message',
469                                     [
470                                         ses('staff_usrname'),
471                                         p.family_name(),
472                                         p.card().barcode()
473                                     ]
474                                 ), {
475                                     'au_id' : p.id(),
476                                     'au_family_name' : p.family_name(),
477                                     'au_barcode' : p.card().barcode()
478                                 }
479                             );
480                         } catch(E) {
481                             obj.error.sdump('D_ERROR','Error with work_logging in menu.js, cmd_patron_register:' + E);
482                         }
483                     }
484
485                     function spawn_editor(p) {
486                         var url = urls.XUL_PATRON_EDIT;
487                         var param_count = 0;
488                         for (var i in p) {
489                             if (param_count++ == 0) url += '?'; else url += '&';
490                             url += i + '=' + window.escape(p[i]);
491                         }
492                         var loc = obj.url_prefix( urls.XUL_BROWSER ) + '?url=' + window.escape( obj.url_prefix(url) );
493                         obj.new_tab(
494                             loc, 
495                             {}, 
496                             { 
497                                 'show_print_button' : true , 
498                                 'tab_name' : offline.getString('menu.cmd_patron_register.related.tab'),
499                                 'passthru_content_params' : {
500                                     'spawn_search' : function(s) { obj.spawn_search(s); },
501                                     'spawn_editor' : spawn_editor,
502                                     'on_save' : function(p) { log_registration(p); }
503                                 }
504                             }
505                         );
506                     }
507
508                     obj.data.stash_retrieve();
509                     var loc = obj.url_prefix( urls.XUL_BROWSER ) 
510                         + '?url=' + window.escape( obj.url_prefix(urls.XUL_PATRON_EDIT) );
511                     obj.command_tab(
512                         event,
513                         loc, 
514                         {}, 
515                         { 
516                             'show_print_button' : true , 
517                             'tab_name' : offlineStrings.getString('menu.cmd_patron_register.tab'),
518                             'passthru_content_params' : {
519                                 'ses' : ses(),
520                                 'spawn_search' : function(s) { obj.spawn_search(s); },
521                                 'spawn_editor' : spawn_editor,
522                                 'on_save' : function(p) { log_registration(p); }
523                             }
524                         }
525                     );
526                 }
527             ],
528             'cmd_staged_patrons' : [
529                 ['oncommand'],
530                 function(event) {
531                     obj.data.stash_retrieve();
532                     obj.command_tab(event,obj.url_prefix(urls.XUL_STAGED_PATRONS),{'tab_name':offlineStrings.getString('menu.circulation.staged_patrons.tab')},{});
533                 }
534             ],
535             'cmd_circ_checkin' : [
536                 ['oncommand'],
537                 function(event) { 
538                     obj.data.stash_retrieve();
539                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN),{},{});
540                 }
541             ],
542             'cmd_circ_renew' : [
543                 ['oncommand'],
544                 function(event) { 
545                     obj.data.stash_retrieve();
546                     obj.command_tab(event,obj.url_prefix(urls.XUL_RENEW),{},{});
547                 }
548             ],
549             'cmd_circ_checkout' : [
550                 ['oncommand'],
551                 function(event) { 
552                     obj.data.stash_retrieve();
553                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY),{},{});
554                 }
555             ],
556             'cmd_circ_hold_capture' : [
557                 ['oncommand'],
558                 function(event) { 
559                     obj.data.stash_retrieve();
560                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN)+'?hold_capture=1',{},{});
561                 }
562             ],
563             'cmd_browse_holds' : [
564                 ['oncommand'],
565                 function(event) { 
566                     obj.data.stash_retrieve();
567                     obj.command_tab(event,obj.url_prefix(urls.XUL_HOLDS_BROWSER),{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds.tab') },{});
568                 }
569             ],
570             'cmd_browse_holds_shelf' : [
571                 ['oncommand'],
572                 function(event) { 
573                     obj.data.stash_retrieve();
574                     obj.command_tab(event,obj.url_prefix(urls.XUL_HOLDS_BROWSER)+'?shelf=1',{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds_shelf.tab') },{});
575                 }
576             ],
577             'cmd_circ_hold_pull_list' : [
578                 ['oncommand'],
579                 function(event) { 
580                     obj.data.stash_retrieve();
581                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
582                         obj.url_prefix(urls.XUL_HOLD_PULL_LIST)
583                     );
584                     obj.command_tab(event, loc, {'tab_name' : offlineStrings.getString('menu.cmd_browse_hold_pull_list.tab')} );
585                 }
586             ],
587
588             'cmd_in_house_use' : [
589                 ['oncommand'],
590                 function(event) { 
591                     obj.data.stash_retrieve();
592                     obj.command_tab(event,obj.url_prefix(urls.XUL_IN_HOUSE_USE),{},{});
593                 }
594             ],
595
596             'cmd_scan_item_as_missing_pieces' : [
597                 ['oncommand'],
598                 function() { 
599                     xulG.window.open(obj.url_prefix(urls.XUL_SCAN_ITEM_AS_MISSING_PIECES),'scan_missing_pieces','chrome'); 
600                 }
601             ],
602
603             'cmd_standalone' : [
604                 ['oncommand'],
605                 function() { 
606                     //obj.set_tab(obj.url_prefix(urls.XUL_STANDALONE),{},{});
607                     window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
608                 }
609             ],
610
611             'cmd_local_admin' : [
612                 ['oncommand'],
613                 function(event) { 
614                     //obj.set_tab(obj.url_prefix(urls.XUL_LOCAL_ADMIN)+'?ses='+window.escape(ses())+'&session='+window.escape(ses()),{},{});
615                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
616                         obj.url_prefix( urls.XUL_LOCAL_ADMIN+'?ses='+window.escape(ses())+'&session='+window.escape(ses()) )
617                     );
618                     obj.command_tab(
619                         event,
620                         loc, 
621                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin.tab'), 'browser' : false }, 
622                         { 'no_xulG' : false, 'show_nav_buttons' : true, 'show_print_button' : true } 
623                     );
624
625                 }
626             ],
627
628             'cmd_toggle_meters' : [
629                 ['oncommand'],
630                 function() {
631                     var x = document.getElementById('network_progress');
632                     if (x) x.hidden = ! x.hidden;
633                     var y = document.getElementById('page_progress');
634                     if (y) y.hidden = ! y.hidden;
635                 }
636             ],
637
638             'cmd_local_admin_reports' : [
639                 ['oncommand'],
640                 function(event) { 
641                     var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_REPORTS) + '?ses=' + ses());
642                     obj.command_tab(
643                         event,
644                         loc, 
645                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin_reports.tab'), 'browser' : false }, 
646                         {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons : true } 
647                     );
648                 }
649             ],
650             'cmd_open_vandelay' : [
651                 ['oncommand'],
652                 function(event) { open_eg_web_page('vandelay/vandelay', null, event); }
653             ],
654             'cmd_local_admin_transit_list' : [
655                 ['oncommand'],
656                 function(event) { open_admin_page('transit_list.xul', 'menu.cmd_local_admin_transit_list.tab', false, event); }
657             ],
658             'cmd_local_admin_age_overdue_circulations_to_lost' : [
659                 ['oncommand'],
660                 function(event) { open_admin_page('circ_age_to_lost.xul', 'menu.cmd_local_admin_age_overdue_circulations_to_lost.tab', true, event); }
661             ],
662             'cmd_local_admin_cash_reports' : [
663                 ['oncommand'],
664                 function(event) { open_admin_page('cash_reports.xhtml', 'menu.cmd_local_admin_cash_reports.tab', true, event); }
665             ],
666             'cmd_local_admin_fonts_and_sounds' : [
667                 ['oncommand'],
668                 function(event) { open_admin_page('font_settings.xul', 'menu.cmd_local_admin_fonts_and_sounds.tab', false, event); }
669             ],
670             'cmd_local_admin_printer' : [
671                 ['oncommand'],
672                 function(event) { open_admin_page('printer_settings.html', 'menu.cmd_local_admin_printer.tab', true, event); }
673             ],
674             'cmd_local_admin_do_not_auto_attempt_print_setting' : [
675                 ['oncommand'],
676                 function(event) { 
677                     obj.command_tab(event,obj.url_prefix(urls.XUL_DO_NOT_AUTO_ATTEMPT_PRINT_SETTING),{'tab_name':offlineStrings.getString('menu.cmd_local_admin_do_not_auto_attempt_print_setting.tab')},{});
678                 }
679             ],
680             'cmd_local_admin_closed_dates' : [
681                 ['oncommand'],
682                 function(event) { open_admin_page('closed_dates.xhtml', 'menu.cmd_local_admin_closed_dates.tab', true, event); }
683             ],
684             'cmd_local_admin_copy_locations' : [
685                 ['oncommand'],
686                 function(event) { open_admin_page('copy_locations.xhtml', 'menu.cmd_local_admin_copy_locations.tab', true, event); }
687             ],
688             'cmd_local_admin_lib_settings' : [
689                 ['oncommand'],
690                 function(event) { open_admin_page('org_unit_settings.xhtml', 'menu.cmd_local_admin_lib_settings.tab', true, event); }
691             ],
692             'cmd_local_admin_non_cat_types' : [
693                 ['oncommand'],
694                 function(event) { open_admin_page('non_cat_types.xhtml', 'menu.cmd_local_admin_non_cat_types.tab', true, event); }
695             ],
696             'cmd_local_admin_stat_cats' : [
697                 ['oncommand'],
698                 function(event) { open_admin_page('stat_cat_editor.xhtml', 'menu.cmd_local_admin_stat_cats.tab', true, event); }
699             ],
700             'cmd_local_admin_standing_penalty' : [
701                 ['oncommand'],
702                 function(event) { open_eg_web_page('conify/global/config/standing_penalty', null, event); }
703             ],
704             'cmd_local_admin_grp_penalty_threshold' : [
705                 ['oncommand'],
706                 function(event) { open_eg_web_page('conify/global/permission/grp_penalty_threshold', null, event); }
707             ],
708             'cmd_server_admin_config_rule_circ_duration' : [
709                 ['oncommand'],
710                 function(event) { open_eg_web_page('conify/global/config/rule_circ_duration', null, event); }
711             ],
712             'cmd_server_admin_config_hard_due_date' : [
713                 ['oncommand'],
714                 function(event) { open_eg_web_page('conify/global/config/hard_due_date', null, event); }
715             ],
716             'cmd_server_admin_config_rule_recurring_fine' : [
717                 ['oncommand'],
718                 function(event) { open_eg_web_page('conify/global/config/rule_recurring_fine', null, event); }
719             ],
720             'cmd_server_admin_config_rule_max_fine' : [
721                 ['oncommand'],
722                 function(event) { open_eg_web_page('conify/global/config/rule_max_fine', null, event); }
723             ],
724             'cmd_server_admin_config_rule_age_hold_protect' : [
725                 ['oncommand'],
726                 function(event) { open_eg_web_page('conify/global/config/rule_age_hold_protect', null, event); }
727             ],
728             'cmd_server_admin_config_circ_weights' : [
729                 ['oncommand'],
730                 function(event) { open_eg_web_page('conify/global/config/circ_matrix_weights', null, event); }
731             ],
732             'cmd_server_admin_config_hold_weights' : [
733                 ['oncommand'],
734                 function(event) { open_eg_web_page('conify/global/config/hold_matrix_weights', null, event); }
735             ],
736             'cmd_server_admin_config_weight_assoc' : [
737                 ['oncommand'],
738                 function(event) { open_eg_web_page('conify/global/config/weight_assoc', null, event); }
739             ],
740             'cmd_local_admin_external_text_editor' : [
741                 ['oncommand'],
742                 function() {
743                     var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
744                     var key = 'oils.text_editor.external.cmd';
745                     var has_key = prefs.prefHasUserValue(key);
746                     var value = has_key ? prefs.getCharPref(key) : 'C:\\Windows\\notepad.exe %letter.txt%';
747                     var cmd = window.prompt(
748                         document.getElementById('offlineStrings').getString('text_editor.prompt_for_external_cmd'),
749                         value
750                     );
751                     if (!cmd) { return; }
752                     prefs.setCharPref(key,cmd);
753                 }
754             ],
755             'cmd_local_admin_idl_field_doc' : [
756                 ['oncommand'],
757                 function(event) { open_eg_web_page('conify/global/config/idl_field_doc', null, event); }
758             ],
759             'cmd_local_admin_action_trigger' : [
760                 ['oncommand'],
761                 function(event) { open_eg_web_page('conify/global/action_trigger/event_definition', null, event); }
762             ],
763             'cmd_local_admin_survey' : [
764                 ['oncommand'],
765                 function(event) { open_eg_web_page('conify/global/action/survey', null, event); }
766             ],
767             'cmd_local_admin_barcode_completion' : [
768                 ['oncommand'],
769                 function() { open_eg_web_page('conify/global/config/barcode_completion', 
770                     'menu.local_admin.barcode_completion.tab'); }
771             ],
772             'cmd_local_admin_circ_matrix_matchpoint' : [
773                 ['oncommand'],
774                 function() { open_eg_web_page('conify/global/config/circ_matrix_matchpoint', 
775                     'menu.local_admin.circ_matrix_matchpoint.tab'); }
776             ],
777             'cmd_local_admin_hold_matrix_matchpoint' : [
778                 ['oncommand'],
779                 function() { open_eg_web_page('conify/global/config/hold_matrix_matchpoint', 
780                     'menu.local_admin.hold_matrix_matchpoint.tab'); }
781             ],
782             'cmd_local_admin_copy_location_order' : [
783                 ['oncommand'],
784                 function(event) { open_eg_web_page('conify/global/asset/copy_location_order', null, event); }
785             ],
786             'cmd_local_admin_work_log' : [
787                 ['oncommand'],
788                 function(event) { 
789                     obj.command_tab(
790                         event,
791                         urls.XUL_WORK_LOG,
792                         { 'tab_name' : offlineStrings.getString('menu.local_admin.work_log.tab') },
793                         {}
794                     );
795                 }
796             ],
797             "cmd_local_admin_copy_template": [
798                 ["oncommand"],
799                 function() {
800                     open_eg_web_page("conify/global/asset/copy_template");
801                 }
802             ],
803             'cmd_local_admin_patrons_due_refunds' : [
804                 ['oncommand'],
805                 function(event) {
806                     obj.command_tab(
807                         event,
808                         obj.url_prefix(urls.XUL_PATRONS_DUE_REFUNDS),
809                         { 'tab_name' : offlineStrings.getString('menu.local_admin.patrons_due_refunds.tab') },
810                         {}
811                     );
812                 }
813             ],
814             'cmd_server_admin_org_type' : [
815                 ['oncommand'],
816                 function(event) { open_conify_page('actor/org_unit_type', null, event); }
817             ],
818             'cmd_server_admin_org_unit' : [
819                 ['oncommand'],
820                 function(event) { open_conify_page('actor/org_unit', null, event); }
821             ],
822             'cmd_server_admin_grp_tree' : [
823                 ['oncommand'],
824                 function(event) { open_conify_page('permission/grp_tree', null, event); }
825             ],
826             'cmd_server_admin_perm_list' : [
827                 ['oncommand'],
828                 function(event) { open_conify_page('permission/perm_list', null, event); }
829             ],
830             'cmd_server_admin_copy_status' : [
831                 ['oncommand'],
832                 function(event) { open_conify_page('config/copy_status', null, event); }
833             ],
834             'cmd_server_admin_marc_code' : [
835                 ['oncommand'],
836                 function(event) { open_eg_web_page('conify/global/config/record_attr_definition', null, event); }
837             ],
838             'cmd_server_admin_coded_value_map' : [
839                 ['oncommand'],
840                 function(event) { open_eg_web_page('conify/global/config/coded_value_map', null, event); }
841             ],
842             'cmd_server_admin_acn_prefix' : [
843                 ['oncommand'],
844                 function(event) { open_eg_web_page('conify/global/config/acn_prefix', null, event); }
845             ],
846             'cmd_server_admin_acn_suffix' : [
847                 ['oncommand'],
848                 function(event) { open_eg_web_page('conify/global/config/acn_suffix', null, event); }
849             ],
850             'cmd_server_admin_billing_type' : [
851                 ['oncommand'],
852                 function(event) { open_eg_web_page('conify/global/config/billing_type', null, event); }
853             ],
854             'cmd_server_admin_acq_invoice_item_type' : [
855                 ['oncommand'],
856                 function(event) { open_eg_web_page('conify/global/acq/invoice_item_type', null, event); }
857             ],
858             'cmd_server_admin_acq_invoice_payment_method' : [
859                 ['oncommand'],
860                 function(event) { open_eg_web_page('conify/global/acq/invoice_payment_method', null, event); }
861             ],
862             'cmd_server_admin_acq_lineitem_alert' : [
863                 ['oncommand'],
864                 function(event) { open_eg_web_page('conify/global/acq/lineitem_alert', null, event); }
865             ],
866             'cmd_server_admin_acq_lineitem_marc_attr_def' : [
867                 ['oncommand'],
868                 function(event) { open_eg_web_page('conify/global/acq/lineitem_marc_attr_def', null, event); }
869             ],
870             'cmd_server_admin_acq_fund_tag' : [
871                 ['oncommand'],
872                 function(event) { open_eg_web_page('conify/global/acq/fund_tag', null, event); }
873             ],
874             'cmd_server_admin_acq_cancel_reason' : [
875                 ['oncommand'],
876                 function(event) { open_eg_web_page('conify/global/acq/cancel_reason', null, event); }
877             ],
878             'cmd_server_admin_acq_claim_type' : [
879                 ['oncommand'],
880                 function(event) { open_eg_web_page('conify/global/acq/claim_type', null, event); }
881             ],
882             'cmd_server_admin_acq_claim_event_type' : [
883                 ['oncommand'],
884                 function(event) { open_eg_web_page('conify/global/acq/claim_event_type', null, event); }
885             ],
886             'cmd_server_admin_acq_claim_policy' : [
887                 ['oncommand'],
888                 function(event) { open_eg_web_page('conify/global/acq/claim_policy', null, event); }
889             ],
890             'cmd_server_admin_acq_claim_policy_action' : [
891                 ['oncommand'],
892                 function(event) { open_eg_web_page('conify/global/acq/claim_policy_action', null, event); }
893             ],
894             'cmd_server_admin_acq_fund' : [
895                 ['oncommand'],
896                 function(event) { open_eg_web_page('acq/fund/list', null, event); }
897             ],
898             'cmd_server_admin_acq_funding_source' : [
899                 ['oncommand'],
900                 function(event) { open_eg_web_page('acq/funding_source/list', null, event); }
901             ],
902             'cmd_server_admin_acq_provider' : [
903                 ['oncommand'],
904                 function(event) { open_eg_web_page('conify/global/acq/provider', null, event); }
905             ],
906             'cmd_server_admin_acq_edi_account' : [
907                 ['oncommand'],
908                 function(event) { open_eg_web_page('conify/global/acq/edi_account', null, event); }
909             ],
910             'cmd_server_admin_acq_edi_message' : [
911                 ['oncommand'],
912                 function(event) { open_eg_web_page('acq/po/edi_messages', null, event); }
913             ],
914             'cmd_server_admin_acq_currency_type' : [
915                 ['oncommand'],
916                 function(event) { open_eg_web_page('acq/currency_type/list', null, event); }
917             ],
918             'cmd_server_admin_acq_exchange_rate' : [
919                 ['oncommand'],
920                 function(event) { open_eg_web_page('conify/global/acq/exchange_rate', null, event); }
921             ],
922             'cmd_server_admin_acq_distrib_formula' : [
923                 ['oncommand'],
924                 function(event) { open_eg_web_page('conify/global/acq/distribution_formula', null, event); }
925             ],
926             'cmd_server_admin_z39_source' : [
927                 ['oncommand'],
928                 function(event) { open_eg_web_page('conify/global/config/z3950_source', null, event); }
929             ],
930             'cmd_server_admin_circ_mod' : [
931                 ['oncommand'],
932                 function(event) { open_eg_web_page('conify/global/config/circ_modifier', null, event); }
933             ],
934             'cmd_server_admin_global_flag' : [
935                 ['oncommand'],
936                 function(event) { open_eg_web_page('conify/global/config/global_flag', null, event); }
937             ],
938             'cmd_server_admin_org_unit_setting_type' : [
939                 ['oncommand'],
940                 function(event) { open_eg_web_page('conify/global/config/org_unit_setting_type', null, event); }
941             ],
942             'cmd_server_admin_usr_setting_type' : [
943                 ['oncommand'],
944                 function(event) { open_eg_web_page('conify/global/config/usr_setting_type', null, event); }
945             ],
946             'cmd_server_admin_booking_resource': [
947                 ['oncommand'],
948                 function(event) { open_eg_web_page('conify/global/booking/resource', null, event); }
949             ],
950             'cmd_server_admin_booking_resource_type': [
951                 ['oncommand'],
952                 function(event) { open_eg_web_page('conify/global/booking/resource_type', null, event); }
953             ],
954             'cmd_server_admin_booking_resource_attr': [
955                 ['oncommand'],
956                 function(event) { open_eg_web_page('conify/global/booking/resource_attr', null, event); }
957             ],
958             'cmd_server_admin_booking_resource_attr_value': [
959                 ['oncommand'],
960                 function(event) { open_eg_web_page('conify/global/booking/resource_attr_value', null, event); }
961             ],
962             'cmd_server_admin_booking_resource_attr_map': [
963                 ['oncommand'],
964                 function(event) { open_eg_web_page('conify/global/booking/resource_attr_map', null, event); }
965             ],
966             'cmd_acq_create_invoice' : [
967                 ['oncommand'],
968                 function(event) { open_eg_web_page('acq/invoice/view?create=1', 'menu.cmd_acq_create_invoice.tab', event); }
969             ],
970             'cmd_acq_view_my_pl' : [
971                 ['oncommand'],
972                 function(event) { open_eg_web_page('acq/search/unified?ca=pl', 'menu.cmd_acq_unified_search.tab', event); }
973             ],
974             'cmd_acq_view_local_po' : [
975                 ['oncommand'],
976                 function(event) { open_eg_web_page('acq/search/unified?ca=po', 'menu.cmd_acq_unified_search.tab', event); }
977             ],
978             'cmd_acq_create_po' : [
979                 ['oncommand'],
980                 function(event) { open_eg_web_page('acq/po/create', 'menu.cmd_acq_po.tab', event); }
981             ],
982             'cmd_acq_view_local_inv' : [
983                 ['oncommand'],
984                 function(event) { open_eg_web_page('acq/search/unified?ca=inv', 'menu.cmd_acq_unified_search.tab', event); }
985             ],
986             'cmd_acq_user_requests' : [
987                 ['oncommand'],
988                 function(event) { open_eg_web_page('acq/picklist/user_request', 'menu.cmd_acq_user_requests.tab', event); }
989             ],
990             'cmd_acq_upload' : [
991                 ['oncommand'],
992                 function(event) { open_eg_web_page('acq/picklist/upload', 'menu.cmd_acq_upload.tab', event); }
993             ],
994             'cmd_acq_bib_search' : [
995                 ['oncommand'],
996                 function(event) { open_eg_web_page('acq/picklist/bib_search', 'menu.cmd_acq_bib_search.tab', event); }
997             ],
998             'cmd_acq_unified_search' : [
999                 ['oncommand'],
1000                 function(event) { open_eg_web_page('acq/search/unified', 'menu.cmd_acq_unified_search.tab', event); }
1001             ],
1002             'cmd_acq_from_bib' : [
1003                 ['oncommand'],
1004                 function(event) { open_eg_web_page('acq/picklist/from_bib', 'menu.cmd_acq_from_bib.tab', event); }
1005             ],
1006             'cmd_acq_new_brief_record' : [
1007                 ['oncommand'],
1008                 function(event) { open_eg_web_page('acq/picklist/brief_record', 'menu.cmd_acq_new_brief_record.tab', event); }
1009             ],
1010             'cmd_acq_claim_eligible' : [
1011                 ['oncommand'],
1012                 function(event) { open_eg_web_page('acq/financial/claim_eligible', 'menu.cmd_acq_claim_eligible.tab', event); }
1013             ],
1014             'cmd_booking_reservation' : [
1015                 ['oncommand'],
1016                 function(event) {
1017                     open_eg_web_page(
1018                         "/eg/booking/reservation",
1019                         "menu.cmd_booking_reservation.tab",
1020                         event
1021                     );
1022                 }
1023             ],
1024             'cmd_booking_pull_list' : [
1025                 ['oncommand'],
1026                 function(event) {
1027                     open_eg_web_page(
1028                         "/eg/booking/pull_list",
1029                         "menu.cmd_booking_pull_list.tab",
1030                         event
1031                     );
1032                 }
1033             ],
1034             'cmd_booking_capture' : [
1035                 ['oncommand'],
1036                 function(event) {
1037                     open_eg_web_page(
1038                         "/eg/booking/capture",
1039                         "menu.cmd_booking_capture.tab",
1040                         event
1041                     );
1042                 }
1043             ],
1044             'cmd_booking_reservation_pickup' : [
1045                 ['oncommand'],
1046                 function(event) {
1047                     open_eg_web_page(
1048                         "/eg/booking/pickup",
1049                         "menu.cmd_booking_reservation_pickup.tab",
1050                         event
1051                     );
1052                 }
1053             ],
1054             'cmd_booking_reservation_return' : [
1055                 ['oncommand'],
1056                 function(event) {
1057                     open_eg_web_page(
1058                         "/eg/booking/return",
1059                         "menu.cmd_booking_reservation_return.tab",
1060                         event
1061                     );
1062                 }
1063             ],
1064             'cmd_reprint' : [
1065                 ['oncommand'],
1066                 function() {
1067                     try {
1068                         JSAN.use('util.print'); var print = new util.print();
1069                         print.reprint_last();
1070                     } catch(E) {
1071                         alert(E);
1072                     }
1073                 }
1074             ],
1075
1076             'cmd_retrieve_last_patron' : [
1077                 ['oncommand'],
1078                 function(event) {
1079                     obj.data.stash_retrieve();
1080                     if (!obj.data.last_patron) {
1081                         alert(offlineStrings.getString('menu.cmd_retrieve_last_patron.session.error'));
1082                         return;
1083                     }
1084                     var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1085                     var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1086                     obj.command_tab( event, url, {}, { 'id' : obj.data.last_patron } );
1087                 }
1088             ],
1089             
1090             'cmd_retrieve_last_record' : [
1091                 ['oncommand'],
1092                 function(event) {
1093                     obj.data.stash_retrieve();
1094                     if (!obj.data.last_record) {
1095                         alert(offlineStrings.getString('menu.cmd_retrieve_last_record.session.error'));
1096                         return;
1097                     }
1098                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + obj.data.last_record;
1099                     var content_params = {
1100                         'session' : ses(),
1101                         'authtime' : ses('authtime'),
1102                         'opac_url' : opac_url,
1103                     };
1104                     obj.command_tab(
1105                         event,
1106                         obj.url_prefix(urls.XUL_OPAC_WRAPPER),
1107                         {'tab_name' : offlineStrings.getString('menu.cmd_retrieve_last_record.status')},
1108                         content_params
1109                     );
1110                 }
1111             ],
1112
1113             'cmd_verify_credentials' : [
1114                 ['oncommand'],
1115                 function(event) {
1116                     obj.command_tab(
1117                         event,
1118                         obj.url_prefix(urls.XUL_VERIFY_CREDENTIALS),
1119                         { 'tab_name' : offlineStrings.getString('menu.cmd_verify_credentials.tabname') },
1120                         {}
1121                     );
1122                 }
1123             ],
1124
1125             /* Cataloging Menu */
1126             'cmd_z39_50_import' : [
1127                 ['oncommand'],
1128                 function(event) {
1129                     obj.data.stash_retrieve();
1130                     obj.command_tab(event,obj.url_prefix(urls.XUL_Z3950_IMPORT),{},{});
1131                 }
1132             ],
1133             'cmd_create_marc' : [
1134                 ['oncommand'],
1135                 function(event) {
1136                     obj.data.stash_retrieve();
1137                     obj.command_tab(event,obj.url_prefix(urls.XUL_MARC_NEW),{},{});
1138                 }
1139             ],
1140
1141             'cmd_authority_manage' : [
1142                 ['oncommand'],
1143                 function(event) {
1144                     obj.data.stash_retrieve();
1145                     obj.command_tab(event,obj.url_prefix(urls.AUTHORITY_MANAGE),{},{});
1146                 }
1147             ],
1148
1149             'cmd_marc_batch_edit' : [
1150                 ['oncommand'],
1151                 function(event) {
1152                     obj.command_tab(
1153                         event,
1154                         obj.url_prefix(urls.MARC_BATCH_EDIT),{
1155                             'tab_name' : offlineStrings.getString('menu.cmd_marc_batch_edit.tab')
1156                         },
1157                         {}
1158                     );
1159                 }
1160             ],
1161
1162             /* Admin menu */
1163             'cmd_change_session' : [
1164                 ['oncommand'],
1165                 function() {
1166                     try {
1167                         obj.data.stash_retrieve();
1168                         JSAN.use('util.network'); var network = new util.network();
1169                         var temp_au = js2JSON( obj.data.list.au[0] );
1170                         var temp_ses = js2JSON( obj.data.session );
1171                         if (obj.data.list.au.length > 1) {
1172                             obj.data.list.au = [ obj.data.list.au[1] ];
1173                             obj.data.stash('list');
1174                             network.reset_titlebars( obj.data );
1175                             network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
1176                             obj.data.session = obj.data.previous_session;
1177                             obj.data.menu_perms = obj.data.previous_menu_perms;
1178                             obj.data.stash('session');
1179                             obj.data.stash('menu_perms');
1180                             try {
1181                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1182                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
1183                                 var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
1184                                 var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
1185                                 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
1186
1187                                 cookieSvc.setCookieString(cookieUri, null, "ses="+obj.data.session.key, null);
1188                                 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+obj.data.session.key, null);
1189
1190                         } catch(E) {
1191                             alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
1192                         }
1193
1194                         } else {
1195                             if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
1196                                 obj.data.stash_retrieve();
1197                                 obj.data.list.au[1] = JSON2js( temp_au );
1198                                 obj.data.stash('list');
1199                                 obj.data.previous_session = JSON2js( temp_ses );
1200                                 obj.data.previous_menu_perms = obj.data.menu_perms;
1201                                 obj.data.menu_perms = false;
1202                                 obj.data.stash('previous_session');
1203                                 obj.data.stash('previous_menu_perms');
1204                                 obj.data.stash('menu_perms');
1205                             }
1206                         }
1207                         network.set_user_status();
1208                     } catch(E) {
1209                         obj.error.standard_unexpected_error_alert('cmd_change_session',E);
1210                     }
1211                 }
1212             ],
1213             'cmd_manage_offline_xacts' : [
1214                 ['oncommand'],
1215                 function(event) {
1216                     obj.command_tab(event,obj.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS), {'tab_name' : offlineStrings.getString('menu.cmd_manage_offline_xacts.tab')}, {});
1217                 }
1218             ],
1219             'cmd_download_patrons' : [
1220                 ['oncommand'],
1221                 function() {
1222                     try {
1223                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1224                         var x = new XMLHttpRequest();
1225                         var url = 'http://' + XML_HTTP_SERVER + '/standalone/list.txt';
1226                         x.open("GET",url,false);
1227                         x.send(null);
1228                         if (x.status == 200) {
1229                             JSAN.use('util.file'); var file = new util.file('offline_patron_list');
1230                             file.write_content('truncate',x.responseText);
1231                             file.close();
1232                             file = new util.file('offline_patron_list.date');
1233                             file.write_content('truncate',new Date());
1234                             file.close();
1235                             alert(offlineStrings.getString('menu.cmd_download_patrons.complete.status'));
1236                         } else {
1237                             alert(offlineStrings.getFormattedString('menu.cmd_download_patrons.error', [x.status, x.statusText]));
1238                         }
1239                     } catch(E) {
1240                         obj.error.standard_unexpected_error_alert('cmd_download_patrons',E);
1241                     }
1242                 }
1243             ],
1244             'cmd_adv_user_edit' : [
1245                 ['oncommand'],
1246                 function(event) {
1247                     obj.data.stash_retrieve();
1248                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY), {}, { 'perm_editor' : true });
1249                 }
1250             ],
1251             'cmd_print_list_template_edit' : [
1252                 ['oncommand'],
1253                 function(event) {
1254                     obj.data.stash_retrieve();
1255                     obj.command_tab(event,obj.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {});
1256                 }
1257             ],
1258             'cmd_stat_cat_edit' : [
1259                 ['oncommand'],
1260                 function(event) {
1261                     obj.data.stash_retrieve();
1262                     obj.command_tab(event,obj.url_prefix(urls.XUL_STAT_CAT_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_stat_cat_edit.tab')},{});
1263                 }
1264             ],
1265             'cmd_non_cat_type_edit' : [
1266                 ['oncommand'],
1267                 function(event) {
1268                     obj.data.stash_retrieve();
1269                     obj.command_tab(event,obj.url_prefix(urls.XUL_NON_CAT_LABEL_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_non_cat_type_edit.tab')},{});
1270                 }
1271             ],
1272             'cmd_copy_location_edit' : [
1273                 ['oncommand'],
1274                 function(event) {
1275                     obj.data.stash_retrieve();
1276                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_LOCATION_EDIT) + '?ses='+window.escape(ses()),{'tab_name' : offlineStrings.getString('menu.cmd_copy_location_edit.tab')},{});
1277                 }
1278             ],
1279             'cmd_test' : [
1280                 ['oncommand'],
1281                 function(event) {
1282                     obj.data.stash_retrieve();
1283                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
1284                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
1285                 }
1286             ],
1287             'cmd_test_html' : [
1288                 ['oncommand'],
1289                 function(event) {
1290                     obj.data.stash_retrieve();
1291                     obj.command_tab(event,obj.url_prefix(urls.TEST_HTML) + '?ses='+window.escape(ses()),{ 'browser' : true },{});
1292                 }
1293             ],
1294             'cmd_test_xul' : [
1295                 ['oncommand'],
1296                 function(event) {
1297                     obj.data.stash_retrieve();
1298                     obj.command_tab(event,obj.url_prefix(urls.TEST_XUL) + '?ses='+window.escape(ses()),{ 'browser' : false },{});
1299                 }
1300             ],
1301             'cmd_console' : [
1302                 ['oncommand'],
1303                 function(event) {
1304                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_CONSOLE),{'tab_name' : offlineStrings.getString('menu.cmd_console.tab')},{});
1305                 }
1306             ],
1307             'cmd_shell' : [
1308                 ['oncommand'],
1309                 function(event) {
1310                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_SHELL),{'tab_name' : offlineStrings.getString('menu.cmd_shell.tab')},{});
1311                 }
1312             ],
1313             'cmd_xuleditor' : [
1314                 ['oncommand'],
1315                 function(event) {
1316                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_XULEDITOR),{'tab_name' : offlineStrings.getString('menu.cmd_xuleditor.tab')},{});
1317                 }
1318             ],
1319             'cmd_fieldmapper' : [
1320                 ['oncommand'],
1321                 function(event) {
1322                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_FIELDMAPPER),{'tab_name' : offlineStrings.getString('menu.cmd_fieldmapper.tab')},{});
1323                 }
1324             ],
1325             'cmd_survey_wizard' : [
1326                 ['oncommand'],
1327                 function() {
1328                     obj.data.stash_retrieve();
1329                     xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome'); 
1330                 }
1331             ],
1332             'cmd_public_opac' : [
1333                 ['oncommand'],
1334                 function(event) {
1335                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
1336                         obj.url_prefix(urls.remote)
1337                     );
1338                     obj.command_tab(
1339                         event,
1340                         loc, 
1341                         {'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
1342                         { 'no_xulG' : true, 'show_nav_buttons' : true, 'show_print_button' : true } 
1343                     );
1344                 }
1345             ],
1346             'cmd_clear_cache' : [
1347                 ['oncommand'],
1348                 function clear_the_cache() {
1349                     try {
1350                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1351                         var cacheClass         = Components.classes["@mozilla.org/network/cache-service;1"];
1352                         var cacheService    = cacheClass.getService(Components.interfaces.nsICacheService);
1353                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
1354                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
1355                     } catch(E) {
1356                         dump(E+'\n');alert(E);
1357                     }
1358                 }
1359             ],
1360             'cmd_restore_all_tabs' : [
1361                 ['oncommand'],
1362                 function() {
1363                     var tabs = obj.controller.view.tabs;
1364                     for (var i = 0; i < tabs.childNodes.length; i++) {
1365                         tabs.childNodes[i].hidden = false;
1366                     }
1367                 }
1368             ],
1369             'cmd_extension_manager' : [
1370                 ['oncommand'],
1371                 function(event) {
1372                     obj.command_tab(event,'chrome://mozapps/content/extensions/extensions.xul?type=extensions',{'tab_name' : offlineStrings.getString('menu.cmd_extension_manager.tab')},{});
1373                 }
1374             ],
1375             'cmd_theme_manager' : [
1376                 ['oncommand'],
1377                 function(event) {
1378                     obj.command_tab(event,'chrome://mozapps/content/extensions/extensions.xul?type=themes',{'tab_name' : offlineStrings.getString('menu.cmd_theme_manager.tab')},{});
1379                 }
1380             ],
1381             'cmd_about_config' : [
1382                 ['oncommand'],
1383                 function(event) {
1384                     obj.command_tab(event,'chrome://global/content/config.xul',{'tab_name' : 'about:config'},{});
1385                 }
1386             ],
1387             'cmd_shutdown' : [
1388                 ['oncommand'],
1389                 function() {
1390                     var confirm_string = offlineStrings.getString('menu.cmd_shutdown.prompt');
1391                     obj.data.stash_retrieve();
1392                     if (typeof obj.data.unsaved_data != 'undefined') {
1393                         if (obj.data.unsaved_data > 0) {
1394                             confirm_string = offlineStrings.getString('menu.shutdown.unsaved_data_warning');
1395                         }
1396                     }
1397                     if (window.confirm(confirm_string)) {
1398                         obj.data.unsaved_data = 0; // just in case the program doesn't close somehow
1399                         obj.data.stash('unsaved_data');
1400                         dump('forcing data.unsaved_data == ' + obj.data.unsaved_data + '\n');
1401                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1402                         var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1403                         var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1404                         var enumerator = windowManagerInterface.getEnumerator(null);
1405                         var w; // close all other windows
1406                         while ( w = enumerator.getNext() ) {
1407                             if (w != window) {
1408                                 if (w.xulG) { w.close(); } // FIXME: kludge so we don't close Firefox windows as an extension.  We should define a @windowtype for all the staff client windows and have the enumerator just pull those
1409                             }
1410                         }
1411                         window.close();
1412                     }
1413                 }
1414             ],
1415             'cmd_hotkeys_toggle' : [
1416                 ['oncommand'],
1417                 function() {
1418                     // Easy enough, toggle disabled on the keyset
1419                     var keyset = document.getElementById("menu_frame_keys");
1420                     var disabled = (keyset.getAttribute("disabled") == "true") ? "false" : "true";
1421                     if(disabled == "true")
1422                         keyset.setAttribute("disabled", "true");
1423                     else
1424                         keyset.removeAttribute("disabled");
1425                     // Then find every menuitem/toolbarbutton for this command for a graphical hint
1426                     var controls = document.getElementsByAttribute("command","cmd_hotkeys_toggle");
1427                     for(var i = 0; i < controls.length; i++)
1428                         controls[i].setAttribute("checked",disabled);
1429                 }
1430             ],
1431             'cmd_hotkeys_set' : [
1432                 ['oncommand'],
1433                 function(event) {
1434                     obj.set_menu_hotkeys(event.explicitOriginalTarget.getAttribute('value'));
1435                 }
1436             ],
1437             'cmd_hotkeys_setworkstation' : [
1438                 ['oncommand'],
1439                 function() {
1440                     xulG.pref.setCharPref('open-ils.menu.hotkeyset', obj.data.current_hotkeyset);
1441                 }
1442             ],
1443             'cmd_hotkeys_clearworkstation' : [
1444                 ['oncommand'],
1445                 function() {
1446                     if(xulG.pref.prefHasUserValue('open-ils.menu.hotkeyset'))
1447                         xulG.pref.clearUserPref('open-ils.menu.hotkeyset');
1448                 }
1449             ],
1450             'cmd_toolbar_set' : [
1451                 ['oncommand'],
1452                 function(event) {
1453                     var newToolbar = event.explicitOriginalTarget.getAttribute('value');
1454                     var toolbox = document.getElementById('main_toolbox');
1455                     var toolbars = toolbox.getElementsByTagName('toolbar');
1456                     for(var i = 0; i < toolbars.length; i++) {
1457                         if(toolbars[i].id == 'toolbar_' + newToolbar)
1458                             toolbars[i].setAttribute('hidden', 'false');
1459                         else
1460                             toolbars[i].setAttribute('hidden', 'true');
1461                     }
1462                     obj.toolbar = newToolbar;
1463                 }
1464             ],
1465             'cmd_toolbar_mode_set' : [
1466                 ['oncommand'],
1467                 function(event) {
1468                     var newMode = event.explicitOriginalTarget.getAttribute('value');
1469                     var toolbox = document.getElementById('main_toolbox');
1470                     var toolbars = toolbox.getElementsByTagName('toolbar');
1471                     for(var i = 0; i < toolbars.length; i++)
1472                         toolbars[i].setAttribute("mode",newMode);
1473                     obj.toolbar_mode = newMode;
1474                 }
1475             ],
1476             'cmd_toolbar_size_set' : [
1477                 ['oncommand'],
1478                 function(event) {
1479                     var newSize = event.explicitOriginalTarget.getAttribute('value');
1480                     var toolbox = document.getElementById('main_toolbox');
1481                     var toolbars = toolbox.getElementsByTagName('toolbar');
1482                     for(var i = 0; i < toolbars.length; i++)
1483                         toolbars[i].setAttribute("iconsize",newSize);
1484                     obj.toolbar_size = newSize;
1485                 }
1486             ],
1487             'cmd_toolbar_label_position_set' : [
1488                 ['oncommand'],
1489                 function(event) {
1490                     var altPosition = (event.explicitOriginalTarget.getAttribute('value') == "under");
1491                     var toolbox = document.getElementById('main_toolbox');
1492                     var toolbars = toolbox.getElementsByTagName('toolbar');
1493                     for(var i = 0; i < toolbars.length; i++) {
1494                         if(altPosition)
1495                             addCSSClass(toolbars[i], 'labelbelow');
1496                         else
1497                             removeCSSClass(toolbars[i], 'labelbelow');
1498                     }
1499                     obj.toolbar_labelpos = (altPosition ? "under" : "side");
1500                 }
1501             ],
1502             'cmd_toolbar_setworkstation' : [
1503                 ['oncommand'],
1504                 function() {
1505                 xulG.pref.setCharPref('open-ils.menu.toolbar', obj.toolbar);
1506                 xulG.pref.setCharPref('open-ils.menu.toolbar.iconsize', obj.toolbar_size);
1507                 xulG.pref.setCharPref('open-ils.menu.toolbar.mode', obj.toolbar_mode);
1508                 xulG.pref.setBoolPref('open-ils.menu.toolbar.labelbelow', (obj.toolbar_labelpos == "under"));
1509                 }
1510             ],
1511             'cmd_toolbar_clearworkstation' : [
1512                 ['oncommand'],
1513                 function() {
1514                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar'))
1515                         xulG.pref.clearUserPref('open-ils.menu.toolbar');
1516                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.iconsize'))
1517                         xulG.pref.clearUserPref('open-ils.menu.toolbar.iconsize');
1518                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.mode'))
1519                         xulG.pref.clearUserPref('open-ils.menu.toolbar.mode');
1520                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.labelbelow'))
1521                         xulG.pref.clearUserPref('open-ils.menu.toolbar.labelbelow');
1522                 }
1523             ],
1524         };
1525
1526         JSAN.use('util.controller');
1527         var cmd;
1528         obj.controller = new util.controller();
1529         obj.controller.init( { 'window_knows_me_by' : 'g.menu.controller', 'control_map' : cmd_map } );
1530
1531         obj.controller.view.tabbox = window.document.getElementById('main_tabbox');
1532         // Despite what the docs say:
1533         // The "tabs" element need not be the first child
1534         // The "panels" element need not be the second/last
1535         // Nor need they be the only ones there.
1536         // Thus, use the IDs for robustness.
1537         obj.controller.view.tabs = window.document.getElementById('main_tabs');
1538         obj.controller.view.panels = window.document.getElementById('main_panels');
1539         obj.controller.view.tabscroller = window.document.getElementById('main_tabs_scrollbox');
1540         if(params['firstURL']) {
1541             obj.new_tab(params['firstURL'],{'focus':true},null);
1542         }
1543         else {
1544             obj.new_tab(null,{'focus':true},null);
1545         }
1546     },
1547
1548     'spawn_search' : function(s) {
1549         var obj = this;
1550         obj.error.sdump('D_TRACE', offlineStrings.getFormattedString('menu.spawn_search.msg', [js2JSON(s)]) ); 
1551         obj.new_patron_tab( {}, { 'doit' : 1, 'query' : js2JSON(s) } );
1552     },
1553
1554     'close_all_tabs' : function() {
1555         var obj = this;
1556         try {
1557             var count = obj.controller.view.tabs.childNodes.length;
1558             for (var i = 1; i < count; i++) obj.close_tab();
1559             setTimeout( function(){ obj.controller.view.tabs.firstChild.focus(); }, 0);
1560         } catch(E) {
1561             obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.close_all_tabs.error'),E);
1562         }
1563     },
1564
1565     'close_tab' : function (specific_idx) {
1566         var idx = specific_idx || this.controller.view.tabs.selectedIndex;
1567         var panel = this.controller.view.panels.childNodes[ idx ];
1568
1569         var tab = this.controller.view.tabs.getItemAtIndex( idx );
1570         var id = tab.getAttribute('id');
1571         if (typeof this.tab_semaphores[id] != 'undefined') {
1572             if (this.tab_semaphores[id] > 0) {
1573                 var confirmation = window.confirm(offlineStrings.getString('menu.close_tab.unsaved_data_warning'));
1574                 if (!confirmation) { return; }
1575                 oils_unsaved_data_P( this.tab_semaphores[id] );
1576             }
1577             delete this.tab_semaphores[id];
1578         }
1579
1580         this.controller.view.tabs.removeItemAt(idx);
1581         this.controller.view.panels.removeChild(panel);
1582         if(this.controller.view.tabs.childNodes.length > idx) {
1583             this.controller.view.tabbox.selectedIndex = idx;
1584         }
1585         else {
1586             this.controller.view.tabbox.selectedIndex = idx - 1;
1587         }
1588         this.controller.view.tabscroller.ensureElementIsVisible(this.controller.view.tabs.selectedItem);
1589         this.update_all_tab_names();
1590         // Make sure we keep at least one tab open.
1591         if(this.controller.view.tabs.childNodes.length == 1) {
1592             this.new_tab(); 
1593         }
1594     },
1595     
1596     'update_all_tab_names' : function() {
1597         var doAccessKeys = !xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs');
1598         for(var i = 1; i < this.controller.view.tabs.childNodes.length; ++i) {
1599             var tab = this.controller.view.tabs.childNodes[i];
1600             tab.curindex = i;
1601             tab.label = i + ' ' + tab.origlabel;
1602             if(doAccessKeys && offlineStrings.testString('menu.tab' + i + '.accesskey')) {
1603                 tab.accessKey = offlineStrings.getString('menu.tab' + i + '.accesskey');
1604             }
1605         }
1606     },
1607
1608     'command_tab' : function(event,url,params,content_params) {
1609         var newTab = false;
1610         var myEvent = event;
1611         if(event && event.sourceEvent) myEvent = event.sourceEvent;
1612         // Note: The last event is not supposed to be myEvent in this if.
1613         if(myEvent && myEvent.explicitOriginalTarget.nodeName.match(/toolbarbutton/) && myEvent.explicitOriginalTarget.command == event.originalTarget.id) {
1614             var value = xulG.pref.getIntPref('ui.key.accelKey');
1615             switch(value) {
1616                 case 17:
1617                     newTab = myEvent.ctrlKey;
1618                     break;
1619                 case 18:
1620                     newTab = myEvent.altKey;
1621                     break;
1622                 case 224:
1623                     newTab = myEvent.metaKey;
1624                     break;
1625             }
1626             try {
1627                 if(xulG.pref.getBoolPref('open-ils.toolbar.defaultnewtab')) {
1628                     newTab = !newTab;
1629                 }
1630             }
1631             catch (e) {
1632             }
1633         }
1634         if(newTab) {
1635             this.new_tab(url,params,content_params);
1636         }
1637         else {
1638             this.set_tab(url,params,content_params);
1639         }
1640     },
1641
1642     'new_tab' : function(url,params,content_params) {
1643         var obj = this;
1644         var max_tabs = 0;
1645         try {
1646             var max_tabs = xulG.pref.getIntPref('open-ils.window_max_tabs') || max_tabs;
1647         }
1648         catch (e) {}
1649         if(max_tabs > 0 && this.controller.view.tabs.childNodes.length > max_tabs) return false;
1650         var tab = this.w.document.createElement('tab');
1651         var panel = this.w.document.createElement('tabpanel');
1652         var tabscroller = this.controller.view.tabscroller;
1653         this.controller.view.tabs.appendChild(tab);
1654         this.controller.view.panels.appendChild(panel);
1655         tab.curindex = this.controller.view.tabs.childNodes.length - 1;
1656         if(!xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs')) {
1657             if(offlineStrings.testString('menu.tab' + tab.curindex + '.accesskey')) {
1658                 tab.accessKey = offlineStrings.getString('menu.tab' + tab.curindex + '.accesskey');
1659             }
1660         }
1661         var tabs = this.controller.view.tabs;
1662         tab.addEventListener(
1663             'command',
1664             function() {
1665                 try {
1666                     tabscroller.ensureElementIsVisible(tab);
1667                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1668                     if (panel
1669                         && panel.firstChild 
1670                         && ( panel.firstChild.nodeName == 'iframe' || panel.firstChild.nodeName == 'browser' )
1671                         && panel.firstChild.contentWindow 
1672                     ) {
1673                         var cw = panel.firstChild.contentWindow;
1674                         var help_params = {
1675                             'protocol' : cw.location.protocol,
1676                             'hostname' : cw.location.hostname,
1677                             'port' : cw.location.port,
1678                             'pathname' : cw.location.pathname,
1679                             'src' : ''
1680                         };
1681                         obj.set_help_context(help_params);
1682                         if (typeof cw.default_focus == 'function') {
1683                             cw.default_focus();
1684                         }
1685                     }
1686                 } catch(E) {
1687                     obj.error.sdump('D_ERROR','init_tab_focus_handler: ' + js2JSON(E));
1688                 }
1689             }
1690             ,
1691             false
1692         );
1693         if (!content_params) content_params = {};
1694         if (!params) params = {};
1695         if (!params.tab_name) params.tab_name = offlineStrings.getString('menu.new_tab.tab');
1696         if (!params.nofocus) params.focus = true; /* make focus the default */
1697         try {
1698             if (params.focus) {
1699                 this.controller.view.tabs.selectedItem = tab;
1700                 tabscroller.ensureElementIsVisible(tab);
1701             }
1702             params.index = tab.curindex;
1703             this.set_tab(url,params,content_params);
1704             return true;
1705         } catch(E) {
1706             this.error.sdump('D_ERROR',E);
1707             return false;
1708         }
1709     },
1710
1711     'set_menu_access' : function(perms) {
1712         if(perms === false) return;
1713         var commands = document.getElementById('universal_cmds').getElementsByTagName('command');
1714         var commandperms;
1715 commands:
1716         for (var i = 0; i < commands.length; i++) { 
1717             if (commands[i].hasAttribute('perm')) {
1718                 commandperms = commands[i].getAttribute('perm').split(' ');
1719                 for (var j = 0; j < commandperms.length; j++) {
1720                     if (perms[commandperms[j]]) {
1721                         commands[i].setAttribute('disabled','false');
1722                         continue commands;
1723                     }
1724                 }
1725                 commands[i].setAttribute('disabled','true');
1726             }           
1727         }
1728
1729     },
1730
1731     'set_menu_hotkeys' : function(hotkeyset) {
1732         this.data.stash_retrieve();
1733
1734         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
1735                     getService(Components.interfaces.nsIWindowMediator);
1736         var mainwin = wm.getMostRecentWindow('eg_main');
1737         JSAN.use('util.network');
1738         var network = new util.network();
1739
1740         if(hotkeyset) { // Explicit request
1741             // Store
1742             this.data.current_hotkeyset = hotkeyset;
1743             this.data.stash('current_hotkeyset');
1744             // Then iterate over windows
1745             var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1746             var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1747             var enumerator = windowManagerInterface.getEnumerator('eg_menu');
1748
1749             var w;
1750             while ( w = enumerator.getNext() ) {
1751                 if ( w != window )
1752                     w.g.menu.set_menu_hotkeys();
1753             }
1754         }
1755         else { // Non-explicit request?
1756             if(this.data.current_hotkeyset) // Previous hotkeyset?
1757                 hotkeyset = this.data.current_hotkeyset; // Use it
1758             else { // No previous? We need to decide on one!
1759                 // Load the list so we know if what we are being asked to load is valid.
1760                 var hotkeysets = mainwin.load_hotkey_sets();
1761                 if(!hotkeysets) return; // No sets = nothing to load. Which is probably an error, but meh.
1762                 hotkeysets.has = function(test) {
1763                     for(i = 0; i < this.length; i++) {
1764                         if(this[i] == test) return true;
1765                     }
1766                     return false;
1767                 }; 
1768                 // Try workstation (pref)
1769                 hotkeyset = xulG.pref.getCharPref('open-ils.menu.hotkeyset');
1770
1771                 // Nothing or nothing valid?
1772                 if(!hotkeyset || !hotkeysets.has(hotkeyset)) {
1773                     hotkeyset = this.data.hash.aous['ui.general.hotkeyset'];
1774                 }
1775                 // STILL nothing? Try Default.
1776                 if(!hotkeyset || !hotkeysets.has(hotkeyset)) {
1777                     if(hotkeysets.has('Default'))
1778                         hotkeyset = 'Default';
1779                     else
1780                         return false;
1781                 }
1782                 // And save whatever we are using.
1783                 this.data.current_hotkeyset = hotkeyset;
1784                 this.data.stash('current_hotkeyset');
1785             }
1786         }
1787         // Clear out all the old hotkeys
1788         var keyset = document.getElementById('menu_frame_keys');
1789         var main_menu = document.getElementById('main_menubar');
1790         if(keyset.hasChildNodes()) {
1791             var menuitems = main_menu.getElementsByAttribute('key','*');
1792             while(menuitems.length > 0) {
1793                 var menuitem = menuitems[0];
1794                 menuitem.removeAttribute('key');
1795                 // Trick/force mozilla to re-evaluate the menuitem
1796                 // If you want to take this trick for use *anywhere* in *any* project, regardless of licensing, please do
1797                 // Because it was a PITA to figure out
1798                 menuitem.style.display = 'none'; // Hide the item to force menu to clear spot
1799                 menuitem.setAttribute('acceltext', ''); // Set acceltext to blank string outright
1800                 menuitem.removeAttribute('acceltext'); // Remove acceltext to clear out hotkey hint text
1801                 menuitem.parentNode.openPopupAtScreen(0,0,false); // Tell menupopup to redraw itself
1802                 menuitem.parentNode.hidePopup(); // And then make it go away right away.
1803                 menuitem.style.removeProperty('display'); // Restore normal css display
1804             }
1805             while(keyset.hasChildNodes()) keyset.removeChild(keyset.childNodes[0]);
1806         }
1807         keyset_lines = mainwin.get_hotkey_array(hotkeyset);
1808         // Next, fill the keyset
1809         for(var line = 0; line < keyset_lines.length; line++) {
1810             // Create and populate our <key>
1811             var key_node = document.createElement('key');
1812             key_node.setAttribute('id',keyset_lines[line][0] + "_key");
1813             key_node.setAttribute('command',keyset_lines[line][0]);
1814             key_node.setAttribute('modifiers',keyset_lines[line][1]);
1815             // If keycode starts with VK_ we assume it is a key code.
1816             // Key codes go in the keycode attribute
1817             // Regular keys (like "i") go in the key attribute
1818             if(keyset_lines[line][2].match(/^VK_/))
1819                 key_node.setAttribute('keycode',keyset_lines[line][2]);
1820             else
1821                 key_node.setAttribute('key',keyset_lines[line][2]);
1822             // If a fourth option was specified, set keytext to it.
1823             if(keyset_lines[line][3])
1824                 key_node.setAttribute('keytext',keyset_lines[line][3]);
1825             // Add the new node to the DOM
1826             keyset.appendChild(key_node);
1827             // And populate all the menu items that should now display it
1828             var menuitems = main_menu.getElementsByAttribute('command',keyset_lines[line][0]);
1829             for(var i = 0; i < menuitems.length; i++) {
1830                 menuitems[i].setAttribute('key', keyset_lines[line][0] + "_key");
1831                 // Trick/force mozilla to re-evaluate the menuitem
1832                 menuitems[i].style.display = 'none'; // Hide the item to force menu to clear spot
1833                 menuitems[i].parentNode.openPopupAtScreen(0,0,false); // Tell menupopup to redraw itself
1834                 menuitems[i].parentNode.hidePopup(); // And then make it go away right away
1835                 menuitems[i].style.removeProperty('display'); // Restore normal css display
1836             }
1837         }
1838         // Force reload of keyset cache?
1839         keyset.parentNode.insertBefore(keyset, keyset.nextSibling);
1840         // If no keys, disable ability to toggle hotkeys (because why bother?)
1841         var x = document.getElementById('cmd_hotkeys_toggle');
1842         if(x) {
1843             if(keyset.hasChildNodes())
1844                 x.removeAttribute('disabled');
1845             else
1846                 x.setAttribute('disabled', 'true');
1847         }
1848         // Select the hotkey set in the menu
1849         // This ensures that first window load OR remote window update shows properly
1850         var hotkeylist = document.getElementById('main.menu.admin.client.hotkeys.current.popup');
1851         var selectitems = hotkeylist.getElementsByAttribute('value',hotkeyset);
1852         if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
1853     },
1854
1855     'page_meter' : {
1856         'node' : document.getElementById('page_progress'),
1857         'on' : function() {
1858             document.getElementById('page_progress').setAttribute('mode','undetermined');
1859         },
1860         'off' : function() {
1861             document.getElementById('page_progress').setAttribute('mode','determined');
1862         },
1863         'tooltip' : function(text) {
1864             if (text || text == '') {
1865                 document.getElementById('page_progress').setAttribute('tooltiptext',text);
1866             }
1867             return document.getElementById('page_progress').getAttribute('tooltiptext');
1868         }
1869     },
1870
1871     'network_meter' : {
1872         'inc' : function(app,method) {
1873             try {
1874                 var m = document.getElementById('network_progress');
1875                 var count = 1 + Number( m.getAttribute('count') );
1876                 m.setAttribute('mode','undetermined');
1877                 m.setAttribute('count', count);
1878                 var rows = document.getElementById('network_progress_rows');
1879                 var row = document.getElementById('network_progress_tip_'+app+'_'+method);
1880                 if (!row) {
1881                     row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
1882                     var a = document.createElement('label'); a.setAttribute('value','App:');
1883                     var b = document.createElement('label'); b.setAttribute('value',app);
1884                     var c = document.createElement('label'); c.setAttribute('value','Method:');
1885                     var d = document.createElement('label'); d.setAttribute('value',method);
1886                     var e = document.createElement('label'); e.setAttribute('value','Total:');
1887                     var f = document.createElement('label'); f.setAttribute('value','0'); 
1888                     f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
1889                     var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
1890                     var h = document.createElement('label'); h.setAttribute('value','0');
1891                     h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
1892                     row.appendChild(a); row.appendChild(b); row.appendChild(c);
1893                     row.appendChild(d); row.appendChild(e); row.appendChild(f);
1894                     row.appendChild(g); row.appendChild(h); rows.appendChild(row);
1895                 }
1896                 var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
1897                 if (total) {
1898                     total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
1899                 }
1900                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1901                 if (out) {
1902                     out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
1903                 }
1904             } catch(E) {
1905                 dump('network_meter.inc(): ' + E + '\n');
1906             }
1907         },
1908         'dec' : function(app,method) {
1909             try {
1910                 var m = document.getElementById('network_progress');
1911                 var count = -1 + Number( m.getAttribute('count') );
1912                 if (count < 0) count = 0;
1913                 if (count == 0) m.setAttribute('mode','determined');
1914                 m.setAttribute('count', count);
1915                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1916                 if (out) {
1917                     out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
1918                 }
1919             } catch(E) {
1920                 dump('network_meter.dec(): ' + E + '\n');
1921             }
1922         }
1923     },
1924     'set_patron_tab' : function(params,content_params,event) {
1925         var obj = this;
1926         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1927         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1928         obj.command_tab(event,url,params ? params : {},content_params ? content_params : {});
1929     },
1930     'new_patron_tab' : function(params,content_params) {
1931         var obj = this;
1932         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1933         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1934         obj.new_tab(url,params ? params : {},content_params ? content_params : {});
1935     },
1936     'volume_item_creator' : function(params) {
1937         var obj = this;
1938         var url;
1939         var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
1940         if (unified_interface) {
1941             var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
1942             url = obj.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
1943         } else {
1944             url = obj.url_prefix( urls.XUL_VOLUME_COPY_CREATOR_ORIGINAL );
1945         }
1946         var w = obj.new_tab(
1947             url,
1948             { 'tab_name' : document.getElementById('offlineStrings').getString('staff.cat.create_or_rebarcode_items') },
1949             params
1950         );
1951     },
1952     'holdings_maintenance_tab' : function(docid,params,content_params) {
1953         var obj = this;
1954         if (!content_params) {
1955             content_params = {};
1956         }
1957         if (docid) {
1958             content_params['docid'] = docid;
1959         }
1960         var url = obj.url_prefix( urls.XUL_COPY_VOLUME_BROWSE );
1961         obj.new_tab(url,params || {}, content_params);
1962     },
1963     'get_new_session' : function(params) {
1964         var obj = this;
1965         if (!params) { params = {}; }
1966         JSAN.use('util.network'); var net = new util.network();
1967         var result = net.get_new_session(null,{'url_prefix':obj.url_prefix},!params.operator_change);
1968         if (typeof params.callback == 'function') {
1969             return params.callback( result, ses(), ses('authtime') );
1970         }
1971         return result;
1972     },
1973     'set_help_context' : function(params) {
1974         var obj = this;
1975         if (!params) { params = {}; }
1976         if (params.protocol == 'chrome:') { return; } /* not supported */
1977         var help_btn = document.getElementById('help_btn');
1978         if (help_btn) {
1979             dump('set_help_context: ' + js2JSON(params) + '\n');
1980             if (params.protocol) { help_btn.setAttribute('protocol', params.protocol); }
1981             if (params.hostname) { help_btn.setAttribute('hostname', params.hostname);  }
1982             if (params.port) { help_btn.setAttribute('port', params.port);  }
1983             if (params.pathname) { help_btn.setAttribute('pathname', params.pathname); }
1984             if (params.src) { help_btn.setAttribute('src', params.src); }
1985         }
1986     },
1987
1988     'tab_semaphores' : {},
1989
1990     'set_tab' : function(url,params,content_params) {
1991         var obj = this;
1992         if (!url) url = '/xul/server/';
1993         if (!url.match(/:\/\//) && !url.match(/^data:/)) url = urls.remote + url;
1994         if (!params) params = {};
1995         if (!content_params) content_params = {};
1996         var idx = this.controller.view.tabs.selectedIndex;
1997         if (params && typeof params.index != 'undefined') idx = params.index;
1998         var tab = this.controller.view.tabs.childNodes[ idx ];
1999
2000         var id = tab.getAttribute('id');
2001         if (id) {
2002             if (typeof obj.tab_semaphores[id] != 'undefined') {
2003                 if (obj.tab_semaphores[id] > 0) {
2004                     var confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning'));
2005                     if (!confirmation) { return; }
2006                     oils_unsaved_data_P( obj.tab_semaphores[id] );
2007                 }
2008                 delete obj.tab_semaphores[id];
2009             }
2010         }
2011         var unique_id = idx + ':' + new Date();
2012         tab.setAttribute('id',unique_id);
2013         if (params.focus) tab.focus();
2014         var panel = this.controller.view.panels.childNodes[ idx ];
2015         while ( panel.lastChild ) panel.removeChild( panel.lastChild );
2016
2017         content_params.lock_tab = function() { 
2018             dump('lock_tab\n');
2019             var id = tab.getAttribute('id');
2020             if (typeof obj.tab_semaphores[id] == 'undefined') {
2021                 obj.tab_semaphores[id] = 0;
2022             }
2023             obj.tab_semaphores[id]++; 
2024             oils_unsaved_data_V();
2025             return obj.tab_semaphores[id]; 
2026         };
2027         content_params.unlock_tab = function() { 
2028             dump('unlock_tab\n');
2029             var id = tab.getAttribute('id');
2030             if (typeof obj.tab_semaphores[id] == 'undefined') {
2031                 obj.tab_semaphores[id] = 0;
2032             }
2033             obj.tab_semaphores[id]--;
2034             if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } 
2035             oils_unsaved_data_P();
2036             return obj.tab_semaphores[id]; 
2037         };
2038         content_params.inspect_tab = function() {
2039             var id = tab.getAttribute('id');
2040             return 'id = ' + id + ' semaphore = ' + obj.tab_semaphores[id];
2041         }
2042         content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); };
2043         content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); };
2044         content_params.close_tab = function() { return obj.close_tab(); };
2045         content_params.new_patron_tab = function(a,b) { return obj.new_patron_tab(a,b); };
2046         content_params.set_patron_tab = function(a,b) { return obj.set_patron_tab(a,b); };
2047         content_params.volume_item_creator = function(a) { return obj.volume_item_creator(a); };
2048         content_params.get_new_session = function(a) { return obj.get_new_session(a); };
2049         content_params.holdings_maintenance_tab = function(a,b,c) { return obj.holdings_maintenance_tab(a,b,c); };
2050         content_params.set_tab_name = function(name) { tab.label = tab.curindex + ' ' + name; tab.origlabel = name; };
2051         content_params.set_help_context = function(params) { return obj.set_help_context(params); };
2052         content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
2053         content_params.url_prefix = function(url) { return obj.url_prefix(url); };
2054         content_params.network_meter = obj.network_meter;
2055         content_params.page_meter = obj.page_meter;
2056         content_params.get_barcode = obj.get_barcode;
2057         content_params.set_statusbar = function(slot,text,tooltiptext,click_handler) {
2058             var e = document.getElementById('statusbarpanel'+slot);
2059             if (e) {
2060                 var p = e.parentNode;
2061                 var sbp = document.createElement('statusbarpanel');
2062                 sbp.setAttribute('id','statusbarpanel'+slot);
2063                 p.replaceChild(sbp,e); // destroy and replace the statusbarpanel as a poor man's way of clearing event handlers
2064
2065                 sbp.setAttribute('label',text);
2066                 if (tooltiptext) {
2067                     sbp.setAttribute('tooltiptext',tooltiptext);
2068                 }
2069                 if (click_handler) {
2070                     sbp.addEventListener(
2071                         'click',
2072                         click_handler,
2073                         false
2074                     );
2075                 }
2076             }
2077         };
2078         content_params.chrome_xulG = xulG;
2079         content_params._data = xulG._data;
2080         if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
2081         
2082         var frame;
2083         try {
2084             if (typeof params.browser == 'undefined') params.browser = false;
2085             if (params.browser) {
2086                 obj.id_incr++;
2087                 frame = this.w.document.createElement('browser');
2088                 frame.setAttribute('flex','1');
2089                 frame.setAttribute('type','content');
2090                 frame.setAttribute('autoscroll','false');
2091                 frame.setAttribute('id','frame_'+obj.id_incr);
2092                 panel.appendChild(frame);
2093                 try {
2094                     dump('creating browser with src = ' + url + '\n');
2095                     JSAN.use('util.browser');
2096                     var b = new util.browser();
2097                     b.init(
2098                         {
2099                             'url' : url,
2100                             'push_xulG' : true,
2101                             'alt_print' : false,
2102                             'browser_id' : 'frame_'+obj.id_incr,
2103                             'passthru_content_params' : content_params,
2104                         }
2105                     );
2106                 } catch(E) {
2107                     alert(E);
2108                 }
2109             } else {
2110                 frame = this.w.document.createElement('iframe');
2111                 frame.setAttribute('flex','1');
2112                 panel.appendChild(frame);
2113                 dump('creating iframe with src = ' + url + '\n');
2114                 frame.setAttribute('src',url);
2115                 try {
2116                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
2117                     var cw = frame.contentWindow;
2118                     if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject;
2119                     cw.IAMXUL = true;
2120                     cw.xulG = content_params;
2121                     cw.addEventListener(
2122                         'load',
2123                         function() {
2124                             try {
2125                                 if (typeof cw.help_context_set_locally == 'undefined') {
2126                                     var help_params = {
2127                                         'protocol' : cw.location.protocol,
2128                                         'hostname' : cw.location.hostname,
2129                                         'port' : cw.location.port,
2130                                         'pathname' : cw.location.pathname,
2131                                         'src' : ''
2132                                     };
2133                                     obj.set_help_context(help_params);
2134                                 } else if (typeof cw.default_focus == 'function') {
2135                                     cw.default_focus();
2136                                 }
2137                             } catch(E) {
2138                                 obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E);
2139                             }
2140                         },
2141                         false
2142                     );
2143                 } catch(E) {
2144                     this.error.sdump('D_ERROR', 'main.menu: ' + E);
2145                 }
2146             }
2147         } catch(E) {
2148             this.error.sdump('D_ERROR', 'main.menu:2: ' + E);
2149             alert(offlineStrings.getString('menu.set_tab.error'));
2150         }
2151
2152         return frame;
2153     },
2154
2155     'get_barcode' : function(window, context, barcode) {
2156         JSAN.use('util.network');
2157         JSAN.use('util.sound');
2158
2159         // Depending on where we were called from data can be found in multiple ways
2160         var data;
2161         if(this.data) data = this.data;
2162         else if(xulG.data) data = xulG.data;        
2163         else {
2164             JSAN.use('util.data');
2165             data = new util.data();
2166         }
2167         data.stash_retrieve();
2168
2169         var network = new util.network();
2170         var sound = new util.sound();
2171
2172         // Should return an array. Or an error.
2173         var r = network.simple_request('GET_BARCODES', [ ses(), data.list.au[0].ws_ou(), context, barcode ]);
2174
2175         if(!r) // Nothing?
2176             return false;
2177
2178         // Top-level error, likely means bad session or no STAFF_LOGIN permission.
2179         if(typeof r.ilsevent != 'undefined') {
2180             // Hand it off to the caller.
2181             return r;
2182         }
2183
2184         // No results? Return false
2185         if(r.length == 0) return false;
2186
2187         // One result?
2188         if(r.length == 1) {
2189             // Return it. If it is an error the caller should deal with it.
2190             return r[0];
2191         }
2192
2193         // At this point we have more than one result.
2194         // Check to see what we got.
2195         var result_filter = {};
2196         var valid_r = [];
2197         var unique_count = 0;
2198         var found_errors = false;
2199         var errors = '';
2200         var len = r.length;
2201
2202         // Check each result.
2203         for(var i = 0; i < len; ++i) {
2204             // If it is an error
2205             if(typeof r[i].ilsevent != 'undefined') {
2206                 // Make note that we found errors
2207                 found_errors = true;
2208                 // Grab the error into a string
2209                 errors += js2JSON(r[i]);
2210             }
2211             else {
2212                 // Otherwise, record the type/id combo for later
2213                 var type = r[i].type;
2214                 var id = r[i].id;
2215                 var barcode = r[i].barcode;
2216                 if(!result_filter[type]) result_filter[type] = {};
2217                 if(!result_filter[type][id]) {
2218                     unique_count++;
2219                     result_filter[type][id] = [];
2220                 }
2221                 result_filter[type][id].push(barcode);
2222                 valid_r.push(r[i]);
2223             }
2224         }
2225
2226         // Only errors? Return the first one.
2227         if(unique_count == 0 && found_errors == true) {
2228             return r[0];
2229         }
2230
2231         // No errors, one (unique) result? Return it.
2232         if(unique_count == 1 && found_errors == false) return valid_r[0];
2233
2234         // For possible debugging, dump the errors.
2235         if(found_errors) dump(errors);
2236
2237         // Still here? Must need to have the user pick.
2238         if(!xulG.url_prefix) xulG.url_prefix = url_prefix; // Make util.window happy
2239         JSAN.use('util.window');
2240         var win = new util.window();
2241         var url = url_prefix(urls.XUL_FANCY_PROMPT);
2242         var title = offlineStrings.getString('barcode_choice.title');
2243         var xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" flex="1">';
2244         xml += '<groupbox flex="1" style="overflow: auto; border: solid thin;"><caption label="' + title + '"/>';
2245         xml += '<description style="-moz-user-select: text; -moz-user-focus: normal; font-size: large">' + offlineStrings.getString('barcode_choice.prompt') + '</description>';
2246         if(found_errors) // Let the user know that one or more possible answers errored out.
2247             xml += '<description style="-moz-user=select: text; -moz-user-focus: normal; font-size: large">' + offlineStrings.getString('barcode_choice.errors_found') + '</description>';
2248         xml += '</groupbox><groupbox><caption label="' + offlineStrings.getString('barcode_choice.choice_label') + '"/><vbox>';
2249
2250         len = valid_r.length;
2251         // Look at all the non-error answers we got
2252         for(var i = 0; i < len; ++i) {
2253             // If we still have a filtered answer, display a button.
2254             if(result_filter[valid_r[i].type][valid_r[i].id]) {
2255                 var result_data = false;
2256                 var barcodes = result_filter[valid_r[i].type][valid_r[i].id];
2257                 var barcodes_assembled = barcodes.shift();
2258                 var button_label = '';
2259                 while(barcodes.length > 0) // Join any secondary barcodes found together
2260                     barcodes_assembled = offlineStrings.getFormattedString('barcode_choice.join_barcodes', [barcodes_assembled, barcodes.shift()]);
2261                 switch(r[i].type) {
2262                     case 'actor':
2263                         result_data = network.simple_request('BLOB_AU_PARTS_RETRIEVE',
2264                             [ ses() , valid_r[i].id, ['family_name', 'first_given_name', 'second_given_name', 'home_ou' ] ]);
2265                         button_label = offlineStrings.getFormattedString('barcode_choice.actor',
2266                             [barcodes_assembled, result_data[0], result_data[1] + (result_data[2] ? ' ' + result_data[2] : ''), data.hash.aou[ result_data[3] ].name(), data.hash.aou[ result_data[3] ].shortname()]);
2267                         break;
2268                     case 'booking':
2269                         result_data = network.simple_request('FM_ACP_DETAILS_VIA_BARCODE', [ ses(), valid_r[i].barcode ]);
2270                         // Note: This falls through intentionally.
2271                     case 'asset':
2272                     case 'serial':
2273                         if(!result_data) // If we fell through this should be set already.
2274                             result_data = network.simple_request('FM_ACP_DETAILS', [ ses(), valid_r[i].id ]);
2275                         button_label = offlineStrings.getFormattedString('barcode_choice.asset',
2276                             [barcodes_assembled, result_data.mvr.title(), data.hash.aou[ result_data.copy.circ_lib() ].name(), data.hash.aou[ result_data.copy.circ_lib() ].shortname()]);
2277                         break;
2278                 }
2279                 r[i].data = result_data;
2280
2281                 // This ensures we only show each unique id once
2282                 delete result_filter[valid_r[i].type][valid_r[i].id];
2283
2284                 // If we have more than one context this should label each entry with where it came from
2285                 // Likely most useful for distinguishing assets from bookings
2286                 if(context != valid_r[i].type && offlineStrings.testString('barcode_choice.' + valid_r[i].type + '_label'))
2287                     button_label = offlineStrings.getFormattedString('barcode_choice.' + valid_r[i].type + '_label', [button_label]);
2288
2289                 xml += '<button label="' + button_label + '" name="fancy_submit" value="' + i + '"/>';
2290             }
2291         }
2292         xml += '<button label="' + offlineStrings.getString('barcode_choice.none') + '" name="fancy_cancel"/>';
2293         xml += '</vbox></groupbox></vbox>';
2294         var fancy_prompt_data = win.open( url, 'fancy_prompt', 'chrome,resizable,modal,width=500,height=500', { 'xml' : xml, 'title' : title, 'sound' : 'bad' } );
2295         if(fancy_prompt_data.fancy_status == 'complete')
2296             return valid_r[fancy_prompt_data.fancy_submit];
2297         else
2298             // user_false is used to indicate the user said "None of the above" to avoid fall-through erroring later.
2299             return "user_false";
2300     }
2301 }
2302
2303 dump('exiting main/menu.js\n');