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