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