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