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