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