bc8c11dad90aa6265edda083a7cdcb15a2480b75
[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) {
42         if (url.match(/^\//)) url = urls.remote + url;
43         if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
44         dump('url_prefix = ' + url + '\n');
45         return url;
46     },
47
48     'init' : function( params ) {
49
50         var obj = this;
51
52         urls.remote = params['server'];
53
54         // Pull in local customizations
55         var r = new XMLHttpRequest();
56         r.open("GET", obj.url_prefix('/xul/server/skin/custom.js'), false);
57         r.send(null);
58         if (r.status == 200) {
59             dump('Evaluating /xul/server/skin/custom.js\n');
60             eval( r.responseText );
61         }
62
63         // Try workstation pref for button bar
64         var button_bar = xulG.pref.getCharPref('open-ils.menu.toolbar');
65
66         if (!button_bar) // No workstation pref? Try org unit pref.
67             button_bar = String( obj.data.hash.aous['ui.general.button_bar'] );
68
69         if (button_bar) {
70             var x = document.getElementById('toolbar_' + button_bar);
71             if (x) x.setAttribute('hidden','false');
72             this.toolbar = button_bar;
73         }
74
75         // Check for alternate Size pref
76         var toolbar_size = xulG.pref.getCharPref('open-ils.menu.toolbar.iconsize');
77         if(toolbar_size) this.toolbar_size = toolbar_size;
78         // Check for alternate Mode pref
79         var toolbar_mode = xulG.pref.getCharPref('open-ils.menu.toolbar.mode');
80         if(toolbar_mode) this.toolbar_mode = toolbar_mode;
81         // Check for alternate Label Position pref
82         var toolbar_labelpos = xulG.pref.getBoolPref('open-ils.menu.toolbar.labelbelow');
83         if(toolbar_labelpos) this.toolbar_labelpos = toolbar_labelpos;
84
85         if(button_bar || toolbar_size || toolbar_mode || toolbar_labelpos) {
86             var toolbox = document.getElementById('main_toolbox');
87             var toolbars = toolbox.getElementsByTagName('toolbar');
88             for(var i = 0; i < toolbars.length; i++) {
89                 if(toolbars[i].id == 'toolbar_' + button_bar)
90                     toolbars[i].setAttribute('hidden', 'false');
91                 else
92                     toolbars[i].setAttribute('hidden', 'true');
93                 if(toolbar_mode) toolbars[i].setAttribute('mode', toolbar_mode);
94                 if(toolbar_size) toolbars[i].setAttribute('iconsize', toolbar_size);
95                 if(toolbar_labelpos) addCSSClass(toolbars[i], 'labelbelow');
96             }
97         }
98
99         if(button_bar) {
100             var x = document.getElementById('main.menu.admin.client.toolbars.current.popup');
101             if (x) {
102                 var selectitems = x.getElementsByAttribute('value',button_bar);
103                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
104             }
105         }
106
107         if(toolbar_size) {
108             var x = document.getElementById('main.menu.admin.client.toolbars.size.popup');
109             if (x) {
110                 var selectitems = x.getElementsByAttribute('value',toolbar_size);
111                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
112             }
113         }
114
115         if(toolbar_mode) {
116             var x = document.getElementById('main.menu.admin.client.toolbars.mode.popup');
117             if (x) {
118                 var selectitems = x.getElementsByAttribute('value',toolbar_mode);
119                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
120             }
121         }
122
123         if(toolbar_labelpos) {
124             var x = document.getElementById('main.menu.admin.client.toolbars.label_position.popup');
125             if (x) {
126                 var selectitems = x.getElementsByAttribute('value',"under");
127                 if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
128             }
129         }
130
131         var network_meter = String( obj.data.hash.aous['ui.network.progress_meter'] ) == 'true';
132         if (! network_meter) {
133             var x = document.getElementById('network_progress');
134             if (x) x.setAttribute('hidden','true');
135             var y = document.getElementById('page_progress');
136             if (y) y.setAttribute('hidden','true');
137         }
138
139         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
140                     getService(Components.interfaces.nsIWindowMediator);
141         var mainwin = wm.getMostRecentWindow('eg_main');
142         mainwin.get_menu_perms(document);
143         var hotkeysets = mainwin.load_hotkey_sets();
144
145         var popupmenu = document.getElementById('main.menu.admin.client.hotkeys.current.popup');
146         
147         for(var i = 0; i < hotkeysets.length; i++) {
148             var keysetname = hotkeysets[i];
149             var menuitem = document.createElement('menuitem');
150             if(offlineStrings.testString('hotkey.' + keysetname))
151                 menuitem.setAttribute('label',offlineStrings.getString('hotkey.' + keysetname));
152             else
153                 menuitem.setAttribute('label',keysetname);
154             menuitem.setAttribute('value',keysetname);
155             menuitem.setAttribute('type','radio');
156             menuitem.setAttribute('name','menu_hotkey_current');
157             menuitem.setAttribute('command','cmd_hotkeys_set');
158             popupmenu.appendChild(menuitem);
159         }
160
161         JSAN.use('util.network');
162         var network = new util.network();
163         network.set_user_status();
164
165         this.set_menu_hotkeys();
166
167         function open_conify_page(path, labelKey, event) {
168
169             // tab label
170             labelKey = labelKey || 'menu.cmd_open_conify.tab';
171             label = offlineStrings.getString(labelKey);
172
173             // URL
174             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.CONIFY) + '/' + path + '.html');
175
176             obj.command_tab(
177                 event,
178                 loc, 
179                 {'tab_name' : label, 'browser' : false }, 
180                 {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons:true} 
181             );
182         }
183
184         function open_admin_page(path, labelKey, addSes, event) {
185
186             // tab label
187             labelKey = labelKey || 'menu.cmd_open_conify.tab';
188             label = offlineStrings.getString(labelKey);
189
190             // URL
191             var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_LOCAL_ADMIN_BASE) + '/' + path);
192             if(addSes) loc += window.escape('?ses=' + ses());
193
194             obj.command_tab( 
195                 event,
196                 loc, 
197                 {'tab_name' : label, 'browser' : false }, 
198                 {'no_xulG' : false, 'show_print_button' : true, 'show_nav_buttons' : true } 
199             );
200         }
201
202
203         function open_eg_web_page(path, labelKey, event) {
204             
205             // tab label
206             labelKey = labelKey || 'menu.cmd_open_conify.tab';
207             var label = offlineStrings.getString(labelKey);
208
209             // URL
210             var loc = urls.XUL_BROWSER + '?url=' + window.escape(obj.url_prefix(urls.EG_WEB_BASE) + '/' + path);
211
212             obj.command_tab(
213                 event,
214                 loc, 
215                 {tab_name : label, browser : false }, 
216                 {no_xulG : false, show_print_button : true, show_nav_buttons : true }
217             );
218         }
219
220         var cmd_map = {
221             'cmd_broken' : [
222                 ['oncommand'],
223                 function() { alert(offlineStrings.getString('common.unimplemented')); }
224             ],
225
226             /* File Menu */
227             'cmd_close_window' : [ 
228                 ['oncommand'], 
229                 function() {
230                     JSAN.use('util.widgets');
231                     util.widgets.dispatch('close',window);
232                 }
233             ],
234             'cmd_new_window' : [
235                 ['oncommand'],
236                 function() {
237                     var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
238                         getService(Components.interfaces.nsIWindowMediator);
239                     wm.getMostRecentWindow('eg_main').new_tabs(Array('new'));
240                 }
241             ],
242             'cmd_new_tab' : [
243                 ['oncommand'],
244                 function() {
245                     if (obj.new_tab(null,{'focus':true},null) == false)
246                     {
247                         if(window.confirm(offlineStrings.getString('menu.new_tab.max_tab_dialog')))
248                         {
249                             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
250                                 getService(Components.interfaces.nsIWindowMediator);
251                             wm.getMostRecentWindow('eg_main').new_tabs(Array('tab'));
252                         }
253                     }
254                 }
255             ],
256             'cmd_close_tab' : [
257                 ['oncommand'],
258                 function() { obj.close_tab(); }
259             ],
260             'cmd_close_all_tabs' : [
261                 ['oncommand'],
262                 function() { obj.close_all_tabs(); }
263             ],
264
265             /* Edit Menu */
266             'cmd_edit_copy_buckets' : [
267                 ['oncommand'],
268                 function(event) {
269                     obj.data.stash_retrieve();
270                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_copy_buckets.tab')},{});
271                 }
272             ],
273             'cmd_edit_volume_buckets' : [
274                 ['oncommand'],
275                 function(event) {
276                     obj.data.stash_retrieve();
277                     obj.command_tab(event,obj.url_prefix(urls.XUL_VOLUME_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_volume_buckets.tab')},{});
278                 }
279             ],
280             'cmd_edit_record_buckets' : [
281                 ['oncommand'],
282                 function(event) {
283                     obj.data.stash_retrieve();
284                     obj.command_tab(event,obj.url_prefix(urls.XUL_RECORD_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_record_buckets.tab')},{});
285                 }
286             ],
287             'cmd_edit_user_buckets' : [
288                 ['oncommand'],
289                 function(event) {
290                     obj.data.stash_retrieve();
291                     obj.command_tab(event,obj.url_prefix(urls.XUL_USER_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_user_buckets.tab')},{});
292                 }
293             ],
294
295
296             'cmd_replace_barcode' : [
297                 ['oncommand'],
298                 function() {
299                     try {
300                         JSAN.use('util.network');
301                         var network = new util.network();
302
303                         var old_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.label'));
304                         if (!old_bc) return;
305     
306                         var copy;
307                         try {
308                             copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
309                             if (typeof copy.ilsevent != 'undefined') throw(copy); 
310                             if (!copy) throw(copy);
311                         } catch(E) {
312                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n');
313                             return;
314                         }
315     
316                         // Why did I want to do this twice?  Because this copy is more fleshed?
317                         try {
318                             copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
319                             if (typeof copy.ilsevent != 'undefined') throw(copy);
320                             if (!copy) throw(copy);
321                         } catch(E) {
322                             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); }
323                             return;
324                         }
325     
326                         var new_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.replacement.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.replacement.label'));
327                         new_bc = String( new_bc ).replace(/\s/g,'');
328                         /* Casting a possibly null input value to a String turns it into "null" */
329                         if (!new_bc || new_bc == 'null') {
330                             alert(offlineStrings.getString('menu.cmd_replace_barcode.blank.error'));
331                             return;
332                         }
333     
334                         var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
335                         if (typeof test.ilsevent == 'undefined') {
336                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.duplicate.error', [new_bc]));
337                             return;
338                         } else {
339                             if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
340                                 obj.error.standard_unexpected_error_alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.testing.error', [new_bc]),test);
341                                 return;
342                             }    
343                         }
344
345                         copy.barcode(new_bc); copy.ischanged('1');
346                         var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
347                         if (typeof r.ilsevent != 'undefined') { 
348                             if (r.ilsevent != 0) {
349                                 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
350                                     alert(offlineStrings.getString('menu.cmd_replace_barcode.permission.error'));
351                                 } else {
352                                     obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.error'),r);
353                                 }
354                             }
355                         }
356                     } catch(E) {
357                         obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.failure'),copy);
358                     }
359                 }
360             ],
361
362             /* Search Menu */
363             'cmd_patron_search' : [
364                 ['oncommand'],
365                 function(event) {
366                     obj.set_patron_tab({},{},event);
367                 }
368             ],
369             'cmd_search_opac' : [
370                 ['oncommand'],
371                 function(event) {
372                     obj.data.stash_retrieve();
373                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
374                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {'tab_name':offlineStrings.getString('menu.cmd_search_opac.tab')}, content_params);
375                 }
376             ],
377             'cmd_search_tcn' : [
378                 ['oncommand'],
379                 function(event) {
380                     var tcn = prompt(offlineStrings.getString('menu.cmd_search_tcn.tab'),'',offlineStrings.getString('menu.cmd_search_tcn.prompt'));
381
382                     function spawn_tcn(r,event) {
383                         for (var i = 0; i < r.count; i++) {
384                             var id = r.ids[i];
385                             var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + id;
386                             obj.data.stash_retrieve();
387                             var content_params = { 
388                                 'session' : ses(), 
389                                 'authtime' : ses('authtime'),
390                                 'opac_url' : opac_url,
391                             };
392                             if (i == 0) {
393                                 obj.command_tab(
394                                     event,
395                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
396                                     {'tab_name':tcn}, 
397                                     content_params
398                                 );
399                             } else {
400                                 obj.new_tab(
401                                     obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
402                                     {'tab_name':tcn}, 
403                                     content_params
404                                 );
405                             }
406                         }
407                     }
408
409                     if (tcn) {
410                         JSAN.use('util.network');
411                         var network = new util.network();
412                         var robj = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn]);
413                         if (robj.count != robj.ids.length) throw('FIXME -- FM_BRE_ID_SEARCH_VIA_TCN = ' + js2JSON(robj));
414                         if (robj.count == 0) {
415                             var robj2 = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn,1]);
416                             if (robj2.count == 0) {
417                                 alert(offlineStrings.getFormattedString('menu.cmd_search_tcn.not_found.error', [tcn]));
418                             } else {
419                                 if ( window.confirm(offlineStrings.getFormattedString('menu.cmd_search_tcn.deleted.error', [tcn])) ) {
420                                     spawn_tcn(robj2,event);
421                                 }
422                             }
423                         } else {
424                             spawn_tcn(robj,event);
425                         }
426                     }
427                 }
428             ],
429             'cmd_search_bib_id' : [
430                 ['oncommand'],
431                 function(event) {
432                     var bib_id = prompt(offlineStrings.getString('menu.cmd_search_bib_id.tab'),'',offlineStrings.getString('menu.cmd_search_bib_id.prompt'));
433                     if (!bib_id) return;
434
435                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + bib_id;
436                     var content_params = { 
437                         'session' : ses(), 
438                         'authtime' : ses('authtime'),
439                         'opac_url' : opac_url,
440                     };
441                     obj.command_tab(
442                         event,
443                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
444                         {'tab_name':'#' + bib_id}, 
445                         content_params
446                     );
447                 }
448             ],
449             'cmd_copy_status' : [
450                 ['oncommand'],
451                 function(event) {
452                     obj.data.stash_retrieve();
453                     obj.command_tab(event,obj.url_prefix(urls.XUL_COPY_STATUS),{},{});
454                 }
455             ],
456
457             /* Circulation Menu */
458             'cmd_patron_register' : [
459                 ['oncommand'],
460                 function(event) {
461
462                     function log_registration(p) {
463                         try {
464                             obj.error.work_log(
465                                 document.getElementById('offlineStrings').getFormattedString(
466                                     'staff.circ.work_log_patron_registration.message',
467                                     [
468                                         ses('staff_usrname'),
469                                         p.family_name(),
470                                         p.card().barcode()
471                                     ]
472                                 ), {
473                                     'au_id' : p.id(),
474                                     'au_family_name' : p.family_name(),
475                                     'au_barcode' : p.card().barcode()
476                                 }
477                             );
478                         } catch(E) {
479                             obj.error.sdump('D_ERROR','Error with work_logging in menu.js, cmd_patron_register:' + E);
480                         }
481                     }
482
483                     function spawn_editor(p) {
484                         var url = urls.XUL_PATRON_EDIT;
485                         var param_count = 0;
486                         for (var i in p) {
487                             if (param_count++ == 0) url += '?'; else url += '&';
488                             url += i + '=' + window.escape(p[i]);
489                         }
490                         var loc = obj.url_prefix( urls.XUL_BROWSER ) + '?url=' + window.escape( obj.url_prefix(url) );
491                         obj.new_tab(
492                             loc, 
493                             {}, 
494                             { 
495                                 'show_print_button' : true , 
496                                 'tab_name' : offline.getString('menu.cmd_patron_register.related.tab'),
497                                 'passthru_content_params' : {
498                                     'spawn_search' : function(s) { obj.spawn_search(s); },
499                                     'spawn_editor' : spawn_editor,
500                                     'on_save' : function(p) { log_registration(p); }
501                                 }
502                             }
503                         );
504                     }
505
506                     obj.data.stash_retrieve();
507                     var loc = obj.url_prefix( urls.XUL_BROWSER ) 
508                         + '?url=' + window.escape( obj.url_prefix(urls.XUL_PATRON_EDIT) );
509                     obj.command_tab(
510                         event,
511                         loc, 
512                         {}, 
513                         { 
514                             'show_print_button' : true , 
515                             'tab_name' : offlineStrings.getString('menu.cmd_patron_register.tab'),
516                             'passthru_content_params' : {
517                                 'ses' : ses(),
518                                 'spawn_search' : function(s) { obj.spawn_search(s); },
519                                 'spawn_editor' : spawn_editor,
520                                 'on_save' : function(p) { log_registration(p); }
521                             }
522                         }
523                     );
524                 }
525             ],
526             'cmd_staged_patrons' : [
527                 ['oncommand'],
528                 function(event) {
529                     obj.data.stash_retrieve();
530                     obj.command_tab(event,obj.url_prefix(urls.XUL_STAGED_PATRONS),{'tab_name':offlineStrings.getString('menu.circulation.staged_patrons.tab')},{});
531                 }
532             ],
533             'cmd_circ_checkin' : [
534                 ['oncommand'],
535                 function(event) { 
536                     obj.data.stash_retrieve();
537                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN),{},{});
538                 }
539             ],
540             'cmd_circ_renew' : [
541                 ['oncommand'],
542                 function(event) { 
543                     obj.data.stash_retrieve();
544                     obj.command_tab(event,obj.url_prefix(urls.XUL_RENEW),{},{});
545                 }
546             ],
547             'cmd_circ_checkout' : [
548                 ['oncommand'],
549                 function(event) { 
550                     obj.data.stash_retrieve();
551                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY),{},{});
552                 }
553             ],
554             'cmd_circ_hold_capture' : [
555                 ['oncommand'],
556                 function(event) { 
557                     obj.data.stash_retrieve();
558                     obj.command_tab(event,obj.url_prefix(urls.XUL_CHECKIN)+'?hold_capture=1',{},{});
559                 }
560             ],
561             'cmd_browse_holds' : [
562                 ['oncommand'],
563                 function(event) { 
564                     obj.data.stash_retrieve();
565                     obj.command_tab(event,obj.url_prefix(urls.XUL_HOLDS_BROWSER),{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds.tab') },{});
566                 }
567             ],
568             'cmd_browse_holds_shelf' : [
569                 ['oncommand'],
570                 function(event) { 
571                     obj.data.stash_retrieve();
572                     obj.command_tab(event,obj.url_prefix(urls.XUL_HOLDS_BROWSER)+'?shelf=1',{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds_shelf.tab') },{});
573                 }
574             ],
575             'cmd_circ_hold_pull_list' : [
576                 ['oncommand'],
577                 function(event) { 
578                     obj.data.stash_retrieve();
579                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
580                         obj.url_prefix(urls.XUL_HOLD_PULL_LIST)
581                     );
582                     obj.command_tab(event, loc, {'tab_name' : offlineStrings.getString('menu.cmd_browse_hold_pull_list.tab')} );
583                 }
584             ],
585
586             'cmd_in_house_use' : [
587                 ['oncommand'],
588                 function(event) { 
589                     obj.data.stash_retrieve();
590                     obj.command_tab(event,obj.url_prefix(urls.XUL_IN_HOUSE_USE),{},{});
591                 }
592             ],
593
594             'cmd_scan_item_as_missing_pieces' : [
595                 ['oncommand'],
596                 function() { 
597                     xulG.window.open(obj.url_prefix(urls.XUL_SCAN_ITEM_AS_MISSING_PIECES),'scan_missing_pieces','chrome'); 
598                 }
599             ],
600
601             'cmd_standalone' : [
602                 ['oncommand'],
603                 function() { 
604                     //obj.set_tab(obj.url_prefix(urls.XUL_STANDALONE),{},{});
605                     window.open(urls.XUL_STANDALONE,'Offline','chrome,resizable');
606                 }
607             ],
608
609             'cmd_local_admin' : [
610                 ['oncommand'],
611                 function(event) { 
612                     //obj.set_tab(obj.url_prefix(urls.XUL_LOCAL_ADMIN)+'?ses='+window.escape(ses())+'&session='+window.escape(ses()),{},{});
613                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
614                         obj.url_prefix( urls.XUL_LOCAL_ADMIN+'?ses='+window.escape(ses())+'&session='+window.escape(ses()) )
615                     );
616                     obj.command_tab(
617                         event,
618                         loc, 
619                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin.tab'), 'browser' : false }, 
620                         { 'no_xulG' : false, 'show_nav_buttons' : true, 'show_print_button' : true } 
621                     );
622
623                 }
624             ],
625
626             'cmd_toggle_meters' : [
627                 ['oncommand'],
628                 function() {
629                     var x = document.getElementById('network_progress');
630                     if (x) x.hidden = ! x.hidden;
631                     var y = document.getElementById('page_progress');
632                     if (y) y.hidden = ! y.hidden;
633                 }
634             ],
635
636             'cmd_local_admin_reports' : [
637                 ['oncommand'],
638                 function(event) { 
639                     var loc = urls.XUL_BROWSER + '?url=' + window.escape( obj.url_prefix(urls.XUL_REPORTS) + '?ses=' + ses());
640                     obj.command_tab(
641                         event,
642                         loc, 
643                         {'tab_name' : offlineStrings.getString('menu.cmd_local_admin_reports.tab'), 'browser' : false }, 
644                         {'no_xulG' : false, 'show_print_button' : false, show_nav_buttons : true } 
645                     );
646                 }
647             ],
648             'cmd_open_vandelay' : [
649                 ['oncommand'],
650                 function(event) { open_eg_web_page('vandelay/vandelay', null, event); }
651             ],
652             'cmd_local_admin_transit_list' : [
653                 ['oncommand'],
654                 function(event) { open_admin_page('transit_list.xul', 'menu.cmd_local_admin_transit_list.tab', false, event); }
655             ],
656             'cmd_local_admin_age_overdue_circulations_to_lost' : [
657                 ['oncommand'],
658                 function(event) { open_admin_page('circ_age_to_lost.xul', 'menu.cmd_local_admin_age_overdue_circulations_to_lost.tab', true, event); }
659             ],
660             'cmd_local_admin_cash_reports' : [
661                 ['oncommand'],
662                 function(event) { open_admin_page('cash_reports.xhtml', 'menu.cmd_local_admin_cash_reports.tab', true, event); }
663             ],
664             'cmd_local_admin_fonts_and_sounds' : [
665                 ['oncommand'],
666                 function(event) { open_admin_page('font_settings.xul', 'menu.cmd_local_admin_fonts_and_sounds.tab', false, event); }
667             ],
668             'cmd_local_admin_printer' : [
669                 ['oncommand'],
670                 function(event) { open_admin_page('printer_settings.html', 'menu.cmd_local_admin_printer.tab', true, event); }
671             ],
672             'cmd_local_admin_do_not_auto_attempt_print_setting' : [
673                 ['oncommand'],
674                 function(event) { 
675                     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')},{});
676                 }
677             ],
678             'cmd_local_admin_closed_dates' : [
679                 ['oncommand'],
680                 function(event) { open_admin_page('closed_dates.xhtml', 'menu.cmd_local_admin_closed_dates.tab', true, event); }
681             ],
682             'cmd_local_admin_copy_locations' : [
683                 ['oncommand'],
684                 function(event) { open_admin_page('copy_locations.xhtml', 'menu.cmd_local_admin_copy_locations.tab', true, event); }
685             ],
686             'cmd_local_admin_lib_settings' : [
687                 ['oncommand'],
688                 function(event) { open_admin_page('org_unit_settings.xhtml', 'menu.cmd_local_admin_lib_settings.tab', true, event); }
689             ],
690             'cmd_local_admin_non_cat_types' : [
691                 ['oncommand'],
692                 function(event) { open_admin_page('non_cat_types.xhtml', 'menu.cmd_local_admin_non_cat_types.tab', true, event); }
693             ],
694             'cmd_local_admin_stat_cats' : [
695                 ['oncommand'],
696                 function(event) { open_admin_page('stat_cat_editor.xhtml', 'menu.cmd_local_admin_stat_cats.tab', true, event); }
697             ],
698             'cmd_local_admin_standing_penalty' : [
699                 ['oncommand'],
700                 function(event) { open_eg_web_page('conify/global/config/standing_penalty', null, event); }
701             ],
702             'cmd_local_admin_grp_penalty_threshold' : [
703                 ['oncommand'],
704                 function(event) { open_eg_web_page('conify/global/permission/grp_penalty_threshold', null, event); }
705             ],
706             'cmd_server_admin_config_rule_circ_duration' : [
707                 ['oncommand'],
708                 function(event) { open_eg_web_page('conify/global/config/rule_circ_duration', null, event); }
709             ],
710             'cmd_server_admin_config_hard_due_date' : [
711                 ['oncommand'],
712                 function(event) { open_eg_web_page('conify/global/config/hard_due_date', null, event); }
713             ],
714             'cmd_server_admin_config_rule_recurring_fine' : [
715                 ['oncommand'],
716                 function(event) { open_eg_web_page('conify/global/config/rule_recurring_fine', null, event); }
717             ],
718             'cmd_server_admin_config_rule_max_fine' : [
719                 ['oncommand'],
720                 function(event) { open_eg_web_page('conify/global/config/rule_max_fine', null, event); }
721             ],
722             'cmd_server_admin_config_rule_age_hold_protect' : [
723                 ['oncommand'],
724                 function(event) { open_eg_web_page('conify/global/config/rule_age_hold_protect', null, event); }
725             ],
726             'cmd_server_admin_config_circ_weights' : [
727                 ['oncommand'],
728                 function(event) { open_eg_web_page('conify/global/config/circ_matrix_weights', null, event); }
729             ],
730             'cmd_server_admin_config_hold_weights' : [
731                 ['oncommand'],
732                 function(event) { open_eg_web_page('conify/global/config/hold_matrix_weights', null, event); }
733             ],
734             'cmd_server_admin_config_weight_assoc' : [
735                 ['oncommand'],
736                 function(event) { open_eg_web_page('conify/global/config/weight_assoc', null, event); }
737             ],
738             'cmd_local_admin_external_text_editor' : [
739                 ['oncommand'],
740                 function() {
741                     var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces['nsIPrefBranch']);
742                     var key = 'oils.text_editor.external.cmd';
743                     var has_key = prefs.prefHasUserValue(key);
744                     var value = has_key ? prefs.getCharPref(key) : 'C:\\Windows\\notepad.exe %letter.txt%';
745                     var cmd = window.prompt(
746                         document.getElementById('offlineStrings').getString('text_editor.prompt_for_external_cmd'),
747                         value
748                     );
749                     if (!cmd) { return; }
750                     prefs.setCharPref(key,cmd);
751                 }
752             ],
753             'cmd_local_admin_idl_field_doc' : [
754                 ['oncommand'],
755                 function(event) { open_eg_web_page('conify/global/config/idl_field_doc', null, event); }
756             ],
757             'cmd_local_admin_action_trigger' : [
758                 ['oncommand'],
759                 function(event) { open_eg_web_page('conify/global/action_trigger/event_definition', null, event); }
760             ],
761             'cmd_local_admin_survey' : [
762                 ['oncommand'],
763                 function(event) { open_eg_web_page('conify/global/action/survey', null, event); }
764             ],
765             'cmd_local_admin_circ_matrix_matchpoint' : [
766                 ['oncommand'],
767                 function() { open_eg_web_page('conify/global/config/circ_matrix_matchpoint', 
768                     'menu.local_admin.circ_matrix_matchpoint.tab'); }
769             ],
770             'cmd_local_admin_hold_matrix_matchpoint' : [
771                 ['oncommand'],
772                 function() { open_eg_web_page('conify/global/config/hold_matrix_matchpoint', 
773                     'menu.local_admin.hold_matrix_matchpoint.tab'); }
774             ],
775             'cmd_local_admin_copy_location_order' : [
776                 ['oncommand'],
777                 function(event) { open_eg_web_page('conify/global/asset/copy_location_order', null, event); }
778             ],
779             'cmd_local_admin_work_log' : [
780                 ['oncommand'],
781                 function(event) { 
782                     obj.command_tab(
783                         event,
784                         urls.XUL_WORK_LOG,
785                         { 'tab_name' : offlineStrings.getString('menu.local_admin.work_log.tab') },
786                         {}
787                     );
788                 }
789             ],
790             "cmd_local_admin_copy_template": [
791                 ["oncommand"],
792                 function() {
793                     open_eg_web_page("conify/global/asset/copy_template");
794                 }
795             ],
796             'cmd_local_admin_patrons_due_refunds' : [
797                 ['oncommand'],
798                 function(event) {
799                     obj.command_tab(
800                         event,
801                         obj.url_prefix(urls.XUL_PATRONS_DUE_REFUNDS),
802                         { 'tab_name' : offlineStrings.getString('menu.local_admin.patrons_due_refunds.tab') },
803                         {}
804                     );
805                 }
806             ],
807             'cmd_server_admin_org_type' : [
808                 ['oncommand'],
809                 function(event) { open_conify_page('actor/org_unit_type', null, event); }
810             ],
811             'cmd_server_admin_org_unit' : [
812                 ['oncommand'],
813                 function(event) { open_conify_page('actor/org_unit', null, event); }
814             ],
815             'cmd_server_admin_grp_tree' : [
816                 ['oncommand'],
817                 function(event) { open_conify_page('permission/grp_tree', null, event); }
818             ],
819             'cmd_server_admin_perm_list' : [
820                 ['oncommand'],
821                 function(event) { open_conify_page('permission/perm_list', null, event); }
822             ],
823             'cmd_server_admin_copy_status' : [
824                 ['oncommand'],
825                 function(event) { open_conify_page('config/copy_status', null, event); }
826             ],
827             'cmd_server_admin_marc_code' : [
828                 ['oncommand'],
829                 function(event) { open_eg_web_page('conify/global/config/record_attr_definition', null, event); }
830             ],
831             'cmd_server_admin_coded_value_map' : [
832                 ['oncommand'],
833                 function(event) { open_eg_web_page('conify/global/config/coded_value_map', null, event); }
834             ],
835             'cmd_server_admin_acn_prefix' : [
836                 ['oncommand'],
837                 function(event) { open_eg_web_page('conify/global/config/acn_prefix', null, event); }
838             ],
839             'cmd_server_admin_acn_suffix' : [
840                 ['oncommand'],
841                 function(event) { open_eg_web_page('conify/global/config/acn_suffix', null, event); }
842             ],
843             'cmd_server_admin_billing_type' : [
844                 ['oncommand'],
845                 function(event) { open_eg_web_page('conify/global/config/billing_type', null, event); }
846             ],
847             'cmd_server_admin_acq_invoice_item_type' : [
848                 ['oncommand'],
849                 function(event) { open_eg_web_page('conify/global/acq/invoice_item_type', null, event); }
850             ],
851             'cmd_server_admin_acq_invoice_payment_method' : [
852                 ['oncommand'],
853                 function(event) { open_eg_web_page('conify/global/acq/invoice_payment_method', null, event); }
854             ],
855             'cmd_server_admin_acq_lineitem_alert' : [
856                 ['oncommand'],
857                 function(event) { open_eg_web_page('conify/global/acq/lineitem_alert', null, event); }
858             ],
859             'cmd_server_admin_acq_lineitem_marc_attr_def' : [
860                 ['oncommand'],
861                 function(event) { open_eg_web_page('conify/global/acq/lineitem_marc_attr_def', null, event); }
862             ],
863             'cmd_server_admin_acq_fund_tag' : [
864                 ['oncommand'],
865                 function(event) { open_eg_web_page('conify/global/acq/fund_tag', null, event); }
866             ],
867             'cmd_server_admin_acq_cancel_reason' : [
868                 ['oncommand'],
869                 function(event) { open_eg_web_page('conify/global/acq/cancel_reason', null, event); }
870             ],
871             'cmd_server_admin_acq_claim_type' : [
872                 ['oncommand'],
873                 function(event) { open_eg_web_page('conify/global/acq/claim_type', null, event); }
874             ],
875             'cmd_server_admin_acq_claim_event_type' : [
876                 ['oncommand'],
877                 function(event) { open_eg_web_page('conify/global/acq/claim_event_type', null, event); }
878             ],
879             'cmd_server_admin_acq_claim_policy' : [
880                 ['oncommand'],
881                 function(event) { open_eg_web_page('conify/global/acq/claim_policy', null, event); }
882             ],
883             'cmd_server_admin_acq_claim_policy_action' : [
884                 ['oncommand'],
885                 function(event) { open_eg_web_page('conify/global/acq/claim_policy_action', null, event); }
886             ],
887             'cmd_server_admin_acq_fund' : [
888                 ['oncommand'],
889                 function(event) { open_eg_web_page('acq/fund/list', null, event); }
890             ],
891             'cmd_server_admin_acq_funding_source' : [
892                 ['oncommand'],
893                 function(event) { open_eg_web_page('acq/funding_source/list', null, event); }
894             ],
895             'cmd_server_admin_acq_provider' : [
896                 ['oncommand'],
897                 function(event) { open_eg_web_page('conify/global/acq/provider', null, event); }
898             ],
899             'cmd_server_admin_acq_edi_account' : [
900                 ['oncommand'],
901                 function(event) { open_eg_web_page('conify/global/acq/edi_account', null, event); }
902             ],
903             'cmd_server_admin_acq_edi_message' : [
904                 ['oncommand'],
905                 function(event) { open_eg_web_page('acq/po/edi_messages', null, event); }
906             ],
907             'cmd_server_admin_acq_currency_type' : [
908                 ['oncommand'],
909                 function(event) { open_eg_web_page('acq/currency_type/list', null, event); }
910             ],
911             'cmd_server_admin_acq_exchange_rate' : [
912                 ['oncommand'],
913                 function(event) { open_eg_web_page('conify/global/acq/exchange_rate', null, event); }
914             ],
915             'cmd_server_admin_acq_distrib_formula' : [
916                 ['oncommand'],
917                 function(event) { open_eg_web_page('conify/global/acq/distribution_formula', null, event); }
918             ],
919             'cmd_server_admin_z39_source' : [
920                 ['oncommand'],
921                 function(event) { open_eg_web_page('conify/global/config/z3950_source', null, event); }
922             ],
923             'cmd_server_admin_circ_mod' : [
924                 ['oncommand'],
925                 function(event) { open_eg_web_page('conify/global/config/circ_modifier', null, event); }
926             ],
927             'cmd_server_admin_global_flag' : [
928                 ['oncommand'],
929                 function(event) { open_eg_web_page('conify/global/config/global_flag', null, event); }
930             ],
931             'cmd_server_admin_org_unit_setting_type' : [
932                 ['oncommand'],
933                 function(event) { open_eg_web_page('conify/global/config/org_unit_setting_type', null, event); }
934             ],
935             'cmd_server_admin_usr_setting_type' : [
936                 ['oncommand'],
937                 function(event) { open_eg_web_page('conify/global/config/usr_setting_type', null, event); }
938             ],
939             'cmd_server_admin_booking_resource': [
940                 ['oncommand'],
941                 function(event) { open_eg_web_page('conify/global/booking/resource', null, event); }
942             ],
943             'cmd_server_admin_booking_resource_type': [
944                 ['oncommand'],
945                 function(event) { open_eg_web_page('conify/global/booking/resource_type', null, event); }
946             ],
947             'cmd_server_admin_booking_resource_attr': [
948                 ['oncommand'],
949                 function(event) { open_eg_web_page('conify/global/booking/resource_attr', null, event); }
950             ],
951             'cmd_server_admin_booking_resource_attr_value': [
952                 ['oncommand'],
953                 function(event) { open_eg_web_page('conify/global/booking/resource_attr_value', null, event); }
954             ],
955             'cmd_server_admin_booking_resource_attr_map': [
956                 ['oncommand'],
957                 function(event) { open_eg_web_page('conify/global/booking/resource_attr_map', null, event); }
958             ],
959             'cmd_acq_create_invoice' : [
960                 ['oncommand'],
961                 function(event) { open_eg_web_page('acq/invoice/view?create=1', 'menu.cmd_acq_create_invoice.tab', event); }
962             ],
963             'cmd_acq_view_my_pl' : [
964                 ['oncommand'],
965                 function(event) { open_eg_web_page('acq/search/unified?ca=pl', 'menu.cmd_acq_unified_search.tab', event); }
966             ],
967             'cmd_acq_view_local_po' : [
968                 ['oncommand'],
969                 function(event) { open_eg_web_page('acq/search/unified?ca=po', 'menu.cmd_acq_unified_search.tab', event); }
970             ],
971             'cmd_acq_create_po' : [
972                 ['oncommand'],
973                 function(event) { open_eg_web_page('acq/po/create', 'menu.cmd_acq_po.tab', event); }
974             ],
975             'cmd_acq_view_local_inv' : [
976                 ['oncommand'],
977                 function(event) { open_eg_web_page('acq/search/unified?ca=inv', 'menu.cmd_acq_unified_search.tab', event); }
978             ],
979             'cmd_acq_user_requests' : [
980                 ['oncommand'],
981                 function(event) { open_eg_web_page('acq/picklist/user_request', 'menu.cmd_acq_user_requests.tab', event); }
982             ],
983             'cmd_acq_upload' : [
984                 ['oncommand'],
985                 function(event) { open_eg_web_page('acq/picklist/upload', 'menu.cmd_acq_upload.tab', event); }
986             ],
987             'cmd_acq_bib_search' : [
988                 ['oncommand'],
989                 function(event) { open_eg_web_page('acq/picklist/bib_search', 'menu.cmd_acq_bib_search.tab', event); }
990             ],
991             'cmd_acq_unified_search' : [
992                 ['oncommand'],
993                 function(event) { open_eg_web_page('acq/search/unified', 'menu.cmd_acq_unified_search.tab', event); }
994             ],
995             'cmd_acq_from_bib' : [
996                 ['oncommand'],
997                 function(event) { open_eg_web_page('acq/picklist/from_bib', 'menu.cmd_acq_from_bib.tab', event); }
998             ],
999             'cmd_acq_new_brief_record' : [
1000                 ['oncommand'],
1001                 function(event) { open_eg_web_page('acq/picklist/brief_record', 'menu.cmd_acq_new_brief_record.tab', event); }
1002             ],
1003             'cmd_acq_claim_eligible' : [
1004                 ['oncommand'],
1005                 function(event) { open_eg_web_page('acq/financial/claim_eligible', 'menu.cmd_acq_claim_eligible.tab', event); }
1006             ],
1007             'cmd_booking_reservation' : [
1008                 ['oncommand'],
1009                 function(event) {
1010                     open_eg_web_page(
1011                         "/eg/booking/reservation",
1012                         "menu.cmd_booking_reservation.tab",
1013                         event
1014                     );
1015                 }
1016             ],
1017             'cmd_booking_pull_list' : [
1018                 ['oncommand'],
1019                 function(event) {
1020                     open_eg_web_page(
1021                         "/eg/booking/pull_list",
1022                         "menu.cmd_booking_pull_list.tab",
1023                         event
1024                     );
1025                 }
1026             ],
1027             'cmd_booking_capture' : [
1028                 ['oncommand'],
1029                 function(event) {
1030                     open_eg_web_page(
1031                         "/eg/booking/capture",
1032                         "menu.cmd_booking_capture.tab",
1033                         event
1034                     );
1035                 }
1036             ],
1037             'cmd_booking_reservation_pickup' : [
1038                 ['oncommand'],
1039                 function(event) {
1040                     open_eg_web_page(
1041                         "/eg/booking/pickup",
1042                         "menu.cmd_booking_reservation_pickup.tab",
1043                         event
1044                     );
1045                 }
1046             ],
1047             'cmd_booking_reservation_return' : [
1048                 ['oncommand'],
1049                 function(event) {
1050                     open_eg_web_page(
1051                         "/eg/booking/return",
1052                         "menu.cmd_booking_reservation_return.tab",
1053                         event
1054                     );
1055                 }
1056             ],
1057             'cmd_reprint' : [
1058                 ['oncommand'],
1059                 function() {
1060                     try {
1061                         JSAN.use('util.print'); var print = new util.print();
1062                         print.reprint_last();
1063                     } catch(E) {
1064                         alert(E);
1065                     }
1066                 }
1067             ],
1068
1069             'cmd_retrieve_last_patron' : [
1070                 ['oncommand'],
1071                 function(event) {
1072                     obj.data.stash_retrieve();
1073                     if (!obj.data.last_patron) {
1074                         alert(offlineStrings.getString('menu.cmd_retrieve_last_patron.session.error'));
1075                         return;
1076                     }
1077                     var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1078                     var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1079                     obj.command_tab( event, url, {}, { 'id' : obj.data.last_patron } );
1080                 }
1081             ],
1082             
1083             'cmd_retrieve_last_record' : [
1084                 ['oncommand'],
1085                 function(event) {
1086                     obj.data.stash_retrieve();
1087                     if (!obj.data.last_record) {
1088                         alert(offlineStrings.getString('menu.cmd_retrieve_last_record.session.error'));
1089                         return;
1090                     }
1091                     var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + obj.data.last_record;
1092                     var content_params = {
1093                         'session' : ses(),
1094                         'authtime' : ses('authtime'),
1095                         'opac_url' : opac_url,
1096                     };
1097                     obj.command_tab(
1098                         event,
1099                         obj.url_prefix(urls.XUL_OPAC_WRAPPER),
1100                         {'tab_name' : offlineStrings.getString('menu.cmd_retrieve_last_record.status')},
1101                         content_params
1102                     );
1103                 }
1104             ],
1105
1106             'cmd_verify_credentials' : [
1107                 ['oncommand'],
1108                 function(event) {
1109                     obj.command_tab(
1110                         event,
1111                         obj.url_prefix(urls.XUL_VERIFY_CREDENTIALS),
1112                         { 'tab_name' : offlineStrings.getString('menu.cmd_verify_credentials.tabname') },
1113                         {}
1114                     );
1115                 }
1116             ],
1117
1118             /* Cataloging Menu */
1119             'cmd_z39_50_import' : [
1120                 ['oncommand'],
1121                 function(event) {
1122                     obj.data.stash_retrieve();
1123                     obj.command_tab(event,obj.url_prefix(urls.XUL_Z3950_IMPORT),{},{});
1124                 }
1125             ],
1126             'cmd_create_marc' : [
1127                 ['oncommand'],
1128                 function(event) {
1129                     obj.data.stash_retrieve();
1130                     obj.command_tab(event,obj.url_prefix(urls.XUL_MARC_NEW),{},{});
1131                 }
1132             ],
1133
1134             'cmd_authority_manage' : [
1135                 ['oncommand'],
1136                 function(event) {
1137                     obj.data.stash_retrieve();
1138                     obj.command_tab(event,obj.url_prefix(urls.AUTHORITY_MANAGE),{},{});
1139                 }
1140             ],
1141
1142             'cmd_marc_batch_edit' : [
1143                 ['oncommand'],
1144                 function(event) {
1145                     obj.command_tab(
1146                         event,
1147                         obj.url_prefix(urls.MARC_BATCH_EDIT),{
1148                             'tab_name' : offlineStrings.getString('menu.cmd_marc_batch_edit.tab')
1149                         },
1150                         {}
1151                     );
1152                 }
1153             ],
1154
1155             /* Admin menu */
1156             'cmd_change_session' : [
1157                 ['oncommand'],
1158                 function() {
1159                     try {
1160                         obj.data.stash_retrieve();
1161                         JSAN.use('util.network'); var network = new util.network();
1162                         var temp_au = js2JSON( obj.data.list.au[0] );
1163                         var temp_ses = js2JSON( obj.data.session );
1164                         if (obj.data.list.au.length > 1) {
1165                             obj.data.list.au = [ obj.data.list.au[1] ];
1166                             obj.data.stash('list');
1167                             network.reset_titlebars( obj.data );
1168                             network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
1169                             obj.data.session = obj.data.previous_session;
1170                             obj.data.menu_perms = obj.data.previous_menu_perms;
1171                             obj.data.stash('session');
1172                             obj.data.stash('menu_perms');
1173                             try {
1174                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1175                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
1176                                 var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
1177                                 var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
1178                                 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
1179
1180                                 cookieSvc.setCookieString(cookieUri, null, "ses="+obj.data.session.key, null);
1181                                 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+obj.data.session.key, null);
1182
1183                         } catch(E) {
1184                             alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
1185                         }
1186
1187                         } else {
1188                             if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
1189                                 obj.data.stash_retrieve();
1190                                 obj.data.list.au[1] = JSON2js( temp_au );
1191                                 obj.data.stash('list');
1192                                 obj.data.previous_session = JSON2js( temp_ses );
1193                                 obj.data.previous_menu_perms = obj.data.menu_perms;
1194                                 obj.data.menu_perms = false;
1195                                 obj.data.stash('previous_session');
1196                                 obj.data.stash('previous_menu_perms');
1197                                 obj.data.stash('menu_perms');
1198                             }
1199                         }
1200                         network.set_user_status();
1201                     } catch(E) {
1202                         obj.error.standard_unexpected_error_alert('cmd_change_session',E);
1203                     }
1204                 }
1205             ],
1206             'cmd_manage_offline_xacts' : [
1207                 ['oncommand'],
1208                 function(event) {
1209                     obj.command_tab(event,obj.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS), {'tab_name' : offlineStrings.getString('menu.cmd_manage_offline_xacts.tab')}, {});
1210                 }
1211             ],
1212             'cmd_download_patrons' : [
1213                 ['oncommand'],
1214                 function() {
1215                     try {
1216                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1217                         var x = new XMLHttpRequest();
1218                         var url = 'http://' + XML_HTTP_SERVER + '/standalone/list.txt';
1219                         x.open("GET",url,false);
1220                         x.send(null);
1221                         if (x.status == 200) {
1222                             JSAN.use('util.file'); var file = new util.file('offline_patron_list');
1223                             file.write_content('truncate',x.responseText);
1224                             file.close();
1225                             file = new util.file('offline_patron_list.date');
1226                             file.write_content('truncate',new Date());
1227                             file.close();
1228                             alert(offlineStrings.getString('menu.cmd_download_patrons.complete.status'));
1229                         } else {
1230                             alert(offlineStrings.getFormattedString('menu.cmd_download_patrons.error', [x.status, x.statusText]));
1231                         }
1232                     } catch(E) {
1233                         obj.error.standard_unexpected_error_alert('cmd_download_patrons',E);
1234                     }
1235                 }
1236             ],
1237             'cmd_adv_user_edit' : [
1238                 ['oncommand'],
1239                 function(event) {
1240                     obj.data.stash_retrieve();
1241                     obj.command_tab(event,obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY), {}, { 'perm_editor' : true });
1242                 }
1243             ],
1244             'cmd_print_list_template_edit' : [
1245                 ['oncommand'],
1246                 function(event) {
1247                     obj.data.stash_retrieve();
1248                     obj.command_tab(event,obj.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {});
1249                 }
1250             ],
1251             'cmd_stat_cat_edit' : [
1252                 ['oncommand'],
1253                 function(event) {
1254                     obj.data.stash_retrieve();
1255                     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')},{});
1256                 }
1257             ],
1258             'cmd_non_cat_type_edit' : [
1259                 ['oncommand'],
1260                 function(event) {
1261                     obj.data.stash_retrieve();
1262                     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')},{});
1263                 }
1264             ],
1265             'cmd_copy_location_edit' : [
1266                 ['oncommand'],
1267                 function(event) {
1268                     obj.data.stash_retrieve();
1269                     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')},{});
1270                 }
1271             ],
1272             'cmd_test' : [
1273                 ['oncommand'],
1274                 function(event) {
1275                     obj.data.stash_retrieve();
1276                     var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
1277                     obj.command_tab(event,obj.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
1278                 }
1279             ],
1280             'cmd_test_html' : [
1281                 ['oncommand'],
1282                 function(event) {
1283                     obj.data.stash_retrieve();
1284                     obj.command_tab(event,obj.url_prefix(urls.TEST_HTML) + '?ses='+window.escape(ses()),{ 'browser' : true },{});
1285                 }
1286             ],
1287             'cmd_test_xul' : [
1288                 ['oncommand'],
1289                 function(event) {
1290                     obj.data.stash_retrieve();
1291                     obj.command_tab(event,obj.url_prefix(urls.TEST_XUL) + '?ses='+window.escape(ses()),{ 'browser' : false },{});
1292                 }
1293             ],
1294             'cmd_console' : [
1295                 ['oncommand'],
1296                 function(event) {
1297                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_CONSOLE),{'tab_name' : offlineStrings.getString('menu.cmd_console.tab')},{});
1298                 }
1299             ],
1300             'cmd_shell' : [
1301                 ['oncommand'],
1302                 function(event) {
1303                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_SHELL),{'tab_name' : offlineStrings.getString('menu.cmd_shell.tab')},{});
1304                 }
1305             ],
1306             'cmd_xuleditor' : [
1307                 ['oncommand'],
1308                 function(event) {
1309                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_XULEDITOR),{'tab_name' : offlineStrings.getString('menu.cmd_xuleditor.tab')},{});
1310                 }
1311             ],
1312             'cmd_fieldmapper' : [
1313                 ['oncommand'],
1314                 function(event) {
1315                     obj.command_tab(event,obj.url_prefix(urls.XUL_DEBUG_FIELDMAPPER),{'tab_name' : offlineStrings.getString('menu.cmd_fieldmapper.tab')},{});
1316                 }
1317             ],
1318             'cmd_survey_wizard' : [
1319                 ['oncommand'],
1320                 function() {
1321                     obj.data.stash_retrieve();
1322                     xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome'); 
1323                 }
1324             ],
1325             'cmd_public_opac' : [
1326                 ['oncommand'],
1327                 function(event) {
1328                     var loc = urls.XUL_BROWSER + '?url=' + window.escape(
1329                         obj.url_prefix(urls.remote)
1330                     );
1331                     obj.command_tab(
1332                         event,
1333                         loc, 
1334                         {'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
1335                         { 'no_xulG' : true, 'show_nav_buttons' : true, 'show_print_button' : true } 
1336                     );
1337                 }
1338             ],
1339             'cmd_clear_cache' : [
1340                 ['oncommand'],
1341                 function clear_the_cache() {
1342                     try {
1343                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1344                         var cacheClass         = Components.classes["@mozilla.org/network/cache-service;1"];
1345                         var cacheService    = cacheClass.getService(Components.interfaces.nsICacheService);
1346                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
1347                         cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
1348                     } catch(E) {
1349                         dump(E+'\n');alert(E);
1350                     }
1351                 }
1352             ],
1353             'cmd_restore_all_tabs' : [
1354                 ['oncommand'],
1355                 function() {
1356                     var tabs = obj.controller.view.tabs;
1357                     for (var i = 0; i < tabs.childNodes.length; i++) {
1358                         tabs.childNodes[i].hidden = false;
1359                     }
1360                 }
1361             ],
1362             'cmd_extension_manager' : [
1363                 ['oncommand'],
1364                 function(event) {
1365                     obj.command_tab(event,'chrome://mozapps/content/extensions/extensions.xul?type=extensions',{'tab_name' : offlineStrings.getString('menu.cmd_extension_manager.tab')},{});
1366                 }
1367             ],
1368             'cmd_theme_manager' : [
1369                 ['oncommand'],
1370                 function(event) {
1371                     obj.command_tab(event,'chrome://mozapps/content/extensions/extensions.xul?type=themes',{'tab_name' : offlineStrings.getString('menu.cmd_theme_manager.tab')},{});
1372                 }
1373             ],
1374             'cmd_about_config' : [
1375                 ['oncommand'],
1376                 function(event) {
1377                     obj.command_tab(event,'chrome://global/content/config.xul',{'tab_name' : 'about:config'},{});
1378                 }
1379             ],
1380             'cmd_shutdown' : [
1381                 ['oncommand'],
1382                 function() {
1383                     var confirm_string = offlineStrings.getString('menu.cmd_shutdown.prompt');
1384                     obj.data.stash_retrieve();
1385                     if (typeof obj.data.unsaved_data != 'undefined') {
1386                         if (obj.data.unsaved_data > 0) {
1387                             confirm_string = offlineStrings.getString('menu.shutdown.unsaved_data_warning');
1388                         }
1389                     }
1390                     if (window.confirm(confirm_string)) {
1391                         obj.data.unsaved_data = 0; // just in case the program doesn't close somehow
1392                         obj.data.stash('unsaved_data');
1393                         dump('forcing data.unsaved_data == ' + obj.data.unsaved_data + '\n');
1394                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1395                         var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1396                         var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1397                         var enumerator = windowManagerInterface.getEnumerator(null);
1398                         var w; // close all other windows
1399                         while ( w = enumerator.getNext() ) {
1400                             if (w != window) {
1401                                 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
1402                             }
1403                         }
1404                         window.close();
1405                     }
1406                 }
1407             ],
1408             'cmd_hotkeys_toggle' : [
1409                 ['oncommand'],
1410                 function() {
1411                     // Easy enough, toggle disabled on the keyset
1412                     var keyset = document.getElementById("menu_frame_keys");
1413                     var disabled = (keyset.getAttribute("disabled") == "true") ? "false" : "true";
1414                     if(disabled == "true")
1415                         keyset.setAttribute("disabled", "true");
1416                     else
1417                         keyset.removeAttribute("disabled");
1418                     // Then find every menuitem/toolbarbutton for this command for a graphical hint
1419                     var controls = document.getElementsByAttribute("command","cmd_hotkeys_toggle");
1420                     for(var i = 0; i < controls.length; i++)
1421                         controls[i].setAttribute("checked",disabled);
1422                 }
1423             ],
1424             'cmd_hotkeys_set' : [
1425                 ['oncommand'],
1426                 function(event) {
1427                     obj.set_menu_hotkeys(event.explicitOriginalTarget.getAttribute('value'));
1428                 }
1429             ],
1430             'cmd_hotkeys_setworkstation' : [
1431                 ['oncommand'],
1432                 function() {
1433                     xulG.pref.setCharPref('open-ils.menu.hotkeyset', obj.data.current_hotkeyset);
1434                 }
1435             ],
1436             'cmd_hotkeys_clearworkstation' : [
1437                 ['oncommand'],
1438                 function() {
1439                     if(xulG.pref.prefHasUserValue('open-ils.menu.hotkeyset'))
1440                         xulG.pref.clearUserPref('open-ils.menu.hotkeyset');
1441                 }
1442             ],
1443             'cmd_toolbar_set' : [
1444                 ['oncommand'],
1445                 function(event) {
1446                     var newToolbar = event.explicitOriginalTarget.getAttribute('value');
1447                     var toolbox = document.getElementById('main_toolbox');
1448                     var toolbars = toolbox.getElementsByTagName('toolbar');
1449                     for(var i = 0; i < toolbars.length; i++) {
1450                         if(toolbars[i].id == 'toolbar_' + newToolbar)
1451                             toolbars[i].setAttribute('hidden', 'false');
1452                         else
1453                             toolbars[i].setAttribute('hidden', 'true');
1454                     }
1455                     obj.toolbar = newToolbar;
1456                 }
1457             ],
1458             'cmd_toolbar_mode_set' : [
1459                 ['oncommand'],
1460                 function(event) {
1461                     var newMode = event.explicitOriginalTarget.getAttribute('value');
1462                     var toolbox = document.getElementById('main_toolbox');
1463                     var toolbars = toolbox.getElementsByTagName('toolbar');
1464                     for(var i = 0; i < toolbars.length; i++)
1465                         toolbars[i].setAttribute("mode",newMode);
1466                     obj.toolbar_mode = newMode;
1467                 }
1468             ],
1469             'cmd_toolbar_size_set' : [
1470                 ['oncommand'],
1471                 function(event) {
1472                     var newSize = event.explicitOriginalTarget.getAttribute('value');
1473                     var toolbox = document.getElementById('main_toolbox');
1474                     var toolbars = toolbox.getElementsByTagName('toolbar');
1475                     for(var i = 0; i < toolbars.length; i++)
1476                         toolbars[i].setAttribute("iconsize",newSize);
1477                     obj.toolbar_size = newSize;
1478                 }
1479             ],
1480             'cmd_toolbar_label_position_set' : [
1481                 ['oncommand'],
1482                 function(event) {
1483                     var altPosition = (event.explicitOriginalTarget.getAttribute('value') == "under");
1484                     var toolbox = document.getElementById('main_toolbox');
1485                     var toolbars = toolbox.getElementsByTagName('toolbar');
1486                     for(var i = 0; i < toolbars.length; i++) {
1487                         if(altPosition)
1488                             addCSSClass(toolbars[i], 'labelbelow');
1489                         else
1490                             removeCSSClass(toolbars[i], 'labelbelow');
1491                     }
1492                     obj.toolbar_labelpos = (altPosition ? "under" : "side");
1493                 }
1494             ],
1495             'cmd_toolbar_setworkstation' : [
1496                 ['oncommand'],
1497                 function() {
1498                 xulG.pref.setCharPref('open-ils.menu.toolbar', obj.toolbar);
1499                 xulG.pref.setCharPref('open-ils.menu.toolbar.iconsize', obj.toolbar_size);
1500                 xulG.pref.setCharPref('open-ils.menu.toolbar.mode', obj.toolbar_mode);
1501                 xulG.pref.setBoolPref('open-ils.menu.toolbar.labelbelow', (obj.toolbar_labelpos == "under"));
1502                 }
1503             ],
1504             'cmd_toolbar_clearworkstation' : [
1505                 ['oncommand'],
1506                 function() {
1507                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar'))
1508                         xulG.pref.clearUserPref('open-ils.menu.toolbar');
1509                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.iconsize'))
1510                         xulG.pref.clearUserPref('open-ils.menu.toolbar.iconsize');
1511                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.mode'))
1512                         xulG.pref.clearUserPref('open-ils.menu.toolbar.mode');
1513                     if(xulG.pref.prefHasUserValue('open-ils.menu.toolbar.labelbelow'))
1514                         xulG.pref.clearUserPref('open-ils.menu.toolbar.labelbelow');
1515                 }
1516             ],
1517         };
1518
1519         JSAN.use('util.controller');
1520         var cmd;
1521         obj.controller = new util.controller();
1522         obj.controller.init( { 'window_knows_me_by' : 'g.menu.controller', 'control_map' : cmd_map } );
1523
1524         obj.controller.view.tabbox = window.document.getElementById('main_tabbox');
1525         // Despite what the docs say:
1526         // The "tabs" element need not be the first child
1527         // The "panels" element need not be the second/last
1528         // Nor need they be the only ones there.
1529         // Thus, use the IDs for robustness.
1530         obj.controller.view.tabs = window.document.getElementById('main_tabs');
1531         obj.controller.view.panels = window.document.getElementById('main_panels');
1532         obj.controller.view.tabscroller = window.document.getElementById('main_tabs_scrollbox');
1533         if(params['firstURL']) {
1534             obj.new_tab(params['firstURL'],{'focus':true},null);
1535         }
1536         else {
1537             obj.new_tab(null,{'focus':true},null);
1538         }
1539     },
1540
1541     'spawn_search' : function(s) {
1542         var obj = this;
1543         obj.error.sdump('D_TRACE', offlineStrings.getFormattedString('menu.spawn_search.msg', [js2JSON(s)]) ); 
1544         obj.new_patron_tab( {}, { 'doit' : 1, 'query' : js2JSON(s) } );
1545     },
1546
1547     'close_all_tabs' : function() {
1548         var obj = this;
1549         try {
1550             var count = obj.controller.view.tabs.childNodes.length;
1551             for (var i = 1; i < count; i++) obj.close_tab();
1552             setTimeout( function(){ obj.controller.view.tabs.firstChild.focus(); }, 0);
1553         } catch(E) {
1554             obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.close_all_tabs.error'),E);
1555         }
1556     },
1557
1558     'close_tab' : function (specific_idx) {
1559         var idx = specific_idx || this.controller.view.tabs.selectedIndex;
1560         var panel = this.controller.view.panels.childNodes[ idx ];
1561
1562         var tab = this.controller.view.tabs.getItemAtIndex( idx );
1563         var id = tab.getAttribute('id');
1564         if (typeof this.tab_semaphores[id] != 'undefined') {
1565             if (this.tab_semaphores[id] > 0) {
1566                 var confirmation = window.confirm(offlineStrings.getString('menu.close_tab.unsaved_data_warning'));
1567                 if (!confirmation) { return; }
1568                 oils_unsaved_data_P( this.tab_semaphores[id] );
1569             }
1570             delete this.tab_semaphores[id];
1571         }
1572
1573         this.controller.view.tabs.removeItemAt(idx);
1574         this.controller.view.panels.removeChild(panel);
1575         if(this.controller.view.tabs.childNodes.length > idx) {
1576             this.controller.view.tabbox.selectedIndex = idx;
1577         }
1578         else {
1579             this.controller.view.tabbox.selectedIndex = idx - 1;
1580         }
1581         this.controller.view.tabscroller.ensureElementIsVisible(this.controller.view.tabs.selectedItem);
1582         this.update_all_tab_names();
1583         // Make sure we keep at least one tab open.
1584         if(this.controller.view.tabs.childNodes.length == 1) {
1585             this.new_tab(); 
1586         }
1587     },
1588     
1589     'update_all_tab_names' : function() {
1590         var doAccessKeys = !xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs');
1591         for(var i = 1; i < this.controller.view.tabs.childNodes.length; ++i) {
1592             var tab = this.controller.view.tabs.childNodes[i];
1593             tab.curindex = i;
1594             tab.label = i + ' ' + tab.origlabel;
1595             if(doAccessKeys && offlineStrings.testString('menu.tab' + i + '.accesskey')) {
1596                 tab.accessKey = offlineStrings.getString('menu.tab' + i + '.accesskey');
1597             }
1598         }
1599     },
1600
1601     'command_tab' : function(event,url,params,content_params) {
1602         var newTab = false;
1603         var myEvent = event;
1604         if(event && event.sourceEvent) myEvent = event.sourceEvent;
1605         // Note: The last event is not supposed to be myEvent in this if.
1606         if(myEvent && myEvent.explicitOriginalTarget.nodeName.match(/toolbarbutton/) && myEvent.explicitOriginalTarget.command == event.originalTarget.id) {
1607             var value = xulG.pref.getIntPref('ui.key.accelKey');
1608             switch(value) {
1609                 case 17:
1610                     newTab = myEvent.ctrlKey;
1611                     break;
1612                 case 18:
1613                     newTab = myEvent.altKey;
1614                     break;
1615                 case 224:
1616                     newTab = myEvent.metaKey;
1617                     break;
1618             }
1619             try {
1620                 if(xulG.pref.getBoolPref('open-ils.toolbar.defaultnewtab')) {
1621                     newTab = !newTab;
1622                 }
1623             }
1624             catch (e) {
1625             }
1626         }
1627         if(newTab) {
1628             this.new_tab(url,params,content_params);
1629         }
1630         else {
1631             this.set_tab(url,params,content_params);
1632         }
1633     },
1634
1635     'new_tab' : function(url,params,content_params) {
1636         var obj = this;
1637         var max_tabs = 0;
1638         try {
1639             var max_tabs = xulG.pref.getIntPref('open-ils.window_max_tabs') || max_tabs;
1640         }
1641         catch (e) {}
1642         if(max_tabs > 0 && this.controller.view.tabs.childNodes.length > max_tabs) return false;
1643         var tab = this.w.document.createElement('tab');
1644         var panel = this.w.document.createElement('tabpanel');
1645         var tabscroller = this.controller.view.tabscroller;
1646         this.controller.view.tabs.appendChild(tab);
1647         this.controller.view.panels.appendChild(panel);
1648         tab.curindex = this.controller.view.tabs.childNodes.length - 1;
1649         if(!xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs')) {
1650             if(offlineStrings.testString('menu.tab' + tab.curindex + '.accesskey')) {
1651                 tab.accessKey = offlineStrings.getString('menu.tab' + tab.curindex + '.accesskey');
1652             }
1653         }
1654         var tabs = this.controller.view.tabs;
1655         tab.addEventListener(
1656             'command',
1657             function() {
1658                 try {
1659                     tabscroller.ensureElementIsVisible(tab);
1660                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1661                     if (panel
1662                         && panel.firstChild 
1663                         && ( panel.firstChild.nodeName == 'iframe' || panel.firstChild.nodeName == 'browser' )
1664                         && panel.firstChild.contentWindow 
1665                     ) {
1666                         var cw = panel.firstChild.contentWindow;
1667                         var help_params = {
1668                             'protocol' : cw.location.protocol,
1669                             'hostname' : cw.location.hostname,
1670                             'port' : cw.location.port,
1671                             'pathname' : cw.location.pathname,
1672                             'src' : ''
1673                         };
1674                         obj.set_help_context(help_params);
1675                         if (typeof cw.default_focus == 'function') {
1676                             cw.default_focus();
1677                         }
1678                     }
1679                 } catch(E) {
1680                     obj.error.sdump('D_ERROR','init_tab_focus_handler: ' + js2JSON(E));
1681                 }
1682             }
1683             ,
1684             false
1685         );
1686         if (!content_params) content_params = {};
1687         if (!params) params = {};
1688         if (!params.tab_name) params.tab_name = offlineStrings.getString('menu.new_tab.tab');
1689         if (!params.nofocus) params.focus = true; /* make focus the default */
1690         try {
1691             if (params.focus) {
1692                 this.controller.view.tabs.selectedItem = tab;
1693                 tabscroller.ensureElementIsVisible(tab);
1694             }
1695             params.index = tab.curindex;
1696             this.set_tab(url,params,content_params);
1697             return true;
1698         } catch(E) {
1699             this.error.sdump('D_ERROR',E);
1700             return false;
1701         }
1702     },
1703
1704     'set_menu_access' : function(perms) {
1705         if(perms === false) return;
1706         var commands = document.getElementById('universal_cmds').getElementsByTagName('command');
1707         var commandperms;
1708 commands:
1709         for (var i = 0; i < commands.length; i++) { 
1710             if (commands[i].hasAttribute('perm')) {
1711                 commandperms = commands[i].getAttribute('perm').split(' ');
1712                 for (var j = 0; j < commandperms.length; j++) {
1713                     if (perms[commandperms[j]]) {
1714                         commands[i].setAttribute('disabled','false');
1715                         continue commands;
1716                     }
1717                 }
1718                 commands[i].setAttribute('disabled','true');
1719             }           
1720         }
1721
1722     },
1723
1724     'set_menu_hotkeys' : function(hotkeyset) {
1725         this.data.stash_retrieve();
1726
1727         var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
1728                     getService(Components.interfaces.nsIWindowMediator);
1729         var mainwin = wm.getMostRecentWindow('eg_main');
1730         JSAN.use('util.network');
1731         var network = new util.network();
1732
1733         if(hotkeyset) { // Explicit request
1734             // Store
1735             this.data.current_hotkeyset = hotkeyset;
1736             this.data.stash('current_hotkeyset');
1737             // Then iterate over windows
1738             var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
1739             var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
1740             var enumerator = windowManagerInterface.getEnumerator('eg_menu');
1741
1742             var w;
1743             while ( w = enumerator.getNext() ) {
1744                 if ( w != window )
1745                     w.g.menu.set_menu_hotkeys();
1746             }
1747         }
1748         else { // Non-explicit request?
1749             if(this.data.current_hotkeyset) // Previous hotkeyset?
1750                 hotkeyset = this.data.current_hotkeyset; // Use it
1751             else { // No previous? We need to decide on one!
1752                 // Load the list so we know if what we are being asked to load is valid.
1753                 var hotkeysets = mainwin.load_hotkey_sets();
1754                 if(!hotkeysets) return; // No sets = nothing to load. Which is probably an error, but meh.
1755                 hotkeysets.has = function(test) {
1756                     for(i = 0; i < this.length; i++) {
1757                         if(this[i] == test) return true;
1758                     }
1759                     return false;
1760                 }; 
1761                 // Try workstation (pref)
1762                 hotkeyset = xulG.pref.getCharPref('open-ils.menu.hotkeyset');
1763
1764                 // Nothing or nothing valid?
1765                 if(!hotkeyset || !hotkeysets.has(hotkeyset)) {
1766                     hotkeyset = this.data.hash.aous['ui.general.hotkeyset'];
1767                 }
1768                 // STILL nothing? Try Default.
1769                 if(!hotkeyset || !hotkeysets.has(hotkeyset)) {
1770                     if(hotkeysets.has('Default'))
1771                         hotkeyset = 'Default';
1772                     else
1773                         return false;
1774                 }
1775                 // And save whatever we are using.
1776                 this.data.current_hotkeyset = hotkeyset;
1777                 this.data.stash('current_hotkeyset');
1778             }
1779         }
1780         // Clear out all the old hotkeys
1781         var keyset = document.getElementById('menu_frame_keys');
1782         var main_menu = document.getElementById('main_menubar');
1783         if(keyset.hasChildNodes()) {
1784             var menuitems = main_menu.getElementsByAttribute('key','*');
1785             while(menuitems.length > 0) {
1786                 var menuitem = menuitems[0];
1787                 menuitem.removeAttribute('key');
1788                 // Trick/force mozilla to re-evaluate the menuitem
1789                 // If you want to take this trick for use *anywhere* in *any* project, regardless of licensing, please do
1790                 // Because it was a PITA to figure out
1791                 menuitem.style.display = 'none'; // Hide the item to force menu to clear spot
1792                 menuitem.setAttribute('acceltext', ''); // Set acceltext to blank string outright
1793                 menuitem.removeAttribute('acceltext'); // Remove acceltext to clear out hotkey hint text
1794                 menuitem.parentNode.openPopupAtScreen(0,0,false); // Tell menupopup to redraw itself
1795                 menuitem.parentNode.hidePopup(); // And then make it go away right away.
1796                 menuitem.style.removeProperty('display'); // Restore normal css display
1797             }
1798             while(keyset.hasChildNodes()) keyset.removeChild(keyset.childNodes[0]);
1799         }
1800         keyset_lines = mainwin.get_hotkey_array(hotkeyset);
1801         // Next, fill the keyset
1802         for(var line = 0; line < keyset_lines.length; line++) {
1803             // Create and populate our <key>
1804             var key_node = document.createElement('key');
1805             key_node.setAttribute('id',keyset_lines[line][0] + "_key");
1806             key_node.setAttribute('command',keyset_lines[line][0]);
1807             key_node.setAttribute('modifiers',keyset_lines[line][1]);
1808             // If keycode starts with VK_ we assume it is a key code.
1809             // Key codes go in the keycode attribute
1810             // Regular keys (like "i") go in the key attribute
1811             if(keyset_lines[line][2].match(/^VK_/))
1812                 key_node.setAttribute('keycode',keyset_lines[line][2]);
1813             else
1814                 key_node.setAttribute('key',keyset_lines[line][2]);
1815             // If a fourth option was specified, set keytext to it.
1816             if(keyset_lines[line][3])
1817                 key_node.setAttribute('keytext',keyset_lines[line][3]);
1818             // Add the new node to the DOM
1819             keyset.appendChild(key_node);
1820             // And populate all the menu items that should now display it
1821             var menuitems = main_menu.getElementsByAttribute('command',keyset_lines[line][0]);
1822             for(var i = 0; i < menuitems.length; i++) {
1823                 menuitems[i].setAttribute('key', keyset_lines[line][0] + "_key");
1824                 // Trick/force mozilla to re-evaluate the menuitem
1825                 menuitems[i].style.display = 'none'; // Hide the item to force menu to clear spot
1826                 menuitems[i].parentNode.openPopupAtScreen(0,0,false); // Tell menupopup to redraw itself
1827                 menuitems[i].parentNode.hidePopup(); // And then make it go away right away
1828                 menuitems[i].style.removeProperty('display'); // Restore normal css display
1829             }
1830         }
1831         // Force reload of keyset cache?
1832         keyset.parentNode.insertBefore(keyset, keyset.nextSibling);
1833         // If no keys, disable ability to toggle hotkeys (because why bother?)
1834         var x = document.getElementById('cmd_hotkeys_toggle');
1835         if(x) {
1836             if(keyset.hasChildNodes())
1837                 x.removeAttribute('disabled');
1838             else
1839                 x.setAttribute('disabled', 'true');
1840         }
1841         // Select the hotkey set in the menu
1842         // This ensures that first window load OR remote window update shows properly
1843         var hotkeylist = document.getElementById('main.menu.admin.client.hotkeys.current.popup');
1844         var selectitems = hotkeylist.getElementsByAttribute('value',hotkeyset);
1845         if(selectitems.length > 0) selectitems[0].setAttribute('checked','true');
1846     },
1847
1848     'page_meter' : {
1849         'node' : document.getElementById('page_progress'),
1850         'on' : function() {
1851             document.getElementById('page_progress').setAttribute('mode','undetermined');
1852         },
1853         'off' : function() {
1854             document.getElementById('page_progress').setAttribute('mode','determined');
1855         },
1856         'tooltip' : function(text) {
1857             if (text || text == '') {
1858                 document.getElementById('page_progress').setAttribute('tooltiptext',text);
1859             }
1860             return document.getElementById('page_progress').getAttribute('tooltiptext');
1861         }
1862     },
1863
1864     'network_meter' : {
1865         'inc' : function(app,method) {
1866             try {
1867                 var m = document.getElementById('network_progress');
1868                 var count = 1 + Number( m.getAttribute('count') );
1869                 m.setAttribute('mode','undetermined');
1870                 m.setAttribute('count', count);
1871                 var rows = document.getElementById('network_progress_rows');
1872                 var row = document.getElementById('network_progress_tip_'+app+'_'+method);
1873                 if (!row) {
1874                     row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
1875                     var a = document.createElement('label'); a.setAttribute('value','App:');
1876                     var b = document.createElement('label'); b.setAttribute('value',app);
1877                     var c = document.createElement('label'); c.setAttribute('value','Method:');
1878                     var d = document.createElement('label'); d.setAttribute('value',method);
1879                     var e = document.createElement('label'); e.setAttribute('value','Total:');
1880                     var f = document.createElement('label'); f.setAttribute('value','0'); 
1881                     f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
1882                     var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
1883                     var h = document.createElement('label'); h.setAttribute('value','0');
1884                     h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
1885                     row.appendChild(a); row.appendChild(b); row.appendChild(c);
1886                     row.appendChild(d); row.appendChild(e); row.appendChild(f);
1887                     row.appendChild(g); row.appendChild(h); rows.appendChild(row);
1888                 }
1889                 var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
1890                 if (total) {
1891                     total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
1892                 }
1893                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1894                 if (out) {
1895                     out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
1896                 }
1897             } catch(E) {
1898                 dump('network_meter.inc(): ' + E + '\n');
1899             }
1900         },
1901         'dec' : function(app,method) {
1902             try {
1903                 var m = document.getElementById('network_progress');
1904                 var count = -1 + Number( m.getAttribute('count') );
1905                 if (count < 0) count = 0;
1906                 if (count == 0) m.setAttribute('mode','determined');
1907                 m.setAttribute('count', count);
1908                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1909                 if (out) {
1910                     out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
1911                 }
1912             } catch(E) {
1913                 dump('network_meter.dec(): ' + E + '\n');
1914             }
1915         }
1916     },
1917     'set_patron_tab' : function(params,content_params,event) {
1918         var obj = this;
1919         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1920         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1921         obj.command_tab(event,url,params ? params : {},content_params ? content_params : {});
1922     },
1923     'new_patron_tab' : function(params,content_params) {
1924         var obj = this;
1925         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1926         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1927         obj.new_tab(url,params ? params : {},content_params ? content_params : {});
1928     },
1929     'volume_item_creator' : function(params) {
1930         var obj = this;
1931         var url;
1932         var unified_interface = String( obj.data.hash.aous['ui.unified_volume_copy_editor'] ) == 'true';
1933         if (unified_interface) {
1934             var horizontal_interface = String( obj.data.hash.aous['ui.cat.volume_copy_editor.horizontal'] ) == 'true';
1935             url = obj.url_prefix( horizontal_interface ? urls.XUL_VOLUME_COPY_CREATOR_HORIZONTAL : urls.XUL_VOLUME_COPY_CREATOR );
1936         } else {
1937             url = obj.url_prefix( urls.XUL_VOLUME_COPY_CREATOR_ORIGINAL );
1938         }
1939         var w = obj.new_tab(
1940             url,
1941             { 'tab_name' : document.getElementById('offlineStrings').getString('staff.cat.create_or_rebarcode_items') },
1942             params
1943         );
1944     },
1945     'holdings_maintenance_tab' : function(docid,params,content_params) {
1946         var obj = this;
1947         if (!content_params) {
1948             content_params = {};
1949         }
1950         if (docid) {
1951             content_params['docid'] = docid;
1952         }
1953         var url = obj.url_prefix( urls.XUL_COPY_VOLUME_BROWSE );
1954         obj.new_tab(url,params || {}, content_params);
1955     },
1956     'get_new_session' : function(params) {
1957         var obj = this;
1958         if (!params) { params = {}; }
1959         JSAN.use('util.network'); var net = new util.network();
1960         var result = net.get_new_session(null,{'url_prefix':obj.url_prefix},!params.operator_change);
1961         if (typeof params.callback == 'function') {
1962             return params.callback( result, ses(), ses('authtime') );
1963         }
1964         return result;
1965     },
1966     'set_help_context' : function(params) {
1967         var obj = this;
1968         if (!params) { params = {}; }
1969         if (params.protocol == 'chrome:') { return; } /* not supported */
1970         var help_btn = document.getElementById('help_btn');
1971         if (help_btn) {
1972             dump('set_help_context: ' + js2JSON(params) + '\n');
1973             if (params.protocol) { help_btn.setAttribute('protocol', params.protocol); }
1974             if (params.hostname) { help_btn.setAttribute('hostname', params.hostname);  }
1975             if (params.port) { help_btn.setAttribute('port', params.port);  }
1976             if (params.pathname) { help_btn.setAttribute('pathname', params.pathname); }
1977             if (params.src) { help_btn.setAttribute('src', params.src); }
1978         }
1979     },
1980
1981     'tab_semaphores' : {},
1982
1983     'set_tab' : function(url,params,content_params) {
1984         var obj = this;
1985         if (!url) url = '/xul/server/';
1986         if (!url.match(/:\/\//) && !url.match(/^data:/)) url = urls.remote + url;
1987         if (!params) params = {};
1988         if (!content_params) content_params = {};
1989         var idx = this.controller.view.tabs.selectedIndex;
1990         if (params && typeof params.index != 'undefined') idx = params.index;
1991         var tab = this.controller.view.tabs.childNodes[ idx ];
1992
1993         var id = tab.getAttribute('id');
1994         if (id) {
1995             if (typeof obj.tab_semaphores[id] != 'undefined') {
1996                 if (obj.tab_semaphores[id] > 0) {
1997                     var confirmation = window.confirm(offlineStrings.getString('menu.replace_tab.unsaved_data_warning'));
1998                     if (!confirmation) { return; }
1999                     oils_unsaved_data_P( obj.tab_semaphores[id] );
2000                 }
2001                 delete obj.tab_semaphores[id];
2002             }
2003         }
2004         var unique_id = idx + ':' + new Date();
2005         tab.setAttribute('id',unique_id);
2006         if (params.focus) tab.focus();
2007         var panel = this.controller.view.panels.childNodes[ idx ];
2008         while ( panel.lastChild ) panel.removeChild( panel.lastChild );
2009
2010         content_params.lock_tab = function() { 
2011             dump('lock_tab\n');
2012             var id = tab.getAttribute('id');
2013             if (typeof obj.tab_semaphores[id] == 'undefined') {
2014                 obj.tab_semaphores[id] = 0;
2015             }
2016             obj.tab_semaphores[id]++; 
2017             oils_unsaved_data_V();
2018             return obj.tab_semaphores[id]; 
2019         };
2020         content_params.unlock_tab = function() { 
2021             dump('unlock_tab\n');
2022             var id = tab.getAttribute('id');
2023             if (typeof obj.tab_semaphores[id] == 'undefined') {
2024                 obj.tab_semaphores[id] = 0;
2025             }
2026             obj.tab_semaphores[id]--;
2027             if (obj.tab_semaphores[id] < 0) { obj.tab_semaphores[id] = 0; } 
2028             oils_unsaved_data_P();
2029             return obj.tab_semaphores[id]; 
2030         };
2031         content_params.inspect_tab = function() {
2032             var id = tab.getAttribute('id');
2033             return 'id = ' + id + ' semaphore = ' + obj.tab_semaphores[id];
2034         }
2035         content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); };
2036         content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); };
2037         content_params.close_tab = function() { return obj.close_tab(); };
2038         content_params.new_patron_tab = function(a,b) { return obj.new_patron_tab(a,b); };
2039         content_params.set_patron_tab = function(a,b) { return obj.set_patron_tab(a,b); };
2040         content_params.volume_item_creator = function(a) { return obj.volume_item_creator(a); };
2041         content_params.get_new_session = function(a) { return obj.get_new_session(a); };
2042         content_params.holdings_maintenance_tab = function(a,b,c) { return obj.holdings_maintenance_tab(a,b,c); };
2043         content_params.set_tab_name = function(name) { tab.label = tab.curindex + ' ' + name; tab.origlabel = name; };
2044         content_params.set_help_context = function(params) { return obj.set_help_context(params); };
2045         content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
2046         content_params.url_prefix = function(url) { return obj.url_prefix(url); };
2047         content_params.network_meter = obj.network_meter;
2048         content_params.page_meter = obj.page_meter;
2049         content_params.set_statusbar = function(slot,text,tooltiptext,click_handler) {
2050             var e = document.getElementById('statusbarpanel'+slot);
2051             if (e) {
2052                 var p = e.parentNode;
2053                 var sbp = document.createElement('statusbarpanel');
2054                 sbp.setAttribute('id','statusbarpanel'+slot);
2055                 p.replaceChild(sbp,e); // destroy and replace the statusbarpanel as a poor man's way of clearing event handlers
2056
2057                 sbp.setAttribute('label',text);
2058                 if (tooltiptext) {
2059                     sbp.setAttribute('tooltiptext',tooltiptext);
2060                 }
2061                 if (click_handler) {
2062                     sbp.addEventListener(
2063                         'click',
2064                         click_handler,
2065                         false
2066                     );
2067                 }
2068             }
2069         };
2070         content_params.chrome_xulG = xulG;
2071         content_params._data = xulG._data;
2072         if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
2073         
2074         var frame;
2075         try {
2076             if (typeof params.browser == 'undefined') params.browser = false;
2077             if (params.browser) {
2078                 obj.id_incr++;
2079                 frame = this.w.document.createElement('browser');
2080                 frame.setAttribute('flex','1');
2081                 frame.setAttribute('type','content');
2082                 frame.setAttribute('autoscroll','false');
2083                 frame.setAttribute('id','frame_'+obj.id_incr);
2084                 panel.appendChild(frame);
2085                 try {
2086                     dump('creating browser with src = ' + url + '\n');
2087                     JSAN.use('util.browser');
2088                     var b = new util.browser();
2089                     b.init(
2090                         {
2091                             'url' : url,
2092                             'push_xulG' : true,
2093                             'alt_print' : false,
2094                             'browser_id' : 'frame_'+obj.id_incr,
2095                             'passthru_content_params' : content_params,
2096                         }
2097                     );
2098                 } catch(E) {
2099                     alert(E);
2100                 }
2101             } else {
2102                 frame = this.w.document.createElement('iframe');
2103                 frame.setAttribute('flex','1');
2104                 panel.appendChild(frame);
2105                 dump('creating iframe with src = ' + url + '\n');
2106                 frame.setAttribute('src',url);
2107                 try {
2108                     netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
2109                     var cw = frame.contentWindow;
2110                     if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject;
2111                     cw.IAMXUL = true;
2112                     cw.xulG = content_params;
2113                     cw.addEventListener(
2114                         'load',
2115                         function() {
2116                             try {
2117                                 if (typeof cw.help_context_set_locally == 'undefined') {
2118                                     var help_params = {
2119                                         'protocol' : cw.location.protocol,
2120                                         'hostname' : cw.location.hostname,
2121                                         'port' : cw.location.port,
2122                                         'pathname' : cw.location.pathname,
2123                                         'src' : ''
2124                                     };
2125                                     obj.set_help_context(help_params);
2126                                 } else if (typeof cw.default_focus == 'function') {
2127                                     cw.default_focus();
2128                                 }
2129                             } catch(E) {
2130                                 obj.error.sdump('D_ERROR', 'main.menu, set_tab, onload: ' + E);
2131                             }
2132                         },
2133                         false
2134                     );
2135                 } catch(E) {
2136                     this.error.sdump('D_ERROR', 'main.menu: ' + E);
2137                 }
2138             }
2139         } catch(E) {
2140             this.error.sdump('D_ERROR', 'main.menu:2: ' + E);
2141             alert(offlineStrings.getString('menu.set_tab.error'));
2142         }
2143
2144         return frame;
2145     }
2146
2147 }
2148
2149 dump('exiting main/menu.js\n');