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