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