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