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