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