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