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