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