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