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