plugged in click actions for conify pages
[Evergreen.git] / Open-ILS / xul / staff_client / chrome / content / main / menu.js
1 dump('entering main/menu.js\n');
2 // vim:noet:sw=4:ts=4:
3
4 var offlineStrings;
5
6 if (typeof main == 'undefined') main = {};
7 main.menu = function () {
8
9     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
10     offlineStrings = document.getElementById('offlineStrings');
11         JSAN.use('util.error'); this.error = new util.error();
12         JSAN.use('util.window'); this.window = new util.window();
13
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         if (xulG.pref.getBoolPref('open-ils.disable_accesskeys_on_tabs')) {
31                 var tabs = document.getElementById('main_tabs');
32                 for (var i = 0; i < tabs.childNodes.length; i++) {
33                         tabs.childNodes[i].setAttribute('accesskey','');
34                 }
35         }
36 }
37
38 main.menu.prototype = {
39
40         'id_incr' : 0,
41
42         'url_prefix' : function(url) {
43                 if (url.match(/^\//)) url = urls.remote + url;
44                 if (! url.match(/^(http|chrome):\/\//) && ! url.match(/^data:/) ) url = 'http://' + url;
45                 dump('url_prefix = ' + url + '\n');
46                 return url;
47         },
48
49         'init' : function( params ) {
50
51                 urls.remote = params['server'];
52
53                 var obj = this;
54
55                 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
56
57         var button_bar = String( obj.data.hash.aous['ui.general.button_bar'] ) == 'true';
58         if (button_bar) {
59             var x = document.getElementById('main_toolbar');
60             if (x) x.setAttribute('hidden','false');
61         }
62
63         function open_conify_page(path, labelKey, old_school) {
64
65             // tab label
66             labelKey = labelKey || 'menu.cmd_open_conify.tab';
67             label = offlineStrings.getString(labelKey);
68
69             // URL
70             var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(urls.EG_WEB_BASE + '/conify/global/' + path);
71             if(old_school)
72                 loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(urls.CONIFY + '/' + path + '.html');
73
74             obj.set_tab( 
75                 loc, 
76                 {'tab_name' : label, 'browser' : false }, 
77                 {'no_xulG' : false, 'show_print_button' : false} 
78             );
79         }
80
81
82                 var cmd_map = {
83                         'cmd_broken' : [
84                                 ['oncommand'],
85                                 function() { alert(offlineStrings.getString('common.unimplemented')); }
86                         ],
87
88                         /* File Menu */
89                         'cmd_close_window' : [ 
90                                 ['oncommand'], 
91                                 function() { window.close(); } 
92                         ],
93                         'cmd_new_window' : [
94                                 ['oncommand'],
95                                 function() {
96                                         obj.data.stash_retrieve();
97                                         var mframe = obj.window.open(
98                                                 obj.url_prefix(urls.XUL_MENU_FRAME)
99                                                 + '?server='+window.escape(urls.remote),
100                                                 'main' + obj.window.window_name_increment(),
101                                                 'chrome,resizable'); 
102                     netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
103                     mframe.xulG = xulG;
104                                 }
105                         ],
106                         'cmd_new_tab' : [
107                                 ['oncommand'],
108                                 function() { obj.new_tab(null,{'focus':true},null); }
109                         ],
110                         'cmd_close_tab' : [
111                                 ['oncommand'],
112                                 function() { obj.close_tab(); }
113                         ],
114                         'cmd_close_all_tabs' : [
115                                 ['oncommand'],
116                                 function() { obj.close_all_tabs(); }
117                         ],
118
119                         /* Edit Menu */
120                         'cmd_edit_copy_buckets' : [
121                                 ['oncommand'],
122                                 function() {
123                                         obj.data.stash_retrieve();
124                                         obj.set_tab(obj.url_prefix(urls.XUL_COPY_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_copy_buckets.tab')},{});
125                                 }
126                         ],
127                         'cmd_edit_volume_buckets' : [
128                                 ['oncommand'],
129                                 function() {
130                                         obj.data.stash_retrieve();
131                                         obj.set_tab(obj.url_prefix(urls.XUL_VOLUME_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_volume_buckets.tab')},{});
132                                 }
133                         ],
134                         'cmd_edit_record_buckets' : [
135                                 ['oncommand'],
136                                 function() {
137                                         obj.data.stash_retrieve();
138                                         obj.set_tab(obj.url_prefix(urls.XUL_RECORD_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_record_buckets.tab')},{});
139                                 }
140                         ],
141                         'cmd_edit_user_buckets' : [
142                                 ['oncommand'],
143                                 function() {
144                                         obj.data.stash_retrieve();
145                                         obj.set_tab(obj.url_prefix(urls.XUL_USER_BUCKETS),{'tab_name':offlineStrings.getString('menu.cmd_edit_user_buckets.tab')},{});
146                                 }
147                         ],
148
149
150                         'cmd_replace_barcode' : [
151                                 ['oncommand'],
152                                 function() {
153                                         try {
154                                                 JSAN.use('util.network');
155                                                 var network = new util.network();
156
157                                                 var old_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.label'));
158                                                 if (!old_bc) return;
159         
160                                                 var copy;
161                         try {
162                             copy = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ old_bc ]);
163                                                 if (typeof copy.ilsevent != 'undefined') throw(copy); 
164                                                 if (!copy) throw(copy);
165                         } catch(E) {
166                             alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.retrieval.error', [old_bc]) + '\n');
167                             return;
168                         }
169         
170                                                 // Why did I want to do this twice?  Because this copy is more fleshed?
171                         try {
172                                                 copy = network.simple_request('FM_ACP_RETRIEVE',[ copy.id() ]);
173                                                 if (typeof copy.ilsevent != 'undefined') throw(copy);
174                                                 if (!copy) throw(copy);
175                         } catch(E) {
176                             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); }
177                             return;
178                         }
179         
180                                                 var new_bc = window.prompt(offlineStrings.getString('menu.cmd_replace_barcode.replacement.prompt'),'',offlineStrings.getString('menu.cmd_replace_barcode.replacement.label'));
181                                                 new_bc = String( new_bc ).replace(/\s/g,'');
182                                                 /* Casting a possibly null input value to a String turns it into "null" */
183                                                 if (!new_bc || new_bc == 'null') {
184                                                         alert(offlineStrings.getString('menu.cmd_replace_barcode.blank.error'));
185                                                         return;
186                                                 }
187         
188                                                 var test = network.simple_request('FM_ACP_RETRIEVE_VIA_BARCODE',[ new_bc ]);
189                                                 if (typeof test.ilsevent == 'undefined') {
190                                                 alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.duplicate.error', [new_bc]));
191                                                         return;
192                                                 } else {
193                                                         if (test.ilsevent != 1502 /* ASSET_COPY_NOT_FOUND */) {
194                                                         obj.error.standard_unexpected_error_alert(offlineStrings.getFormattedString('menu.cmd_replace_barcode.testing.error', [new_bc]),test);
195                                                                 return;
196                                                         }       
197                                                 }
198
199                                                 copy.barcode(new_bc); copy.ischanged('1');
200                                                 var r = network.simple_request('FM_ACP_FLESHED_BATCH_UPDATE', [ ses(), [ copy ] ]);
201                                                 if (typeof r.ilsevent != 'undefined') { 
202                             if (r.ilsevent != 0) {
203                                 if (r.ilsevent == 5000 /* PERM_FAILURE */) {
204                                     alert(offlineStrings.getString('menu.cmd_replace_barcode.permission.error'));
205                                 } else {
206                                     obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.error'),r);
207                                 }
208                             }
209                         }
210                                         } catch(E) {
211                                                 obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.cmd_replace_barcode.renaming.failure'),copy);
212                                         }
213                                 }
214                         ],
215
216                         /* Search Menu */
217                         'cmd_patron_search' : [
218                                 ['oncommand'],
219                                 function() {
220                     obj.set_patron_tab();
221                                 }
222                         ],
223                         'cmd_search_opac' : [
224                                 ['oncommand'],
225                                 function() {
226                                         obj.data.stash_retrieve();
227                                         var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
228                                         obj.set_tab(obj.url_prefix(urls.XUL_OPAC_WRAPPER), {'tab_name':offlineStrings.getString('menu.cmd_search_opac.tab')}, content_params);
229                                 }
230                         ],
231                         'cmd_search_tcn' : [
232                                 ['oncommand'],
233                                 function() {
234                                         var tcn = prompt(offlineStrings.getString('menu.cmd_search_tcn.tab'),'',offlineStrings.getString('menu.cmd_search_tcn.prompt'));
235
236                                         function spawn_tcn(r) {
237                                                 for (var i = 0; i < r.count; i++) {
238                                                         var id = r.ids[i];
239                                                         var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + id;
240                                                         obj.data.stash_retrieve();
241                                                         var content_params = { 
242                                                                 'session' : ses(), 
243                                                                 'authtime' : ses('authtime'),
244                                                                 'opac_url' : opac_url,
245                                                         };
246                                                         if (i == 0) {
247                                                                 obj.set_tab(
248                                                                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
249                                                                         {'tab_name':tcn}, 
250                                                                         content_params
251                                                                 );
252                                                         } else {
253                                                                 obj.new_tab(
254                                                                         obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
255                                                                         {'tab_name':tcn}, 
256                                                                         content_params
257                                                                 );
258                                                         }
259                                                 }
260                                         }
261
262                                         if (tcn) {
263                                                 JSAN.use('util.network');
264                                                 var network = new util.network();
265                                                 var robj = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn]);
266                                                 if (robj.count != robj.ids.length) throw('FIXME -- FM_BRE_ID_SEARCH_VIA_TCN = ' + js2JSON(robj));
267                                                 if (robj.count == 0) {
268                                                         var robj2 = network.simple_request('FM_BRE_ID_SEARCH_VIA_TCN',[tcn,1]);
269                                                         if (robj2.count == 0) {
270                                                                 alert(offlineStrings.getFormattedString('menu.cmd_search_tcn.not_found.error', [tcn]));
271                                                         } else {
272                                                                 if ( window.confirm(offlineStrings.getFormattedString('menu.cmd_search_tcn.deleted.error', [tcn])) ) {
273                                                                         spawn_tcn(robj2);
274                                                                 }
275                                                         }
276                                                 } else {
277                                                         spawn_tcn(robj);
278                                                 }
279                                         }
280                                 }
281                         ],
282                         'cmd_search_bib_id' : [
283                                 ['oncommand'],
284                                 function() {
285                                         var bib_id = prompt(offlineStrings.getString('menu.cmd_search_bib_id.tab'),'',offlineStrings.getString('menu.cmd_search_bib_id.prompt'));
286                     if (!bib_id) return;
287
288                                         var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + bib_id;
289                                         var content_params = { 
290                                                 'session' : ses(), 
291                                                 'authtime' : ses('authtime'),
292                                                 'opac_url' : opac_url,
293                                         };
294                                         obj.set_tab(
295                                                 obj.url_prefix(urls.XUL_OPAC_WRAPPER), 
296                                                 {'tab_name':'#' + bib_id}, 
297                                                 content_params
298                                         );
299                                 }
300                         ],
301                         'cmd_copy_status' : [
302                                 ['oncommand'],
303                                 function() {
304                                         obj.data.stash_retrieve();
305                                         obj.set_tab(obj.url_prefix(urls.XUL_COPY_STATUS),{},{});
306                                 }
307                         ],
308
309                         /* Circulation Menu */
310                         'cmd_patron_register' : [
311                                 ['oncommand'],
312                                 function() {
313                                                                 function spawn_editor(p) {
314                                                                         var url = urls.XUL_PATRON_EDIT;
315                                                                         var param_count = 0;
316                                                                         for (var i in p) {
317                                                                                 if (param_count++ == 0) url += '?'; else url += '&';
318                                                                                 url += i + '=' + window.escape(p[i]);
319                                                                         }
320                                                                         var loc = obj.url_prefix( urls.XUL_REMOTE_BROWSER ) + '?url=' + window.escape( url );
321                                                                         obj.new_tab(
322                                                                                 loc, 
323                                                                                 {}, 
324                                                                                 { 
325                                                                                         'show_print_button' : true , 
326                                                                                         'tab_name' : offline.getString('menu.cmd_patron_register.related.tab'),
327                                                                                         'passthru_content_params' : {
328                                                                                                 'spawn_search' : function(s) { obj.spawn_search(s); },
329                                                                                                 'spawn_editor' : spawn_editor,
330                                                                                         }
331                                                                                 }
332                                                                         );
333                                                                 }
334
335                                         obj.data.stash_retrieve();
336                                         var loc = obj.url_prefix( urls.XUL_REMOTE_BROWSER ) 
337                                                 + '?url=' + window.escape( urls.XUL_PATRON_EDIT + '?ses=' + window.escape( ses() ) );
338                                         obj.set_tab(
339                                                 loc, 
340                                                 {}, 
341                                                 { 
342                                                         'show_print_button' : true , 
343                                                         'tab_name' : offlineStrings.getString('menu.cmd_patron_register.tab'),
344                                                         'passthru_content_params' : {
345                                                                 'spawn_search' : function(s) { obj.spawn_search(s); },
346                                                                 'spawn_editor' : spawn_editor,
347                                                         }
348                                                 }
349                                         );
350                                 }
351                         ],
352                         'cmd_circ_checkin' : [
353                                 ['oncommand'],
354                                 function() { 
355                                         obj.data.stash_retrieve();
356                                         obj.set_tab(obj.url_prefix(urls.XUL_CHECKIN),{},{});
357                                 }
358                         ],
359                         'cmd_circ_checkout' : [
360                                 ['oncommand'],
361                                 function() { 
362                                         obj.data.stash_retrieve();
363                                         obj.set_tab(obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY),{},{});
364                                 }
365                         ],
366                         'cmd_circ_hold_capture' : [
367                                 ['oncommand'],
368                                 function() { 
369                                         obj.data.stash_retrieve();
370                                         obj.set_tab(obj.url_prefix(urls.XUL_CHECKIN)+'?hold_capture=1',{},{});
371                                 }
372                         ],
373                         'cmd_browse_holds' : [
374                                 ['oncommand'],
375                                 function() { 
376                                         obj.data.stash_retrieve();
377                                         obj.set_tab(obj.url_prefix(urls.XUL_HOLDS_BROWSER),{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds.tab') },{});
378                                 }
379                         ],
380                         'cmd_browse_holds_shelf' : [
381                                 ['oncommand'],
382                                 function() { 
383                                         obj.data.stash_retrieve();
384                                         obj.set_tab(obj.url_prefix(urls.XUL_HOLDS_BROWSER)+'?shelf=1',{ 'tab_name' : offlineStrings.getString('menu.cmd_browse_holds_shelf.tab') },{});
385                                 }
386                         ],
387                         'cmd_circ_hold_pull_list' : [
388                                 ['oncommand'],
389                                 function() { 
390                                         obj.data.stash_retrieve();
391                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(
392                                                 obj.url_prefix(urls.XUL_HOLD_PULL_LIST) + '?ses='+window.escape(ses())
393                                         );
394                                         obj.set_tab( loc, {'tab_name' : offlineStrings.getString('menu.cmd_browse_hold_pull_list.tab')}, { 'show_print_button' : true } );
395                                 }
396                         ],
397
398                         'cmd_in_house_use' : [
399                                 ['oncommand'],
400                                 function() { 
401                                         obj.data.stash_retrieve();
402                                         obj.set_tab(obj.url_prefix(urls.XUL_IN_HOUSE_USE),{},{});
403                                 }
404                         ],
405
406                         'cmd_standalone' : [
407                                 ['oncommand'],
408                                 function() { 
409                                         obj.set_tab(obj.url_prefix(urls.XUL_STANDALONE),{},{});
410                                 }
411                         ],
412
413                         'cmd_local_admin' : [
414                                 ['oncommand'],
415                                 function() { 
416                                         //obj.set_tab(obj.url_prefix(urls.XUL_LOCAL_ADMIN)+'?ses='+window.escape(ses())+'&session='+window.escape(ses()),{},{});
417                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(
418                                                 urls.XUL_LOCAL_ADMIN+'?ses='+window.escape(ses())+'&session='+window.escape(ses())
419                                         );
420                                         obj.set_tab( 
421                                                 loc, 
422                                                 {'tab_name' : offlineStrings.getString('menu.cmd_local_admin.tab'), 'browser' : false }, 
423                                                 { 'no_xulG' : false, 'show_nav_buttons' : true, 'show_print_button' : true } 
424                                         );
425
426                                 }
427                         ],
428
429             'cmd_toggle_buttonbar' : [
430                 ['oncommand'],
431                 function() {
432                     var x = document.getElementById('main_toolbar');
433                     if (x) x.hidden = ! x.hidden;
434                 }
435             ],
436
437                         'cmd_open_vandelay' : [
438                                 ['oncommand'],
439                                 function() { 
440                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + 
441                         window.escape(urls.VANDELAY+'?ses='+window.escape(ses()));
442                                         obj.set_tab( 
443                                                 loc, 
444                                                 {'tab_name' : offlineStrings.getString('menu.cmd_open_vandelay.tab'), 'browser' : false }, 
445                                                 {'no_xulG' : false, 'show_print_button' : false } 
446                                         );
447
448                                 }
449                         ],
450
451             'cmd_local_admin_fonts_and_sounds' : [
452                 ['oncommand'],
453                 function() { 
454                     alert(123);
455                 }
456             ],
457             'cmd_local_admin_printer' : [
458                 ['oncommand'],
459                 function() { 
460                     alert(123);
461                 }
462             ],
463             'cmd_local_admin_closed_dates' : [
464                 ['oncommand'],
465                 function() { 
466                     alert(123);
467                 }
468             ],
469             'cmd_local_admin_copy_locations' : [
470                 ['oncommand'],
471                 function() { 
472                     alert(123);
473                 }
474             ],
475             'cmd_local_admin_lib_settings' : [
476                 ['oncommand'],
477                 function() { 
478                     alert(123);
479                 }
480             ],
481             'cmd_local_admin_non_cat_types' : [
482                 ['oncommand'],
483                 function() { 
484                     alert(123);
485                 }
486             ],
487             'cmd_local_admin_stat_cats' : [
488                 ['oncommand'],
489                 function() { 
490                     alert(123);
491                 }
492             ],
493             'cmd_local_admin_standing_penalty' : [
494                 ['oncommand'],
495                 function() { open_conify_page('config/standing_penalty'); }
496             ],
497             'cmd_local_admin_grp_penalty_threshold' : [
498                 ['oncommand'],
499                 function() { open_conify_page('permission/grp_penalty_threshold'); }
500             ],
501             'cmd_local_admin_idl_field_doc' : [
502                 ['oncommand'],
503                 function() { open_conify_page('config/idl_field_doc'); }
504             ],
505             'cmd_local_admin_action_trigger' : [
506                 ['oncommand'],
507                 function() { open_conify_page('action_trigger/event_definition'); }
508             ],
509             'cmd_local_admin_survey' : [
510                 ['oncommand'],
511                 function() { open_conify_page('action/survey'); }
512             ],
513             'cmd_server_admin_org_type' : [
514                 ['oncommand'],
515                 function() { open_conify_page('actor/org_unit_type', null, true); }
516             ],
517             'cmd_server_admin_org_unit' : [
518                 ['oncommand'],
519                 function() { open_conify_page('actor/org_unit', null, true); }
520             ],
521             'cmd_server_admin_grp_tree' : [
522                 ['oncommand'],
523                 function() { open_conify_page('permission/grp_tree', null, true); }
524             ],
525             'cmd_server_admin_perm_list' : [
526                 ['oncommand'],
527                 function() { open_conify_page('permission/perm_list', null, true); }
528             ],
529             'cmd_server_admin_copy_status' : [
530                 ['oncommand'],
531                 function() { open_conify_page('config/copy_status', null, true); }
532             ],
533             'cmd_server_admin_marc_code' : [
534                 ['oncommand'],
535                 function() { open_conify_page('config/marc_code_maps', null, true); }
536             ],
537             'cmd_server_admin_billing_type' : [
538                 ['oncommand'],
539                 function() { open_conify_page('config/billing_type'); }
540             ],
541             'cmd_server_admin_z39_source' : [
542                 ['oncommand'],
543                 function() { open_conify_page('config/z3950_source'); }
544             ],
545             'cmd_server_admin_circ_mod' : [
546                 ['oncommand'],
547                 function() { open_conify_page('config/circ_modifier'); }
548             ],
549
550
551                         'cmd_open_conify' : [
552                                 ['oncommand'],
553                                 function() { 
554                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + 
555                         window.escape(urls.CONIFY+'/admin.html?ses='+window.escape(ses()));
556                                         obj.set_tab( 
557                                                 loc, 
558                                                 {'tab_name' : offlineStrings.getString('menu.cmd_open_conify.tab'), 'browser' : false }, 
559                                                 {'no_xulG' : false, 'show_print_button' : false } 
560                                         );
561
562                                 }
563                         ],
564
565                         'cmd_reprint' : [
566                                 ['oncommand'],
567                                 function() {
568                                         try {
569                                                 JSAN.use('util.print'); var print = new util.print();
570                                                 print.reprint_last();
571                                         } catch(E) {
572                                                 alert(E);
573                                         }
574                                 }
575                         ],
576
577                         'cmd_retrieve_last_patron' : [
578                                 ['oncommand'],
579                                 function() {
580                                         obj.data.stash_retrieve();
581                                         if (!obj.data.last_patron) {
582                                                 alert(offlineStrings.getString('menu.cmd_retrieve_last_patron.session.error'));
583                                                 return;
584                                         }
585                                         var url = obj.url_prefix( urls.XUL_PATRON_DISPLAY ); // + '?id=' + window.escape( obj.data.last_patron ) );
586                                         obj.set_tab( url, {}, { 'id' : obj.data.last_patron } );
587                                 }
588                         ],
589                         
590                         'cmd_retrieve_last_record' : [
591                                 ['oncommand'],
592                                 function() {
593                                         obj.data.stash_retrieve();
594                                         if (!obj.data.last_record) {
595                                                 alert(offlineStrings.getString('menu.cmd_retrieve_last_record.session.error'));
596                                                 return;
597                                         }
598                                         var opac_url = obj.url_prefix( urls.opac_rdetail ) + '?r=' + obj.data.last_record;
599                                         var content_params = {
600                                                 'session' : ses(),
601                                                 'authtime' : ses('authtime'),
602                                                 'opac_url' : opac_url,
603                                         };
604                                         obj.set_tab(
605                                                 obj.url_prefix(urls.XUL_OPAC_WRAPPER),
606                                                 {'tab_name' : offlineStrings.getString('menu.cmd_retrieve_last_record.status')},
607                                                 content_params
608                                         );
609                                 }
610                         ],
611
612             'cmd_verify_credentials' : [
613                 ['oncommand'],
614                 function() {
615                                         obj.set_tab(
616                                                 obj.url_prefix(urls.XUL_VERIFY_CREDENTIALS),
617                                                 { 'tab_name' : offlineStrings.getString('menu.cmd_verify_credentials.tabname') },
618                                                 {}
619                                         );
620                 }
621             ],
622
623                         /* Cataloging Menu */
624                         'cmd_z39_50_import' : [
625                                 ['oncommand'],
626                                 function() {
627                                         obj.data.stash_retrieve();
628                                         obj.set_tab(obj.url_prefix(urls.XUL_Z3950_IMPORT),{},{});
629                                 }
630                         ],
631                         'cmd_create_marc' : [
632                                 ['oncommand'],
633                                 function() {
634                                         obj.data.stash_retrieve();
635                                         obj.set_tab(obj.url_prefix(urls.XUL_MARC_NEW),{},{});
636                                 }
637                         ],
638
639                         /* Admin menu */
640                         'cmd_change_session' : [
641                                 ['oncommand'],
642                                 function() {
643                                         try {
644                                                 obj.data.stash_retrieve();
645                                                 JSAN.use('util.network'); var network = new util.network();
646                                                 var x = document.getElementById('oc_menuitem');
647                                                 var x_label = x.getAttribute('label_orig');
648                                                 var temp_au = js2JSON( obj.data.list.au[0] );
649                                                 var temp_ses = js2JSON( obj.data.session );
650                                                 if (obj.data.list.au.length > 1) {
651                                                         obj.data.list.au = [ obj.data.list.au[1] ];
652                                                         obj.data.stash('list');
653                                                         network.reset_titlebars( obj.data );
654                                                         x.setAttribute('label', x_label );
655                                                         network.simple_request('AUTH_DELETE', [ obj.data.session.key ] );
656                                                         obj.data.session = obj.data.previous_session;
657                                                         obj.data.stash('session');
658                                             try {
659                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
660                                                                 var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
661                                                                 var cookieUri = ios.newURI("http://" + obj.data.server_unadorned, null, null);
662                                                                 var cookieUriSSL = ios.newURI("https://" + obj.data.server_unadorned, null, null);
663                                                                 var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);
664
665                                                                 cookieSvc.setCookieString(cookieUri, null, "ses="+obj.data.session.key, null);
666                                                                 cookieSvc.setCookieString(cookieUriSSL, null, "ses="+obj.data.session.key, null);
667
668                                             } catch(E) {
669                                                     alert(offlineStrings.getFormattedString(main.session_cookie.error, [E]));
670                                             }
671
672                                                         removeCSSClass(document.getElementById('main_tabbox'),'operator_change');
673                                                 } else {
674                                                         if (network.get_new_session(offlineStrings.getString('menu.cmd_chg_session.label'),{'url_prefix':obj.url_prefix})) {
675                                                                 obj.data.stash_retrieve();
676                                                                 obj.data.list.au[1] = JSON2js( temp_au );
677                                                                 obj.data.stash('list');
678                                                                 obj.data.previous_session = JSON2js( temp_ses );
679                                                                 obj.data.stash('previous_session');
680                                                                 x.setAttribute('label', offlineStrings.getFormattedString('menu.cmd_chg_session.operator.label', [obj.data.list.au[1].usrname()]) );
681                                                                 addCSSClass(document.getElementById('main_tabbox'),'operator_change');
682                                                         }
683                                                 }
684                                         } catch(E) {
685                                                 obj.error.standard_unexpected_error_alert('cmd_change_session',E);
686                                         }
687                                 }
688                         ],
689                         'cmd_manage_offline_xacts' : [
690                                 ['oncommand'],
691                                 function() {
692                                         obj.set_tab(obj.url_prefix(urls.XUL_OFFLINE_MANAGE_XACTS), {'tab_name' : offlineStrings.getString('menu.cmd_manage_offline_xacts.tab')}, {});
693                                 }
694                         ],
695                         'cmd_download_patrons' : [
696                                 ['oncommand'],
697                                 function() {
698                                         try {
699                                                 netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
700                                                 var x = new XMLHttpRequest();
701                                                 var url = 'http://' + XML_HTTP_SERVER + '/standalone/list.txt';
702                                                 x.open("GET",url,false);
703                                                 x.send(null);
704                                                 if (x.status == 200) {
705                                                         JSAN.use('util.file'); var file = new util.file('offline_patron_list');
706                                                         file.write_content('truncate',x.responseText);
707                                                         file.close();
708                                                         file = new util.file('offline_patron_list.date');
709                                                         file.write_content('truncate',new Date());
710                                                         file.close();
711                                                         alert(offlineStrings.getString('menu.cmd_download_patrons.complete.status'));
712                                                 } else {
713                                                         alert(offlineStrings.getFormattedString('menu.cmd_download_patrons.error', [x.status, x.statusText]));
714                                                 }
715                                         } catch(E) {
716                                                 obj.error.standard_unexpected_error_alert('cmd_download_patrons',E);
717                                         }
718                                 }
719                         ],
720                         'cmd_adv_user_edit' : [
721                                 ['oncommand'],
722                                 function() {
723                                         obj.data.stash_retrieve();
724                                         obj.set_tab(obj.url_prefix(urls.XUL_PATRON_BARCODE_ENTRY), {}, { 'perm_editor' : true });
725                                 }
726                         ],
727                         'cmd_print_list_template_edit' : [
728                                 ['oncommand'],
729                                 function() {
730                                         obj.data.stash_retrieve();
731                                         obj.set_tab(obj.url_prefix(urls.XUL_PRINT_LIST_TEMPLATE_EDITOR), {}, {});
732                                 }
733                         ],
734                         'cmd_stat_cat_edit' : [
735                                 ['oncommand'],
736                                 function() {
737                                         obj.data.stash_retrieve();
738                                         obj.set_tab(obj.url_prefix(urls.XUL_STAT_CAT_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_stat_cat_edit.tab')},{});
739                                 }
740                         ],
741                         'cmd_non_cat_type_edit' : [
742                                 ['oncommand'],
743                                 function() {
744                                         obj.data.stash_retrieve();
745                                         obj.set_tab(obj.url_prefix(urls.XUL_NON_CAT_LABEL_EDIT) + '?ses='+window.escape(ses()), {'tab_name' : offlineStrings.getString('menu.cmd_non_cat_type_edit.tab')},{});
746                                 }
747                         ],
748                         'cmd_copy_location_edit' : [
749                                 ['oncommand'],
750                                 function() {
751                                         obj.data.stash_retrieve();
752                                         obj.set_tab(obj.url_prefix(urls.XUL_COPY_LOCATION_EDIT) + '?ses='+window.escape(ses()),{'tab_name' : offlineStrings.getString('menu.cmd_copy_location_edit.tab')},{});
753                                 }
754                         ],
755                         'cmd_test' : [
756                                 ['oncommand'],
757                                 function() {
758                                         obj.data.stash_retrieve();
759                                         var content_params = { 'session' : ses(), 'authtime' : ses('authtime') };
760                                         obj.set_tab(obj.url_prefix(urls.XUL_OPAC_WRAPPER), {}, content_params);
761                                 }
762                         ],
763                         'cmd_test_html' : [
764                                 ['oncommand'],
765                                 function() {
766                                         obj.data.stash_retrieve();
767                                         obj.set_tab(obj.url_prefix(urls.TEST_HTML) + '?ses='+window.escape(ses()),{ 'browser' : true },{});
768                                 }
769                         ],
770                         'cmd_test_xul' : [
771                                 ['oncommand'],
772                                 function() {
773                                         obj.data.stash_retrieve();
774                                         obj.set_tab(obj.url_prefix(urls.TEST_XUL) + '?ses='+window.escape(ses()),{ 'browser' : false },{});
775                                 }
776                         ],
777                         'cmd_console' : [
778                                 ['oncommand'],
779                                 function() {
780                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_CONSOLE),{'tab_name' : offlineStrings.getString('menu.cmd_console.tab')},{});
781                                 }
782                         ],
783                         'cmd_shell' : [
784                                 ['oncommand'],
785                                 function() {
786                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_SHELL),{'tab_name' : offlineStrings.getString('menu.cmd_shell.tab')},{});
787                                 }
788                         ],
789                         'cmd_xuleditor' : [
790                                 ['oncommand'],
791                                 function() {
792                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_XULEDITOR),{'tab_name' : offlineStrings.getString('menu.cmd_xuleditor.tab')},{});
793                                 }
794                         ],
795                         'cmd_fieldmapper' : [
796                                 ['oncommand'],
797                                 function() {
798                                         obj.set_tab(obj.url_prefix(urls.XUL_DEBUG_FIELDMAPPER),{'tab_name' : offlineStrings.getString('menu.cmd_fieldmapper.tab')},{});
799                                 }
800                         ],
801                         'cmd_survey_wizard' : [
802                                 ['oncommand'],
803                                 function() {
804                                         obj.data.stash_retrieve();
805                                         xulG.window.open(obj.url_prefix(urls.XUL_SURVEY_WIZARD),'survey_wizard','chrome'); 
806                                 }
807                         ],
808                         'cmd_public_opac' : [
809                                 ['oncommand'],
810                                 function() {
811                                         var loc = urls.XUL_REMOTE_BROWSER + '?url=' + window.escape(
812                                                 urls.remote
813                                         );
814                                         obj.set_tab( 
815                                                 loc, 
816                                                 {'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
817                                                 { 'no_xulG' : true, 'show_nav_buttons' : true, 'show_print_button' : true } 
818                                         );
819                                 }
820                         ],
821                         'cmd_clear_cache' : [
822                                 ['oncommand'],
823                                 function clear_the_cache() {
824                                         try {
825                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
826                                                 var cacheClass          = Components.classes["@mozilla.org/network/cache-service;1"];
827                                                 var cacheService        = cacheClass.getService(Components.interfaces.nsICacheService);
828                                                 cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
829                                                 cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
830                                         } catch(E) {
831                                                 dump(E+'\n');alert(E);
832                                         }
833                                 }
834                         ],
835                         'cmd_restore_all_tabs' : [
836                                 ['oncommand'],
837                                 function() {
838                                         var tabs = obj.controller.view.tabs;
839                                         for (var i = 0; i < tabs.childNodes.length; i++) {
840                                                 tabs.childNodes[i].hidden = false;
841                                         }
842                                 }
843                         ],
844                         'cmd_extension_manager' : [
845                                 ['oncommand'],
846                                 function() {
847                                         obj.set_tab('chrome://mozapps/content/extensions/extensions.xul?type=extensions',{'tab_name' : offlineStrings.getString('menu.cmd_extension_manager.tab')},{});
848                                 }
849                         ],
850                         'cmd_theme_manager' : [
851                                 ['oncommand'],
852                                 function() {
853                                         obj.set_tab('chrome://mozapps/content/extensions/extensions.xul?type=themes',{'tab_name' : offlineStrings.getString('menu.cmd_theme_manager.tab')},{});
854                                 }
855                         ],
856                         'cmd_about_config' : [
857                                 ['oncommand'],
858                                 function() {
859                                         obj.set_tab('chrome://global/content/config.xul',{'tab_name' : 'about:config'},{});
860                                 }
861                         ],
862                         'cmd_shutdown' : [
863                                 ['oncommand'],
864                                 function() {
865                                         if (window.confirm(offlineStrings.getString('menu.cmd_shutdown.prompt'))) {
866                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
867                                                 var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
868                                                 var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator);
869                                                 var enumerator = windowManagerInterface.getEnumerator(null);
870                                                 var w; // close all other windows
871                                                 while ( w = enumerator.getNext() ) {
872                                                         if (w != window) w.close();
873                                                 }
874                                                 window.close();
875                                         }
876                                 }
877                         ],
878
879                         'cmd_acq_view_picklist' : [
880                                 ['oncommand'],
881                                 function() {
882                                         obj.set_tab( 
883                                                 obj.url_prefix(urls.XUL_ACQ_PICKLIST),
884                                                 //{'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
885                                                 {'tab_name' : 'Selection Lists', 'browser' : false}, 
886                                                 {'show_nav_buttons' : true, 'show_print_button' : true} 
887                                         );
888                                 }
889                         ],
890                         'cmd_acq_view_po' : [
891                                 ['oncommand'],
892                                 function() {
893                                         obj.set_tab( 
894                                                 obj.url_prefix(urls.XUL_ACQ_PO),
895                                                 //{'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
896                                                 {'tab_name' : 'Purchase Orders', 'browser' : false}, 
897                                                 {'show_nav_buttons' : true, 'show_print_button' : true} 
898                                         );
899                                 }
900                         ],
901                         'cmd_acq_upload' : [
902                                 ['oncommand'],
903                                 function() {
904                                         obj.set_tab( 
905                                                 obj.url_prefix(urls.XUL_ACQ_UPLOAD),
906                                                 //{'tab_name' : offlineStrings.getString('menu.cmd_public_opac.tab'), 'browser' : false}, 
907                                                 {'tab_name' : 'Load Order Record', 'browser' : false}, 
908                                                 {'show_nav_buttons' : true, 'show_print_button' : true} 
909                                         );
910                                 }
911                         ],
912
913                 };
914
915                 JSAN.use('util.controller');
916                 var cmd;
917                 obj.controller = new util.controller();
918                 obj.controller.init( { 'window_knows_me_by' : 'g.menu.controller', 'control_map' : cmd_map } );
919
920                 obj.controller.view.tabbox = window.document.getElementById('main_tabbox');
921                 obj.controller.view.tabs = obj.controller.view.tabbox.firstChild;
922                 obj.controller.view.panels = obj.controller.view.tabbox.lastChild;
923
924                 obj.new_tab(null,{'focus':true},null);
925
926                 obj.init_tab_focus_handlers();
927         },
928
929         'spawn_search' : function(s) {
930                 var obj = this;
931                 obj.error.sdump('D_TRACE', offlineStrings.getFormattedString('menu.spawn_search.msg', [js2JSON(s)]) ); 
932                 obj.data.stash_retrieve();
933                 var loc = obj.url_prefix(urls.XUL_PATRON_DISPLAY);
934                 loc += '?doit=1&query=' + window.escape(js2JSON(s));
935                 obj.new_tab( loc, {}, {} );
936         },
937
938         'init_tab_focus_handlers' : function() {
939                 var obj = this;
940                 for (var i = 0; i < obj.controller.view.tabs.childNodes.length; i++) {
941                         var tab = obj.controller.view.tabs.childNodes[i];
942                         var panel = obj.controller.view.panels.childNodes[i];
943                         tab.addEventListener(
944                                 'command',
945                                 function(p) {
946                                         return function() {
947                                                 try {
948                                                                 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
949                                                                 if (p
950                                                                         && p.firstChild 
951                                                                         && ( p.firstChild.nodeName == 'iframe' || p.firstChild.nodeName == 'browser' )
952                                                                         && p.firstChild.contentWindow 
953                                                                 ) {
954                                                                         if (typeof p.firstChild.contentWindow.default_focus == 'function') {
955                                                                                 p.firstChild.contentWindow.default_focus();
956                                                                         } else {
957                                                                                 //p.firstChild.contentWindow.firstChild.focus();
958                                                                         }
959                                                                 }
960                                                 } catch(E) {
961                                                         obj.error.sdump('D_ERROR','init_tab_focus_handler: ' + js2JSON(E));
962                                                 }
963                                         }
964                                 }(panel),
965                                 false
966                         );
967                 }
968         },
969
970         'close_all_tabs' : function() {
971                 var obj = this;
972                 try {
973                         var count = obj.controller.view.tabs.childNodes.length;
974                         for (var i = 0; i < count; i++) obj.close_tab();
975                         setTimeout( function(){ obj.controller.view.tabs.firstChild.focus(); }, 0);
976                 } catch(E) {
977                         obj.error.standard_unexpected_error_alert(offlineStrings.getString('menu.close_all_tabs.error'),E);
978                 }
979         },
980
981         'close_tab' : function () {
982                 var idx = this.controller.view.tabs.selectedIndex;
983                 var tab = this.controller.view.tabs.childNodes[idx];
984                 var panel = this.controller.view.panels.childNodes[ idx ];
985                 while ( panel.lastChild ) panel.removeChild( panel.lastChild );
986                 if (idx == 0) {
987                         try {
988                                 this.controller.view.tabs.advanceSelectedTab(+1);
989                         } catch(E) {
990                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(+1):'+js2JSON(E) + '\n');
991                                 try {
992                                         this.controller.view.tabs.advanceSelectedTab(-1);
993                                 } catch(E) {
994                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(-1):'+
995                                                 js2JSON(E) + '\n');
996                                 }
997                         }
998                 } else {
999                         try {
1000                                 this.controller.view.tabs.advanceSelectedTab(-1);
1001                         } catch(E) {
1002                                 this.error.sdump('D_TAB','failed tabs.advanceSelectedTab(-1):'+js2JSON(E) + '\n');
1003                                 try {
1004                                         this.controller.view.tabs.advanceSelectedTab(+1);
1005                                 } catch(E) {
1006                                         this.error.sdump('D_TAB','failed again tabs.advanceSelectedTab(+1):'+
1007                                                 js2JSON(E) + '\n');
1008                                 }
1009                         }
1010
1011                 }
1012                 
1013                 this.error.sdump('D_TAB','\tnew tabbox.selectedIndex = ' + this.controller.view.tabbox.selectedIndex + '\n');
1014
1015                 this.controller.view.tabs.childNodes[ idx ].hidden = true;
1016                 this.error.sdump('D_TAB','tabs.childNodes[ ' + idx + ' ].hidden = true;\n');
1017
1018                 // Make sure we keep at least one tab open.
1019                 var tab_flag = true;
1020                 for (var i = 0; i < this.controller.view.tabs.childNodes.length; i++) {
1021                         var tab = this.controller.view.tabs.childNodes[i];
1022                         if (!tab.hidden)
1023                                 tab_flag = false;
1024                 }
1025                 if (tab_flag) {
1026                         this.controller.view.tabs.selectedIndex = 0;
1027                         this.new_tab(); 
1028                 }
1029         },
1030
1031         'find_free_tab' : function() {
1032                 var last_not_hidden = -1;
1033                 for (var i = 0; i<this.controller.view.tabs.childNodes.length; i++) {
1034                         var tab = this.controller.view.tabs.childNodes[i];
1035                         if (!tab.hidden)
1036                                 last_not_hidden = i;
1037                 }
1038                 if (last_not_hidden == this.controller.view.tabs.childNodes.length - 1)
1039                         last_not_hidden = -1;
1040                 // If the one next to last_not_hidden is hidden, we want it.
1041                 // Basically, we fill in tabs after existing tabs for as 
1042                 // long as possible.
1043                 var idx = last_not_hidden + 1;
1044                 var candidate = this.controller.view.tabs.childNodes[ idx ];
1045                 if (candidate.hidden)
1046                         return idx;
1047                 // Alright, find the first hidden then
1048                 for (var i = 0; i<this.controller.view.tabs.childNodes.length; i++) {
1049                         var tab = this.controller.view.tabs.childNodes[i];
1050                         if (tab.hidden)
1051                                 return i;
1052                 }
1053                 return -1;
1054         },
1055
1056         'new_tab' : function(url,params,content_params) {
1057                 var tc = this.find_free_tab();
1058                 if (tc == -1) { return null; } // 9 tabs max
1059                 var tab = this.controller.view.tabs.childNodes[ tc ];
1060                 tab.hidden = false;
1061                 if (!content_params) content_params = {};
1062                 if (!params) params = {};
1063                 if (!params.tab_name) params.tab_name = offlineStrings.getString('menu.new_tab.tab');
1064                 if (!params.nofocus) params.focus = true; /* make focus the default */
1065                 try {
1066                         if (params.focus) this.controller.view.tabs.selectedIndex = tc;
1067                         params.index = tc;
1068                         this.set_tab(url,params,content_params);
1069                 } catch(E) {
1070                         this.error.sdump('D_ERROR',E);
1071                 }
1072         },
1073
1074     'network_meter' : {
1075         'inc' : function(app,method) {
1076             try {
1077                 var m = document.getElementById('network_progress');
1078                 var count = 1 + Number( m.getAttribute('count') );
1079                 m.setAttribute('mode','undetermined');
1080                 m.setAttribute('count', count);
1081                 var rows = document.getElementById('network_progress_rows');
1082                 var row = document.getElementById('network_progress_tip_'+app+'_'+method);
1083                 if (!row) {
1084                     row = document.createElement('row'); row.setAttribute('id','network_progress_tip_'+app+'_'+method);
1085                     var a = document.createElement('label'); a.setAttribute('value','App:');
1086                     var b = document.createElement('label'); b.setAttribute('value',app);
1087                     var c = document.createElement('label'); c.setAttribute('value','Method:');
1088                     var d = document.createElement('label'); d.setAttribute('value',method);
1089                     var e = document.createElement('label'); e.setAttribute('value','Total:');
1090                     var f = document.createElement('label'); f.setAttribute('value','0'); 
1091                     f.setAttribute('id','network_progress_tip_total_'+app+'_'+method);
1092                     var g = document.createElement('label'); g.setAttribute('value','Outstanding:');
1093                     var h = document.createElement('label'); h.setAttribute('value','0');
1094                     h.setAttribute('id','network_progress_tip_out_'+app+'_'+method);
1095                     row.appendChild(a); row.appendChild(b); row.appendChild(c);
1096                     row.appendChild(d); row.appendChild(e); row.appendChild(f);
1097                     row.appendChild(g); row.appendChild(h); rows.appendChild(row);
1098                 }
1099                 var total = document.getElementById('network_progress_tip_total_'+app+'_'+method);
1100                 if (total) {
1101                     total.setAttribute('value', 1 + Number( total.getAttribute('value') ));
1102                 }
1103                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1104                 if (out) {
1105                     out.setAttribute('value', 1 + Number( out.getAttribute('value') ));
1106                 }
1107             } catch(E) {
1108                 dump('network_meter.inc(): ' + E + '\n');
1109             }
1110         },
1111         'dec' : function(app,method) {
1112             try {
1113                 var m = document.getElementById('network_progress');
1114                 var count = -1 + Number( m.getAttribute('count') );
1115                 if (count < 0) count = 0;
1116                 if (count == 0) m.setAttribute('mode','determined');
1117                 m.setAttribute('count', count);
1118                 var out = document.getElementById('network_progress_tip_out_'+app+'_'+method);
1119                 if (out) {
1120                     out.setAttribute('value', -1 + Number( out.getAttribute('value') ));
1121                 }
1122             } catch(E) {
1123                 dump('network_meter.dec(): ' + E + '\n');
1124             }
1125         }
1126     },
1127     'set_patron_tab' : function(params,content_params) {
1128         var obj = this;
1129         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1130         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1131         obj.set_tab(url,params ? params : {},content_params ? content_params : {});
1132     },
1133     'new_patron_tab' : function(params,content_params) {
1134         var obj = this;
1135         var horizontal_interface = String( obj.data.hash.aous['ui.circ.patron_summary.horizontal'] ) == 'true';
1136         var url = obj.url_prefix( horizontal_interface ? urls.XUL_PATRON_HORIZ_DISPLAY : urls.XUL_PATRON_DISPLAY );
1137         obj.new_tab(url,params ? params : {},content_params ? content_params : {});
1138     },
1139         'set_tab' : function(url,params,content_params) {
1140                 var obj = this;
1141                 if (!url) url = '/xul/server/';
1142                 if (!url.match(/:\/\//) && !url.match(/^data:/)) url = urls.remote + url;
1143                 if (!params) params = {};
1144                 if (!content_params) content_params = {};
1145                 var idx = this.controller.view.tabs.selectedIndex;
1146                 if (params && typeof params.index != 'undefined') idx = params.index;
1147                 var tab = this.controller.view.tabs.childNodes[ idx ];
1148                 if (params.focus) tab.focus();
1149                 var panel = this.controller.view.panels.childNodes[ idx ];
1150                 while ( panel.lastChild ) panel.removeChild( panel.lastChild );
1151
1152                 content_params.new_tab = function(a,b,c) { return obj.new_tab(a,b,c); };
1153                 content_params.set_tab = function(a,b,c) { return obj.set_tab(a,b,c); };
1154                 content_params.new_patron_tab = function(a,b) { return obj.new_patron_tab(a,b); };
1155                 content_params.set_patron_tab = function(a,b) { return obj.set_patron_tab(a,b); };
1156                 content_params.set_tab_name = function(name) { tab.setAttribute('label',(idx + 1) + ' ' + name); };
1157                 content_params.open_chrome_window = function(a,b,c) { return xulG.window.open(a,b,c); };
1158                 content_params.url_prefix = function(url) { return obj.url_prefix(url); };
1159         content_params.network_meter = obj.network_meter;
1160         content_params.chrome_xulG = xulG;
1161                 if (params && params.tab_name) content_params.set_tab_name( params.tab_name );
1162                 
1163                 var frame;
1164                 try {
1165             if (typeof params.browser == 'undefined') params.browser = false;
1166                         if (params.browser) {
1167                                 obj.id_incr++;
1168                                 frame = this.w.document.createElement('browser');
1169                                 frame.setAttribute('flex','1');
1170                                 frame.setAttribute('type','content');
1171                                 frame.setAttribute('id','frame_'+obj.id_incr);
1172                                 panel.appendChild(frame);
1173                                 try {
1174                                         dump('creating browser with src = ' + url + '\n');
1175                                         JSAN.use('util.browser');
1176                                         var b = new util.browser();
1177                                         b.init(
1178                                                 {
1179                                                         'url' : url,
1180                                                         'push_xulG' : true,
1181                                                         'alt_print' : false,
1182                                                         'browser_id' : 'frame_'+obj.id_incr,
1183                                                         'passthru_content_params' : content_params,
1184                                                 }
1185                                         );
1186                                 } catch(E) {
1187                                         alert(E);
1188                                 }
1189                         } else {
1190                                 frame = this.w.document.createElement('iframe');
1191                                 frame.setAttribute('flex','1');
1192                                 panel.appendChild(frame);
1193                                 dump('creating iframe with src = ' + url + '\n');
1194                                 frame.setAttribute('src',url);
1195                                 try {
1196                                         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
1197                                         var cw = frame.contentWindow;
1198                                         if (typeof cw.wrappedJSObject != 'undefined') cw = cw.wrappedJSObject;
1199                                         cw.IAMXUL = true;
1200                                         cw.xulG = content_params;
1201                                 } catch(E) {
1202                                         this.error.sdump('D_ERROR', 'main.menu: ' + E);
1203                                 }
1204                         }
1205                 } catch(E) {
1206                         this.error.sdump('D_ERROR', 'main.menu:2: ' + E);
1207                         alert(offlineStrings.getString('menu.set_tab.error'));
1208                 }
1209
1210                 return frame;
1211         }
1212
1213 }
1214
1215 dump('exiting main/menu.js\n');