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