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