]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xul/staff_client/server/cat/z3950.js
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[working/Evergreen.git] / Open-ILS / xul / staff_client / server / cat / z3950.js
1 dump('entering cat.z3950.js\n');
2
3 function $(id) { return document.getElementById(id); }
4
5 if (typeof cat == 'undefined') cat = {};
6 cat.z3950 = function (params) {
7     try {
8         netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
9         JSAN.use('util.error'); this.error = new util.error();
10         JSAN.use('util.network'); this.network = new util.network();
11     } catch(E) {
12         dump('cat.z3950: ' + E + '\n');
13     }
14 }
15
16 cat.z3950.prototype = {
17
18     'creds_version' : 2,
19
20     'number_of_result_sets' : 0,
21
22     'result_set' : [],
23
24     'limit' : 10,
25
26     'init' : function( params ) {
27
28         try {
29             netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
30             JSAN.use('util.widgets');
31
32             var obj = this;
33
34             JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
35
36             obj.load_creds();
37
38             JSAN.use('circ.util');
39             var columns = circ.util.columns(
40                 {
41                     'tcn' : { 'hidden' : false },
42                     'isbn' : { 'hidden' : false },
43                     'title' : { 'hidden' : false, 'flex' : '1' },
44                     'author' : { 'hidden' : false },
45                     'edition' : { 'hidden' : false },
46                     'pubdate' : { 'hidden' : false },
47                     'publisher' : { 'hidden' : false },
48                     'service' : { 'hidden' : false }
49                 }
50             );
51
52             JSAN.use('util.list'); obj.list = new util.list('results');
53             obj.list.init(
54                 {
55                     'columns' : columns,
56                     'on_select' : function(ev) {
57                         try {
58                             JSAN.use('util.functional');
59                             var sel = obj.list.retrieve_selection();
60                             document.getElementById('sel_clip').setAttribute('disabled', sel.length < 1);
61                             var list = util.functional.map_list(
62                                 sel,
63                                 function(o) {
64                                     if ( $('jacket_image') ) {
65                                         // A side-effect in this map function, mu hahaha
66                                         if (o.getAttribute('isbn')) {
67                                             $('jacket_image').setAttribute('src',urls.ac_jacket_large+o.getAttribute('isbn'));
68                                             $('jacket_image').setAttribute('tooltiptext',urls.ac_jacket_large+o.getAttribute('isbn'));
69                                         } else {
70                                             $('jacket_image').setAttribute('src','');
71                                             $('jacket_image').setAttribute('tooltiptext','');
72                                         }
73                                     }
74                                     if (o.getAttribute('service') == 'native-evergreen-catalog') {
75                                         $('mark_overlay_btn').disabled = false;
76                                         $('show_in_catalog_btn').disabled = false;
77                                         obj.controller.view.mark_overlay.setAttribute('doc_id',o.getAttribute('doc_id'));
78                                     } else {
79                                         $('mark_overlay_btn').disabled = true;
80                                         $('show_in_catalog_btn').disabled = true;
81                                     }
82                                     return o.getAttribute('retrieve_id');
83                                 }
84                             );
85                             obj.error.sdump('D_TRACE','cat/z3950: selection list = ' + js2JSON(list) );
86                             obj.controller.view.marc_import.disabled = false;
87                             obj.controller.view.marc_import.setAttribute('retrieve_id',list[0]);
88                             obj.data.init({'via':'stash'});
89                             if (obj.data.marked_record) {
90                                 obj.controller.view.marc_import_overlay.disabled = false;
91                             } else {
92                                 obj.controller.view.marc_import_overlay.disabled = true;
93                             }
94                             obj.controller.view.marc_import_overlay.setAttribute('retrieve_id',list[0]);
95                             obj.controller.view.marc_view_btn.disabled = false;
96                             obj.controller.view.marc_view_btn.setAttribute('retrieve_id',list[0]);
97                         } catch(E) {
98                             obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_list_init.list_construction_error'),E);
99                         }
100                     },
101                 }
102             );
103
104             JSAN.use('util.controller'); obj.controller = new util.controller();
105             obj.controller.init(
106                 {
107                     control_map : {
108                         'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
109                         'sel_clip' : [ ['command'], function() { obj.list.clipboard(); } ],
110                         'cmd_z3950_csv_to_clipboard' : [ ['command'], function() { obj.list.dump_csv_to_clipboard(); } ],
111                         'cmd_z3950_csv_to_printer' : [ ['command'], function() { obj.list.dump_csv_to_printer(); } ], 
112                         'cmd_z3950_csv_to_file' : [ ['command'], function() { obj.list.dump_csv_to_file( { 'defaultFileName' : 'z3950_results.txt' } ); } ],
113                         'cmd_broken' : [
114                             ['command'],
115                             function() { alert('Not Yet Implemented'); }
116                         ],
117                         'result_message' : [['render'],function(e){return function(){};}],
118                         'clear' : [
119                             ['command'],
120                             function() {
121                                 obj.clear();
122                             }
123                         ],
124                         'save_creds' : [
125                             ['command'],
126                             function() {
127                                 obj.save_creds();
128                                 setTimeout( function() { obj.focus(); }, 0 );
129                             }
130                         ],
131                         'marc_view_btn' : [
132                             ['render'],
133                             function(e) {
134                                 e.setAttribute('label', $("catStrings").getString('staff.cat.z3950.marc_view.label'));
135                                 e.setAttribute('accesskey', $("catStrings").getString('staff.cat.z3950.marc_view.accesskey'));
136                             }
137                         ],
138                         'marc_view' : [
139                             ['command'],
140                             function(ev) {
141                                 try {
142                                     var n = obj.controller.view.marc_view_btn;
143                                     if (n.getAttribute('toggle') == '1') {
144                                         document.getElementById('deck').selectedIndex = 0;
145                                         n.setAttribute('toggle','0');
146                                         n.setAttribute('label', $("catStrings").getString('staff.cat.z3950.marc_view.label'));
147                                         n.setAttribute('accesskey', $("catStrings").getString('staff.cat.z3950.marc_view.accesskey'));
148                                         document.getElementById('results').focus();
149                                     } else {
150                                         document.getElementById('deck').selectedIndex = 1;
151                                         n.setAttribute('toggle','1');
152                                         n.setAttribute('label', $("catStrings").getString('staff.cat.z3950.results_view.label'));
153                                         n.setAttribute('accesskey', $("catStrings").getString('staff.cat.z3950.results_view.accesskey'));
154                                         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
155                                         var f = get_contentWindow(document.getElementById('marc_frame'));
156                                         var retrieve_id = n.getAttribute('retrieve_id');
157                                         var result_idx = retrieve_id.split('-')[0];
158                                         var record_idx = retrieve_id.split('-')[1];
159                                         f.xulG = { 'marcxml' : obj.result_set[result_idx].records[ record_idx ].marcxml };
160                                         f.my_init();
161                                         f.document.body.firstChild.focus();
162                                     }
163                                 } catch(E) {
164                                     obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.marc_view_error'),E);
165                                 }
166                             },
167                         ],
168                         'mark_overlay' : [
169                             ['command'],
170                             function() {
171                                 try {
172                                     var doc_id = obj.controller.view.mark_overlay.getAttribute('doc_id');
173                                     if (doc_id) {
174                                         cat.util.mark_for_overlay(doc_id);
175                                     }
176                                 } catch(E) {
177                                     alert('Error in z3950.js, mark_overlay: ' + E);
178                                 }
179                             }
180                         ],
181                         'show_in_catalog' : [
182                             ['command'],
183                             function() {
184                                 try {
185                                     var doc_id = obj.controller.view.mark_overlay.getAttribute('doc_id');
186                                     if (doc_id) {
187                                         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + doc_id;
188                                         var content_params = { 
189                                             'session' : ses(),
190                                             'authtime' : ses('authtime'),
191                                             'opac_url' : opac_url,
192                                         };
193                                         xulG.new_tab(
194                                                      xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
195                                                      {'tab_name': $("catStrings").getString('staff.cat.z3950.replace_tab_with_opac.tab_name')}, 
196                                                      content_params
197                                                      );
198                                     }
199                                 } catch(E) {
200                                     alert('Error in z3950.js, show_in_catalog: ' + E);
201                                 }
202                             }
203                         ],
204                         'marc_import' : [
205                             ['command'],
206                             function() {
207                                 try {
208                                     var retrieve_id = obj.controller.view.marc_import.getAttribute('retrieve_id');
209                                     var result_idx = retrieve_id.split('-')[0];
210                                     var record_idx = retrieve_id.split('-')[1];
211                                     obj.spawn_marc_editor( 
212                                         obj.result_set[ result_idx ].records[ record_idx ].marcxml,
213                                         obj.result_set[ result_idx ].records[ record_idx ].service /* FIXME: we want biblio_source here */
214                                     );
215                                 } catch(E) {
216                                     obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.marc_import_error'),E);
217                                 }
218                             },
219                         ],
220                         'marc_import_overlay' : [ 
221                             ['command'],
222                             function() {
223                                 try {
224                                     var retrieve_id = obj.controller.view.marc_import_overlay.getAttribute('retrieve_id');
225                                     var result_idx = retrieve_id.split('-')[0];
226                                     var record_idx = retrieve_id.split('-')[1];
227                                     obj.spawn_marc_editor_for_overlay( 
228                                         obj.result_set[ result_idx ].records[ record_idx ].marcxml,
229                                         obj.result_set[ result_idx ].records[ record_idx ].service /* FIXME: we want biblio_source here */
230                                     );
231                                 } catch(E) {
232                                     obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.marc_import_overlay_error'),E);
233                                 }
234                             },
235                         ],
236                         'search' : [
237                             ['command'],
238                             function() {
239                                 obj.initial_search();
240                             },
241                         ],
242                         'raw_search' : [ 
243                             ['command'], 
244                             function() { 
245                                 var raw = window.prompt(
246                                     $("catStrings").getString('staff.cat.z3950.initial_search.raw_prompt.msg'),
247                                     $("catStrings").getString('staff.cat.z3950.initial_search.raw_prompt.default_value'),
248                                     $("catStrings").getString('staff.cat.z3950.initial_search.raw_prompt.title')
249                                 ); 
250                                 if (raw) obj.initial_raw_search(raw); 
251                             } 
252                         ], 
253                         'page_next' : [
254                             ['command'],
255                             function() {
256                                 obj.page_next();
257                             },
258                         ],
259                         'toggle_form_btn' : [
260                             ['render'],
261                             function(e) {
262                                 e.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
263                                 e.setAttribute('label',$("catStrings").getString('staff.cat.z3950.hide_top_pane.label'));
264                                 e.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.hide_top_pane.accesskey'));
265                             }
266                         ],
267                         'toggle_form' : [
268                             ['command'],
269                             function() {
270                                 var x = document.getElementById('top_pane');
271                                 document.getElementById('splitter_grippy2').doCommand();
272                                 var n = obj.controller.view.toggle_form_btn;
273                                 if (x.collapsed) {
274                                     n.setAttribute('image',"/xul/server/skin/media/images/down_arrow.gif");
275                                     n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.label'));
276                                     n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.accesskey'));
277                                 } else {
278                                     n.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
279                                     n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.hide_top_pane.label'));
280                                     n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.hide_top_pane.accesskey'));
281                                 }
282                             },
283                         ],
284                         'splitter_grippy2' : [
285                             ['click'],
286                             function() {
287                                 var x = document.getElementById('top_pane');
288                                 var n = obj.controller.view.toggle_form_btn;
289                                 if (x.collapsed) {
290                                     n.setAttribute('image',"/xul/server/skin/media/images/down_arrow.gif");
291                                     n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.label'));
292                                     n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.accesskey'));
293                                 } else {
294                                     n.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
295                                     n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.hide_top_pane.label'));
296                                     n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.hide_top_pane.accesskey'));
297                                 }
298                             }
299                         ],
300                         'service_rows' : [
301                             ['render'],
302                             function(e) {
303                                 return function() {
304                                     try {
305
306                                         function handle_switch(node) {
307                                             try {
308                                                 $('search').setAttribute('disabled','true'); $('raw_search').setAttribute('disabled','true');
309                                                 obj.active_services = [];
310                                                 var snl = document.getElementsByAttribute('mytype','service_class');
311                                                 for (var i = 0; i < snl.length; i++) {
312                                                     var n = snl[i];
313                                                     if (n.nodeName == 'checkbox') {
314                                                         if (n.checked) obj.active_services.push( n.getAttribute('service') );
315                                                     }
316                                                 }
317                                                 if (obj.active_services.length > 0) {
318                                                     $('search').setAttribute('disabled','false'); 
319                                                 }
320                                                 if (obj.active_services.length == 1) {
321                                                     if (obj.active_services[0] != 'native-evergreen-catalog') { 
322                                                         $('raw_search').setAttribute('disabled','false');
323                                                     }
324                                                 }
325                                                 var nl = document.getElementsByAttribute('mytype','search_class');
326                                                 for (var i = 0; i < nl.length; i++) { nl[i].disabled = true; }
327                                                 var attrs = {};
328                                                 for (var j = 0; j < obj.active_services.length; j++) {
329                                                     if (obj.services[obj.active_services[j]]) for (var i in obj.services[obj.active_services[j]].attrs) {
330                                                         var attr = obj.services[obj.active_services[j]].attrs[i];
331                                                         if (! attrs[i]) {
332                                                             attrs[i] = { 'labels' : {} };
333                                                         }
334                                                         if (attr.label) {
335                                                             attrs[i].labels[ attr.label ] = true;
336                                                         } else if (document.getElementById('commonStrings').testString('staff.z39_50.search_class.' + i)) {
337                                                             attrs[i].labels[ document.getElementById('commonStrings').getString('staff.z39_50.search_class.' + i) ] = true;
338                                                         } else if (attr.name) {
339                                                             attrs[i].labels[ attr.name ] = true;
340                                                         } else {
341                                                             attrs[i].labels[ i ] = true;
342                                                         }
343
344                                                     }
345                                                     
346                                                 }
347
348                                                 function set_label(x,attr) {
349                                                     var labels = [];
350                                                     for (var j in attrs[attr].labels) {
351                                                         labels.push(j);
352                                                     }
353                                                     if (labels.length > 0) {
354                                                         x.setAttribute('value',labels[0]);
355                                                         x.setAttribute('tooltiptext',labels.join(','));
356                                                         if (labels.length > 1) x.setAttribute('class','multiple_labels');
357                                                     }
358                                                 }
359
360                                                 for (var i in attrs) {
361                                                     var x = document.getElementById(i + '_input');
362                                                     if (x) {
363                                                         x.disabled = false;
364                                                         var y = document.getElementById(i + '_label',i);
365                                                         if (y) set_label(y,i);
366                                                     } else {
367                                                         var rows = document.getElementById('query_inputs');
368                                                         var row = document.createElement('row'); rows.appendChild(row);
369                                                         var label = document.createElement('label');
370                                                         label.setAttribute('id',i+'_label');
371                                                         label.setAttribute('control',i+'_input');
372                                                         label.setAttribute('search_class',i);
373                                                         label.setAttribute('style','-moz-user-focus: ignore');
374                                                         row.appendChild(label);
375                                                         set_label(label,i);
376                                                         label.addEventListener('click',function(ev){
377                                                                 var a = ev.target.getAttribute('search_class');
378                                                                 if (a) obj.default_attr = a;
379                                                             },false
380                                                         );
381                                                         var tb = document.createElement('textbox');
382                                                         tb.setAttribute('id',i+'_input');
383                                                         tb.setAttribute('mytype','search_class');
384                                                         tb.setAttribute('search_class',i);
385                                                         row.appendChild(tb);
386                                                         tb.addEventListener('keypress',function(ev) { return obj.handle_enter(ev); },false);
387                                                     }
388                                                 }
389                                             } catch(E) {
390                                                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.search_fields_error'),E);
391                                             }
392                                         }
393
394                                         document.getElementById('native-evergreen-catalog_service').addEventListener('command',handle_switch,false);
395
396                                         var robj = obj.network.simple_request(
397                                             'RETRIEVE_Z3950_SERVICES',
398                                             [ ses() ]
399                                         );
400                                         if (typeof robj.ilsevent != 'undefined') throw(robj);
401                                         obj.services = robj;
402                                         var x = document.getElementById('service_rows');
403                                         var services = new Array();
404                                         for (var i in obj.services) {
405                                             var label;
406                                             if (obj.services[i].label) {
407                                                 label = obj.services[i].label;
408                                             } else if (obj.services[i].name) {
409                                                 label = obj.services[i].name;
410                                             } else {
411                                                 label = i;
412                                             }
413                                             var j = [label, i];
414                                             services.push(j);
415                                         }
416                                         services.sort();
417                                         for (var j=0; j < services.length; j++) {
418                                             var i = services[j][1];
419                                             try {
420                                                 if (i == 'native-evergreen-catalog') continue;
421                                                 var r = document.createElement('row'); x.appendChild(r);
422                                                 var cb = document.createElement('checkbox'); 
423                                                     cb.setAttribute('label',services[j][0]);
424                                                     cb.setAttribute('tooltiptext',i + ' : ' + obj.services[i].db + '@' + obj.services[i].host + ':' + obj.services[i].port); 
425                                                     cb.setAttribute('mytype','service_class'); cb.setAttribute('service',i);
426                                                     cb.setAttribute('id',i+'_service'); r.appendChild(cb);
427                                                     cb.addEventListener('command',handle_switch,false);
428                                                 var username = document.createElement('textbox'); username.setAttribute('id',i+'_username'); 
429                                                 if (obj.creds.hosts[ obj.data.server_unadorned ] && obj.creds.hosts[ obj.data.server_unadorned ].services[i]) username.setAttribute('value',obj.creds.hosts[ obj.data.server_unadorned ].services[i].username);
430                                                 r.appendChild(username);
431                                                 if (typeof obj.services[i].auth != 'undefined') username.hidden = ! get_bool( obj.services[i].auth );
432                                                 var password = document.createElement('textbox'); password.setAttribute('id',i+'_password'); 
433                                                 if (obj.creds.hosts[ obj.data.server_unadorned ] && obj.creds.hosts[ obj.data.server_unadorned ].services[i]) password.setAttribute('value',obj.creds.hosts[ obj.data.server_unadorned ].services[i].password);
434                                                 password.setAttribute('type','password'); r.appendChild(password);
435                                                 if (typeof obj.services[i].auth != 'undefined') password.hidden = ! get_bool( obj.services[i].auth );
436                                             } catch(E) {
437                                                 alert(E);
438                                             }
439                                         }
440                                         //obj.services[ 'native-evergreen-catalog' ] = { 'attrs' : { 'author' : {}, 'title' : {} } };
441                                         setTimeout(
442                                             function() { 
443                                                 if (obj.creds.hosts[ obj.data.server_unadorned ]) {
444                                                     for (var i = 0; i < obj.creds.hosts[ obj.data.server_unadorned ].default_services.length; i++) {
445                                                         var x = document.getElementById(obj.creds.hosts[ obj.data.server_unadorned ].default_services[i]+'_service');
446                                                         if (x) x.checked = true;
447                                                     }
448                                                 } else if (obj.creds.default_service) {
449                                                     var x = document.getElementById(obj.creds.default_service+'_service');
450                                                     if (x) x.checked = true;
451                                                 }
452                                                 handle_switch();
453                                             },0
454                                         );
455                                     } catch(E) {
456                                         obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.z39_service_error'),E);
457                                     }
458                                 }
459                             }
460                         ],
461                     }
462                 }
463             );
464
465             obj.controller.render();
466
467             setTimeout( function() { obj.focus(); }, 0 );
468
469             setInterval( 
470                 function() {
471                     obj.data.init({'via':'stash'});
472                     if (obj.data.marked_record) {
473                         var sel = obj.list.retrieve_selection();
474                         if (sel.length > 0) { obj.controller.view.marc_import_overlay.disabled = false; }
475                         if ($("overlay_tcn_indicator")) {
476                             if (obj.data.marked_record_mvr) {
477                                 $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.tcn.label',[obj.data.marked_record_mvr.tcn()]));
478                             } else {
479                                 $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.record_id.label',[obj.data.marked_record]));
480                             }
481                         }
482                     } else {
483                         obj.controller.view.marc_import_overlay.disabled = true;
484                         if ($("overlay_tcn_indicator")) {
485                             $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getString('staff.cat.z3950.marked_record_for_overlay_indicator.no_record.label'));
486                         }
487                     }
488                 }, 2000
489             );
490
491         } catch(E) {
492             this.error.sdump('D_ERROR','cat.z3950.init: ' + E + '\n');
493         }
494     },
495
496     'focus' : function() {
497         var obj = this;
498         var focus_me; var or_focus_me;
499         for (var i = 0; i < obj.active_services.length; i++) {
500             if (obj.creds.hosts[ obj.data.server_unadorned ] && obj.creds.hosts[ obj.data.server_unadorned ].services[ obj.active_services[i] ]) {
501                 var x = obj.creds.hosts[ obj.data.server_unadorned ].services[ obj.active_services[i] ].default_attr;
502                 if (x) { focus_me = x; break; }
503             }
504             if (obj.services[ obj.active_services[i] ]) for (var i in obj.services[ obj.active_services[i] ].attr) { or_focus_me = i; }
505         }
506         if (! focus_me) focus_me = or_focus_me;
507         var xx = document.getElementById(focus_me+'_input'); if (xx) xx.focus();
508     },
509
510     'clear' : function() {
511         var obj = this;
512         var nl = document.getElementsByAttribute('mytype','search_class');
513         for (var i = 0; i < nl.length; i++) { nl[i].value = ''; nl[i].setAttribute('value',''); }
514         obj.focus();
515     },
516
517     'search_params' : {},
518
519     'initial_search' : function() {
520         try {
521             var obj = this;
522             obj.result_set = []; obj.number_of_result_sets = 0;
523             JSAN.use('util.widgets');
524             util.widgets.remove_children( obj.controller.view.result_message );
525             var x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
526             if (obj.active_services.length < 1) {
527                 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.no_search_selection')));
528                 return;
529             }
530             x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.searching')));
531             obj.search_params = {}; obj.list.clear();
532             obj.controller.view.page_next.disabled = true;
533             obj.controller.view.cmd_z3950_csv_to_file.setAttribute('disabled','true');
534             obj.controller.view.cmd_z3950_csv_to_clipboard.setAttribute('disabled','true');
535             obj.controller.view.cmd_z3950_csv_to_printer.setAttribute('disabled','true');
536
537             obj.search_params.service_array = []; 
538             obj.search_params.username_array = [];
539             obj.search_params.password_array = [];
540             for (var i = 0; i < obj.active_services.length; i++) {
541                 obj.search_params.service_array.push( obj.active_services[i] );
542                 obj.search_params.username_array.push( document.getElementById( obj.active_services[i]+'_username' ).value );
543                 obj.search_params.password_array.push( document.getElementById( obj.active_services[i]+'_password' ).value );
544             }
545             obj.search_params.limit = Math.ceil( obj.limit / obj.active_services.length );
546             obj.search_params.offset = 0;
547
548             obj.search_params.search = {};
549             var nl = document.getElementsByAttribute('mytype','search_class');
550             var count = 0;
551             for (var i = 0; i < nl.length; i++) {
552                 if (nl[i].disabled) continue;
553                 if (nl[i].value == '') continue;
554                 count++;
555                 obj.search_params.search[ nl[i].getAttribute('search_class') ] = nl[i].value;
556             }
557             if (count>0) {
558                 obj.search();
559             } else {
560                 util.widgets.remove_children( obj.controller.view.result_message );
561             }
562         } catch(E) {
563             this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.initial_search.failed_search'),E);
564         }
565     },
566
567     'initial_raw_search' : function(raw) {
568         try {
569             var obj = this;
570             obj.result_set = []; obj.number_of_result_sets = 0;
571             JSAN.use('util.widgets');
572             util.widgets.remove_children( obj.controller.view.result_message );
573             var x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
574             if (obj.active_services.length < 1) {
575                 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.no_search_selection')));
576                 return;
577             }
578             if (obj.active_services.length > 1) {
579                 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.too_many_selections')));
580                 return;
581             }
582             if (obj.active_services[0] == 'native-evergreen-catalog') {
583                 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.raw_search_unsupported_for_native_catalog')));
584                 return;
585             }
586             x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.searching')));
587             obj.search_params = {}; obj.list.clear();
588             obj.controller.view.page_next.disabled = true;
589             obj.controller.view.cmd_z3950_csv_to_file.setAttribute('disabled','true');
590             obj.controller.view.cmd_z3950_csv_to_clipboard.setAttribute('disabled','true');
591             obj.controller.view.cmd_z3950_csv_to_printer.setAttribute('disabled','true');
592
593             obj.search_params.service_array = []; 
594             obj.search_params.username_array = [];
595             obj.search_params.password_array = [];
596             for (var i = 0; i < obj.active_services.length; i++) {
597                 obj.search_params.service_array.push( obj.active_services[i] );
598                 obj.search_params.username_array.push( document.getElementById( obj.active_services[i]+'_username' ).value );
599                 obj.search_params.password_array.push( document.getElementById( obj.active_services[i]+'_password' ).value );
600             }
601             obj.search_params.limit = Math.ceil( obj.limit / obj.active_services.length );
602             obj.search_params.offset = 0;
603
604             obj.search_params.query = raw;
605
606             obj.search();
607         } catch(E) {
608             this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.initial_search.failed_search'),E);
609         }
610     },
611
612     'page_next' : function() {
613         try {
614             var obj = this;
615             JSAN.use('util.widgets');
616             util.widgets.remove_children( obj.controller.view.result_message );
617             var x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
618             x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.page_next.more_results')));
619             obj.search_params.offset += obj.search_params.limit;
620             obj.search();
621         } catch(E) {
622             this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.page_next.subsequent_search_error'),E);
623         }
624     },
625
626     'search' : function() {
627         try {
628             var obj = this;
629             var method;
630             if (typeof obj.search_params.query == 'undefined') {
631                 method = 'FM_BLOB_RETRIEVE_VIA_Z3950_SEARCH';
632                 obj.search_params.service = obj.search_params.service_array;
633                 obj.search_params.username = obj.search_params.username_array;
634                 obj.search_params.password = obj.search_params.password_array;
635             } else {
636                 method = 'FM_BLOB_RETRIEVE_VIA_Z3950_RAW_SEARCH';
637                 obj.search_params.service = obj.search_params.service_array[0];
638                 obj.search_params.username = obj.search_params.username_array[0];
639                 obj.search_params.password = obj.search_params.password_array[0];
640             }
641             obj.network.simple_request(
642                 method,
643                 [ ses(), obj.search_params ],
644                 function(req) {
645                     obj.handle_results(req.getResultObject())
646                 }
647             );
648             document.getElementById('deck').selectedIndex = 0;
649         } catch(E) {
650             this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.search.search_error'),E);
651         }
652     },
653
654     'handle_results' : function(results) {
655         var obj = this;
656         try {
657             JSAN.use('util.widgets');
658             util.widgets.remove_children( obj.controller.view.result_message ); var x;
659             if (results == null) {
660                 x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
661                 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.handle_results.null_server_error')));
662                 return;
663             }
664             if (typeof results.ilsevent != 'undefined') {
665                 x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
666                 x.appendChild( document.createTextNode($("catStrings").getFormattedString('staff.cat.z3950.handle_results.server_error', [results.textcode, results.desc])));
667                 return;
668             }
669             obj.controller.view.cmd_z3950_csv_to_file.setAttribute('disabled','false');
670             obj.controller.view.cmd_z3950_csv_to_clipboard.setAttribute('disabled','false');
671             obj.controller.view.cmd_z3950_csv_to_printer.setAttribute('disabled','false');
672             if (typeof results.length == 'undefined') results = [ results ];
673
674             var total_showing = 0;
675             var total_count = 0;
676             var tooltip_msg = '';
677
678             for (var i = 0; i < results.length; i++) {
679                 if (results[i].query) {
680                     tooltip_msg += $("catStrings").getFormattedString('staff.cat.z3950.handle_results.raw_query', [results[i].query]) + '\n';
681                 }
682                 if (results[i].count) {
683                     if (results[i].records) {
684                         var showing = obj.search_params.offset + results[i].records.length; 
685                         total_showing += obj.search_params.offset + results[i].records.length; 
686                         total_count += results[i].count;
687                         tooltip_msg += $("catStrings").getFormattedString('staff.cat.z3950.handle_results.showing_results', [(showing > results[i].count ? results[i].count : showing), results[i].count, results[i].service]) + '\n';
688                     }
689                     if (obj.search_params.offset + obj.search_params.limit <= results[i].count) {
690                         obj.controller.view.page_next.disabled = false;
691                     }
692                 } else {
693                     tooltip_msg += $("catStrings").getFormattedString('staff.cat.z3950.handle_results.num_of_results', [(results[i].count ? results[i].count : 0)]) + '\n';
694                 }
695                 if (results[i].records) {
696                     obj.result_set[ ++obj.number_of_result_sets ] = results[i];
697                     obj.controller.view.marc_import.disabled = true;
698                     obj.controller.view.marc_import_overlay.disabled = true;
699                     var x = obj.controller.view.marc_view_btn;
700                     if (x.getAttribute('toggle') == '0') x.disabled = true;
701                     for (var j = 0; j < obj.result_set[ obj.number_of_result_sets ].records.length; j++) {
702                         var f;
703                         var n = obj.list.append(
704                             {
705                                 'retrieve_id' : String( obj.number_of_result_sets ) + '-' + String( j ),
706                                 'row' : {
707                                     'my' : {
708                                         'mvr' : function(a){
709                                             if (a.bibid) {
710                                                 // We have col definitions, etc.
711                                                 // expecting doc_id
712                                                 a.mvr.doc_id( a.bibid );
713                                             }
714                                             return a.mvr;
715                                         }(obj.result_set[ obj.number_of_result_sets ].records[j]),
716                                         'service' : results[i].service
717                                     }
718                                 }
719                             }
720                         );
721                         n.treeitem_node.setAttribute('isbn', function(a){return a;}(obj.result_set[ obj.number_of_result_sets ].records[j].mvr).isbn());
722                         n.treeitem_node.setAttribute(
723                             'service',
724                             function(a){return a;}(
725                                 results[i].service
726                             )
727                         );
728                         n.treeitem_node.setAttribute(
729                             'doc_id',
730                             function(a){return a;}(
731                                 (obj.result_set[ obj.number_of_result_sets ].records[j].mvr)
732                             ).doc_id()
733                         );
734
735                         if (!f) { n.treeitem_node.parentNode.focus(); f = n; } 
736                     }
737                 } else {
738                     x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
739                     x.appendChild(
740                         document.createTextNode($("catStrings").getString('staff.cat.z3950.handle_results.result_error'))
741                     );
742                 }
743             }
744             if (total_showing) {
745                 x = document.createElement('description'); 
746                 x.setAttribute('crop','end');
747                 x.setAttribute('tooltiptext',tooltip_msg);
748                 obj.controller.view.result_message.appendChild(x);
749                 x.appendChild(
750                     document.createTextNode($("catStrings").getFormattedString('staff.cat.z3950.handle_results.showing_total_results',
751                         [(total_showing > total_count ? total_count : total_showing), total_count]))
752                 );
753             } else {
754                 x = document.createElement('description'); 
755                 x.setAttribute('crop','end');
756                 x.setAttribute('tooltiptext',tooltip_msg);
757                 obj.controller.view.result_message.appendChild(x);
758                 x.appendChild(
759                     document.createTextNode($("catStrings").getFormattedString('staff.cat.z3950.handle_results.num_of_results', [(total_count ? total_count : 0)]))
760                 );
761             }            
762
763         } catch(E) {
764             this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.handle_results.search_result_error'),E);
765         }
766     },
767
768     'replace_tab_with_opac' : function(doc_id) {
769         var opac_url = xulG.url_prefix( urls.opac_rdetail ) + doc_id;
770         var content_params = { 
771             'session' : ses(),
772             'authtime' : ses('authtime'),
773             'opac_url' : opac_url,
774         };
775         xulG.set_tab(
776             xulG.url_prefix(urls.XUL_OPAC_WRAPPER), 
777             {'tab_name': $("catStrings").getString('staff.cat.z3950.replace_tab_with_opac.tab_name')}, 
778             content_params
779         );
780     },
781
782     'spawn_marc_editor' : function(my_marcxml,biblio_source) {
783         var obj = this;
784
785         function save_marc (new_marcxml) {
786             try {
787                 var r = obj.network.simple_request('MARC_XML_RECORD_IMPORT', [ ses(), new_marcxml, biblio_source ]);
788                 if (typeof r.ilsevent != 'undefined') {
789                     switch(Number(r.ilsevent)) {
790                         case 1704 /* TCN_EXISTS */ :
791                             var msg = $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor.same_tcn', [r.payload.tcn]);
792                             var title = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.title');
793                             var btn1 = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.btn1_overlay');
794                             var btn2 = typeof r.payload.new_tcn == 'undefined' ? null : $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor.btn2_import', [r.payload.new_tcn]);
795                             if (btn2) {
796                                 obj.data.init({'via':'stash'});
797                                 var robj = obj.network.simple_request(
798                                     'PERM_CHECK',[
799                                         ses(),
800                                         obj.data.list.au[0].id(),
801                                         obj.data.list.au[0].ws_ou(),
802                                         [ 'ALLOW_ALT_TCN' ]
803                                     ]
804                                 );
805                                 if (typeof robj.ilsevent != 'undefined') {
806                                     obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.permission_error'),E);
807                                 }
808                                 if (robj.length != 0) btn2 = null;
809                             }
810                             var btn3 = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.btn3_cancel_import');
811                             var p = obj.error.yns_alert(msg,title,btn1,btn2,btn3,$("catStrings").getString('staff.cat.z3950.spawn_marc_editor.confirm_action'));
812                             obj.error.sdump('D_ERROR','option ' + p + 'chosen');
813                             switch(p) {
814                                 case 0:
815                                     var r3 = obj.network.simple_request('MARC_XML_RECORD_UPDATE', [ ses(), r.payload.dup_record, new_marcxml, biblio_source ]);
816                                     if (typeof r3.ilsevent != 'undefined') {
817                                         throw(r3);
818                                     } else {
819                                         alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.successful_overlay'));
820                                         return {
821                                             'id' : r3.id(),
822                                             'on_complete' : function() {
823                                                 try {
824                                                     obj.replace_tab_with_opac(r3.id());
825                                                 } catch(E) {
826                                                     alert(E);
827                                                 }
828                                             }
829                                         };
830                                     }
831                                 break;
832                                 case 1:
833                                     var r2 = obj.network.request(
834                                         api.MARC_XML_RECORD_IMPORT.app,
835                                         api.MARC_XML_RECORD_IMPORT.method + '.override',
836                                         [ ses(), new_marcxml, biblio_source ]
837                                     );
838                                     if (typeof r2.ilsevent != 'undefined') {
839                                         throw(r2);
840                                     } else {
841                                         alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.successful_import_with_new_tcn'));
842                                         return {
843                                             'id' : r2.id(),
844                                             'on_complete' : function() {
845                                                 try {
846                                                     obj.replace_tab_with_opac(r2.id());
847                                                 } catch(E) {
848                                                     alert(E);
849                                                 }
850                                             }
851                                         };
852                                     }
853                                 break;
854                                 case 2:
855                                 default:
856                                     alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.import_cancelled'));
857                                 break;
858                             }
859                         break;
860                         default:
861                             throw(r);
862                         break;
863                     }
864                 } else {
865                     alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.successful_import'));
866                     return {
867                         'id' : r.id(),
868                         'on_complete' : function() {
869                             try {
870                                 obj.replace_tab_with_opac(r.id());
871                             } catch(E) {
872                                 alert(E);
873                             }
874                         }
875                     };
876                 }
877             } catch(E) {
878                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.import_error'),E);
879             }
880         };
881
882         if ( $('marc_editor').checked ) {
883             xulG.new_tab(
884                 xulG.url_prefix(urls.XUL_MARC_EDIT), 
885                 { 'tab_name' : 'MARC Editor' }, 
886                 { 
887                     'marc_control_number_identifier': obj.data.hash.aous['cat.marc_control_number_identifier'] || 'Set cat.marc_control_number_identifier in Library Settings',
888                     'record' : { 'marc' : my_marcxml, "rtype": "bre" },
889                     'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
890                         try {
891                             JSAN.use('cat.util'); return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
892                         } catch(E) {
893                             alert(E);
894                         }
895                     },
896                     'save' : {
897                         'label' : $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.save_button_label'),
898                         'func' : save_marc
899                     },
900                     'lock_tab' : xulG.lock_tab,
901                     'unlock_tab' : xulG.unlock_tab
902                 } 
903             );
904         } else {
905             save_marc(my_marcxml);
906         }
907     },
908
909     'confirm_overlay' : function(record_ids) {
910         var obj = this; // JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
911         netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect UniversalBrowserWrite');
912         var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" >';
913         top_xml += '<description>'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.description')+'</description>';
914         top_xml += '<hbox><button id="lead" disabled="false" label="'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.lead.label')+'" name="fancy_submit"';
915         top_xml += ' accesskey="'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.lead.accesskey')+'"/>';
916         top_xml += ' <button label="'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.cancel.label')+'" accesskey="'+
917                         $("catStrings").getString('staff.cat.z3950.confirm_overlay.cancel.accesskey')+'" name="fancy_cancel"/></hbox></vbox>';
918
919         var xml = '<form xmlns="http://www.w3.org/1999/xhtml">';
920         xml += '<table width="100%"><tr valign="top">';
921         for (var i = 0; i < record_ids.length; i++) {
922             xml += '<td nowrap="nowrap"><iframe src="' + urls.XUL_BIB_BRIEF; 
923             xml += '?docid=' + record_ids[i] + '"/></td>';
924         }
925         xml += '</tr><tr valign="top">';
926         for (var i = 0; i < record_ids.length; i++) {
927             xml += '<td nowrap="nowrap"><iframe style="min-height: 1000px; min-width: 300px;" flex="1" src="' + urls.XUL_MARC_VIEW + '?docid=' + record_ids[i] + ' "/></td>';
928         }
929         xml += '</tr></table></form>';
930         // data.temp_merge_top = top_xml; data.stash('temp_merge_top');
931         // data.temp_merge_mid = xml; data.stash('temp_merge_mid');
932         JSAN.use('util.window'); var win = new util.window();
933         var fancy_prompt_data = win.open(
934             urls.XUL_FANCY_PROMPT,
935             // + '?xml_in_stash=temp_merge_mid'
936             // + '&top_xml_in_stash=temp_merge_top'
937             // + '&title=' + window.escape('Record Overlay'),
938             'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
939             { 'top_xml' : top_xml, 'xml' : xml, 'title' : $("catStrings").getString('staff.cat.z3950.confirm_overlay.title') }
940         );
941         //data.stash_retrieve();
942         if (fancy_prompt_data.fancy_status == 'incomplete') { alert($("catStrings").getString('staff.cat.z3950.confirm_overlay.aborted')); return false; }
943         return true;
944     },
945
946     'spawn_marc_editor_for_overlay' : function(my_marcxml,biblio_source) {
947         var obj = this;
948         obj.data.init({'via':'stash'});
949         if (!obj.data.marked_record) {
950             alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.try_again'));
951             return;
952         }
953
954         function overlay_marc (new_marcxml) {
955             try {
956                 if (! obj.confirm_overlay( [ obj.data.marked_record ] ) ) { return; }
957                 var r = obj.network.simple_request('MARC_XML_RECORD_REPLACE', [ ses(), obj.data.marked_record, new_marcxml, biblio_source ]);
958                 if (typeof r.ilsevent != 'undefined') {
959                     switch(Number(r.ilsevent)) {
960                         case 1704 /* TCN_EXISTS */ :
961                             var msg = $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor_for_overlay.same_tcn', [r.payload.tcn]);
962                             var title = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.import_collision');
963                             var btn1 = typeof r.payload.new_tcn == 'undefined' ? null : $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor_for_overlay.btn1_overlay', [r.payload.new_tcn]);
964                             if (btn1) {
965                                 var robj = obj.network.simple_request(
966                                     'PERM_CHECK',[
967                                         ses(),
968                                         obj.data.list.au[0].id(),
969                                         obj.data.list.au[0].ws_ou(),
970                                         [ 'ALLOW_ALT_TCN' ]
971                                     ]
972                                 );
973                                 if (typeof robj.ilsevent != 'undefined') {
974                                     obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.permission_error'),E);
975                                 }
976                                 if (robj.length != 0) btn1 = null;
977                             }
978                             var btn2 = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.btn2_cancel');
979                             var p = obj.error.yns_alert(msg,title,btn1,btn2,null, $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.confirm_action'));
980                             obj.error.sdump('D_ERROR','option ' + p + 'chosen');
981                             switch(p) {
982                                 case 0:
983                                     var r2 = obj.network.request(
984                                         api.MARC_XML_RECORD_REPLACE.app,
985                                         api.MARC_XML_RECORD_REPLACE.method + '.override',
986                                         [ ses(), obj.data.marked_record, new_marcxml, biblio_source ]
987                                     );
988                                     if (typeof r2.ilsevent != 'undefined') {
989                                         throw(r2);
990                                     } else {
991                                         alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.successful_overlay_with_new_TCN'));
992                                         return {
993                                             'id' : r2.id(),
994                                             'on_complete' : function() {
995                                                 try {
996                                                     obj.replace_tab_with_opac(r2.id());
997                                                 } catch(E) {
998                                                     alert(E);
999                                                 }
1000                                             }
1001                                         };
1002                                     }
1003                                 break;
1004                                 case 1:
1005                                 default:
1006                                     alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.cancelled_overlay'));
1007                                 break;
1008                             }
1009                         break;
1010                         default:
1011                             throw(r);
1012                         break;
1013                     }
1014                 } else {
1015                     alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.success_overlay'));
1016                     try {
1017                         obj.data.marked_record_mvr = null;
1018                         obj.data.marked_record = null;
1019                         obj.data.stash('marked_record');
1020                         obj.data.stash('marked_record_mvr');
1021                         obj.controller.view.marc_import_overlay.disabled = true;
1022                         if ($("overlay_tcn_indicator")) {
1023                             $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getString('staff.cat.z3950.marked_record_for_overlay_indicator.no_record.label'));
1024                         }
1025                         xulG.set_statusbar(1, $("catStrings").getString('staff.cat.z3950.marked_record_for_overlay_indicator.no_record.label') );
1026                     } catch(E) {
1027                         dump('Error in z3950.js, post-overlay: ' + E + '\n');
1028                     }
1029                     return {
1030                         'id' : r.id(),
1031                         'on_complete' : function() {
1032                             try {
1033                                 obj.replace_tab_with_opac(r.id());
1034                             } catch(E) {
1035                                 alert(E);
1036                             }
1037                         }
1038                     };
1039                 }
1040             } catch(E) {
1041                 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.overlay_error'),E);
1042             }
1043         }
1044
1045         if ( $('marc_editor').checked ) {
1046             xulG.new_tab(
1047                 xulG.url_prefix(urls.XUL_MARC_EDIT), 
1048                 { 'tab_name' : $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.tab_name') },
1049                 { 
1050                     'record' : { 'marc' : my_marcxml },
1051                     'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
1052                         try {
1053                             JSAN.use('cat.util'); cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
1054                         } catch(E) {
1055                             alert(E);
1056                         }
1057                     },
1058                     'save' : {
1059                         'label' : $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.overlay_record_label'),
1060                         'func' : overlay_marc
1061                     }
1062                 } 
1063             );
1064         } else {
1065             overlay_marc(my_marcxml);
1066         }
1067     },
1068
1069
1070     'load_creds' : function() {
1071         var obj = this;
1072         try {
1073             obj.creds = { 'version' : g.save_version, 'services' : {}, 'hosts' : {} };
1074             /*
1075                 {
1076                     'version' : xx,
1077                     'default_service' : xx,
1078                     'services' : {
1079
1080                         'xx' : {
1081                             'username' : xx,
1082                             'password' : xx,
1083                             'default_attr' : xx,
1084                         },
1085
1086                         'xx' : {
1087                             'username' : xx,
1088                             'password' : xx,
1089                             'default_attr' : xx,
1090                         },
1091                     },
1092                     // new in version 2
1093                     'hosts' : {
1094                         'xxxx' : {
1095                             'default_services' : [ xx, ... ],
1096                             'services' : {
1097
1098                                 'xx' : {
1099                                     'username' : xx,
1100                                     'password' : xx,
1101                                     'default_attr' : xx,
1102                                 },
1103
1104                                 'xx' : {
1105                                     'username' : xx,
1106                                     'password' : xx,
1107                                     'default_attr' : xx,
1108                                 },
1109                             },
1110                         }
1111                     }
1112                 }
1113             */
1114             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1115             JSAN.use('util.file'); var file = new util.file('z3950_store');
1116             if (file._file.exists()) {
1117                 var creds = file.get_object(); file.close();
1118                 if (typeof creds.version != 'undefined') {
1119                     if (creds.version >= obj.creds_version) {  /* so apparently, this guy is assuming that future versions will be backwards compatible */
1120                         if (typeof creds.hosts == 'undefined') creds.hosts = {};
1121                         obj.creds = creds;
1122                     }
1123                 }
1124             }
1125         } catch(E) {
1126             obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.load_creds.z3950_cred_error'),E);
1127         }
1128     },
1129
1130     'save_creds' : function () {
1131         try {
1132             var obj = this;
1133             if (typeof obj.creds.hosts == 'undefined') obj.creds.hosts = {};
1134             if (typeof obj.creds.hosts[ obj.data.server_unadorned ] == 'undefined') obj.creds.hosts[ obj.data.server_unadorned ] = { 'services' : {} };
1135             obj.creds.hosts[ obj.data.server_unadorned ].default_services = obj.active_services;
1136             for (var i = 0; i < obj.creds.hosts[ obj.data.server_unadorned ].default_services.length; i++) {
1137                 var service = obj.creds.hosts[ obj.data.server_unadorned ].default_services[i];
1138                 if (typeof obj.creds.hosts[ obj.data.server_unadorned ].services[ service ] == 'undefined') {
1139                     obj.creds.hosts[ obj.data.server_unadorned ].services[ service ] = {}
1140                 }
1141                 obj.creds.hosts[ obj.data.server_unadorned ].services[service].username = document.getElementById(service + '_username').value;
1142                 obj.creds.hosts[ obj.data.server_unadorned ].services[service].password = document.getElementById(service + '_password').value;
1143                 if (obj.default_attr) {
1144                     obj.creds.hosts[ obj.data.server_unadorned ].services[service].default_attr = obj.default_attr;
1145                 }
1146             }
1147             obj.creds.version = obj.creds_version;
1148             netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
1149             JSAN.use('util.file'); var file = new util.file('z3950_store');
1150             file.set_object(obj.creds);
1151             file.close();
1152         } catch(E) {
1153             obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.save_creds.z3950_cred_error'),E);
1154         }
1155     },
1156
1157     'handle_enter' : function(ev) {
1158         var obj = this;
1159         if (ev.target.tagName != 'textbox') return;
1160         if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* enter on a mac */) setTimeout( function() { obj.initial_search(); }, 0);
1161     },
1162 }
1163
1164 dump('exiting cat.z3950.js\n');