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