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