1 dump('entering cat.z3950.js\n');
3 function $(id) { return document.getElementById(id); }
5 if (typeof cat == 'undefined') cat = {};
6 cat.z3950 = function (params) {
8 JSAN.use('util.error'); this.error = new util.error();
9 JSAN.use('util.network'); this.network = new util.network();
11 dump('cat.z3950: ' + E + '\n');
15 cat.z3950.prototype = {
19 'number_of_result_sets' : 0,
23 'results_buffer' : [],
25 'on_display' : [], // Values transfered to display
27 'save_count' : [], // Values available from data source
31 'init' : function( params ) {
34 JSAN.use('util.widgets');
38 JSAN.use('OpenILS.data'); obj.data = new OpenILS.data(); obj.data.init({'via':'stash'});
44 JSAN.use('circ.util');
45 var columns = circ.util.columns(
47 'tcn' : { 'hidden' : false },
48 'isbn' : { 'hidden' : false },
49 'title' : { 'hidden' : false, 'flex' : '1' },
50 'author' : { 'hidden' : false },
51 'edition' : { 'hidden' : false },
52 'pubdate' : { 'hidden' : false },
53 'publisher' : { 'hidden' : false },
54 'service' : { 'hidden' : false }
58 JSAN.use('util.list'); obj.list = new util.list('results');
62 'on_select' : function(ev) {
64 JSAN.use('util.functional');
65 var sel = obj.list.retrieve_selection();
66 document.getElementById('sel_clip').setAttribute('disabled', sel.length < 1);
67 var list = util.functional.map_list(
70 if ( $('jacket_image') ) {
71 // A side-effect in this map function, mu hahaha
72 if (o.getAttribute('isbn')) {
73 $('jacket_image').setAttribute('src',urls.ac_jacket_large+o.getAttribute('isbn'));
74 $('jacket_image').setAttribute('tooltiptext',urls.ac_jacket_large+o.getAttribute('isbn'));
76 $('jacket_image').setAttribute('src','');
77 $('jacket_image').setAttribute('tooltiptext','');
80 if (o.getAttribute('service') == 'native-evergreen-catalog') {
81 $('mark_overlay_btn').disabled = false;
82 $('show_in_catalog_btn').disabled = false;
83 obj.controller.view.mark_overlay.setAttribute('doc_id',o.getAttribute('doc_id'));
85 $('mark_overlay_btn').disabled = true;
86 $('show_in_catalog_btn').disabled = true;
88 return o.getAttribute('retrieve_id');
91 obj.error.sdump('D_TRACE','cat/z3950: selection list = ' + js2JSON(list) );
92 obj.controller.view.marc_import.disabled = false;
93 obj.controller.view.marc_import.setAttribute('retrieve_id',list[0]);
94 obj.data.init({'via':'stash'});
95 if (obj.data.marked_record) {
96 obj.controller.view.marc_import_overlay.disabled = false;
98 obj.controller.view.marc_import_overlay.disabled = true;
100 obj.controller.view.marc_import_overlay.setAttribute('retrieve_id',list[0]);
101 obj.controller.view.marc_view_btn.disabled = false;
102 obj.controller.view.marc_view_btn.setAttribute('retrieve_id',list[0]);
104 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_list_init.list_construction_error'),E);
110 JSAN.use('util.controller'); obj.controller = new util.controller();
114 'save_columns' : [ [ 'command' ], function() { obj.list.save_columns(); } ],
115 'sel_clip' : [ ['command'], function() { obj.list.clipboard(); } ],
116 'cmd_z3950_csv_to_clipboard' : [ ['command'], function() { obj.list.dump_csv_to_clipboard(); } ],
117 'cmd_z3950_csv_to_printer' : [ ['command'], function() { obj.list.dump_csv_to_printer(); } ],
118 'cmd_z3950_csv_to_file' : [ ['command'], function() { obj.list.dump_csv_to_file( { 'defaultFileName' : 'z3950_results.txt' } ); } ],
121 function() { alert('Not Yet Implemented'); }
123 'result_message' : [['render'],function(e){return function(){};}],
134 setTimeout( function() { obj.focus(); }, 0 );
140 e.setAttribute('label', $("catStrings").getString('staff.cat.z3950.marc_view.label'));
141 e.setAttribute('accesskey', $("catStrings").getString('staff.cat.z3950.marc_view.accesskey'));
148 var n = obj.controller.view.marc_view_btn;
149 if (n.getAttribute('toggle') == '1') {
150 document.getElementById('deck').selectedIndex = 0;
151 n.setAttribute('toggle','0');
152 n.setAttribute('label', $("catStrings").getString('staff.cat.z3950.marc_view.label'));
153 n.setAttribute('accesskey', $("catStrings").getString('staff.cat.z3950.marc_view.accesskey'));
154 document.getElementById('results').focus();
156 document.getElementById('deck').selectedIndex = 1;
157 n.setAttribute('toggle','1');
158 n.setAttribute('label', $("catStrings").getString('staff.cat.z3950.results_view.label'));
159 n.setAttribute('accesskey', $("catStrings").getString('staff.cat.z3950.results_view.accesskey'));
160 var f = get_contentWindow(document.getElementById('marc_frame'));
161 var retrieve_id = n.getAttribute('retrieve_id');
162 var result_idx = retrieve_id.split('-')[0];
163 var record_idx = retrieve_id.split('-')[1];
164 f.xulG = { 'marcxml' : obj.result_set[result_idx].records[ record_idx ].marcxml };
166 f.document.body.firstChild.focus();
169 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.marc_view_error'),E);
177 var doc_id = obj.controller.view.mark_overlay.getAttribute('doc_id');
179 cat.util.mark_for_overlay(doc_id);
182 alert('Error in z3950.js, mark_overlay: ' + E);
186 'show_in_catalog' : [
190 var doc_id = obj.controller.view.mark_overlay.getAttribute('doc_id');
192 var opac_url = xulG.url_prefix('opac_rdetail') + doc_id;
193 var content_params = {
195 'authtime' : ses('authtime'),
196 'opac_url' : opac_url,
199 xulG.url_prefix('XUL_OPAC_WRAPPER'),
200 {'tab_name': $("catStrings").getString('staff.cat.z3950.replace_tab_with_opac.tab_name')},
205 alert('Error in z3950.js, show_in_catalog: ' + E);
213 var retrieve_id = obj.controller.view.marc_import.getAttribute('retrieve_id');
214 var result_idx = retrieve_id.split('-')[0];
215 var record_idx = retrieve_id.split('-')[1];
216 obj.spawn_marc_editor(
217 obj.result_set[ result_idx ].records[ record_idx ].marcxml,
218 obj.result_set[ result_idx ].records[ record_idx ].service /* FIXME: we want biblio_source here */
221 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.marc_import_error'),E);
225 'marc_import_overlay' : [
229 var retrieve_id = obj.controller.view.marc_import_overlay.getAttribute('retrieve_id');
230 var result_idx = retrieve_id.split('-')[0];
231 var record_idx = retrieve_id.split('-')[1];
232 obj.spawn_marc_editor_for_overlay(
233 obj.result_set[ result_idx ].records[ record_idx ].marcxml,
234 obj.result_set[ result_idx ].records[ record_idx ].service /* FIXME: we want biblio_source here */
237 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.marc_import_overlay_error'),E);
244 obj.initial_search();
250 var raw = window.prompt(
251 $("catStrings").getString('staff.cat.z3950.initial_search.raw_prompt.msg'),
252 $("catStrings").getString('staff.cat.z3950.initial_search.raw_prompt.default_value'),
253 $("catStrings").getString('staff.cat.z3950.initial_search.raw_prompt.title')
255 if (raw) obj.initial_raw_search(raw);
264 'toggle_form_btn' : [
267 e.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
268 e.setAttribute('label',$("catStrings").getString('staff.cat.z3950.hide_top_pane.label'));
269 e.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.hide_top_pane.accesskey'));
275 var x = document.getElementById('top_pane');
276 document.getElementById('splitter_grippy2').doCommand();
277 var n = obj.controller.view.toggle_form_btn;
279 n.setAttribute('image',"/xul/server/skin/media/images/down_arrow.gif");
280 n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.label'));
281 n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.accesskey'));
283 n.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
284 n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.hide_top_pane.label'));
285 n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.hide_top_pane.accesskey'));
289 'splitter_grippy2' : [
292 var x = document.getElementById('top_pane');
293 var n = obj.controller.view.toggle_form_btn;
295 n.setAttribute('image',"/xul/server/skin/media/images/down_arrow.gif");
296 n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.label'));
297 n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.unhide_top_pane.accesskey'));
299 n.setAttribute('image',"/xul/server/skin/media/images/up_arrow.gif");
300 n.setAttribute('label',$("catStrings").getString('staff.cat.z3950.hide_top_pane.label'));
301 n.setAttribute('accesskey',$("catStrings").getString('staff.cat.z3950.hide_top_pane.accesskey'));
311 function handle_switch(node) {
313 $('search').setAttribute('disabled','true'); $('raw_search').setAttribute('disabled','true');
314 obj.active_services = [];
315 var snl = document.getElementsByAttribute('mytype','service_class');
316 for (var i = 0; i < snl.length; i++) {
318 if (n.nodeName == 'checkbox') {
319 if (n.checked) obj.active_services.push( n.getAttribute('service') );
322 if (obj.active_services.length > 0) {
323 $('search').setAttribute('disabled','false');
325 if (obj.active_services.length == 1) {
326 if (obj.active_services[0] != 'native-evergreen-catalog') {
327 $('raw_search').setAttribute('disabled','false');
330 var nl = document.getElementsByAttribute('mytype','search_class');
331 for (var i = 0; i < nl.length; i++) { nl[i].disabled = true; }
333 for (var j = 0; j < obj.active_services.length; j++) {
334 if (obj.services[obj.active_services[j]]) for (var i in obj.services[obj.active_services[j]].attrs) {
335 var attr = obj.services[obj.active_services[j]].attrs[i];
337 attrs[i] = { 'labels' : {} };
340 attrs[i].labels[ attr.label ] = true;
341 } else if (document.getElementById('commonStrings').testString('staff.z39_50.search_class.' + i)) {
342 attrs[i].labels[ document.getElementById('commonStrings').getString('staff.z39_50.search_class.' + i) ] = true;
343 } else if (attr.name) {
344 attrs[i].labels[ attr.name ] = true;
346 attrs[i].labels[ i ] = true;
353 function set_label(x,attr) {
355 for (var j in attrs[attr].labels) {
358 if (labels.length > 0) {
359 x.setAttribute('value',labels[0]);
360 x.setAttribute('tooltiptext',labels.join(','));
361 if (labels.length > 1) x.setAttribute('class','multiple_labels');
365 for (var i in attrs) {
366 var x = document.getElementById(i + '_input');
369 var y = document.getElementById(i + '_label',i);
370 if (y) set_label(y,i);
372 var rows = document.getElementById('query_inputs');
373 var row = document.createElement('row'); rows.appendChild(row);
374 var label = document.createElement('label');
375 label.setAttribute('id',i+'_label');
376 label.setAttribute('control',i+'_input');
377 label.setAttribute('search_class',i);
378 label.setAttribute('style','-moz-user-focus: ignore');
379 row.appendChild(label);
381 label.addEventListener('click',function(ev){
382 var a = ev.target.getAttribute('search_class');
383 if (a) obj.default_attr = a;
386 var tb = document.createElement('textbox');
387 tb.setAttribute('id',i+'_input');
388 tb.setAttribute('mytype','search_class');
389 tb.setAttribute('search_class',i);
391 tb.addEventListener('keypress',function(ev) { return obj.handle_enter(ev); },false);
395 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.search_fields_error'),E);
399 document.getElementById('native-evergreen-catalog_service').addEventListener('command',handle_switch,false);
401 var robj = obj.network.simple_request(
402 'RETRIEVE_Z3950_SERVICES',
405 if (typeof robj.ilsevent != 'undefined') throw(robj);
407 var x = document.getElementById('service_rows');
408 var services = new Array();
409 for (var i in obj.services) {
411 if (obj.services[i].label) {
412 label = obj.services[i].label;
413 } else if (obj.services[i].name) {
414 label = obj.services[i].name;
422 for (var j=0; j < services.length; j++) {
423 var i = services[j][1];
425 if (i == 'native-evergreen-catalog') continue;
426 var r = document.createElement('row'); x.appendChild(r);
427 var cb = document.createElement('checkbox');
428 cb.setAttribute('label',services[j][0]);
429 cb.setAttribute('tooltiptext',i + ' : ' + obj.services[i].db + '@' + obj.services[i].host + ':' + obj.services[i].port);
430 cb.setAttribute('mytype','service_class'); cb.setAttribute('service',i);
431 cb.setAttribute('id',i+'_service'); r.appendChild(cb);
432 cb.addEventListener('command',handle_switch,false);
433 var username = document.createElement('textbox'); username.setAttribute('id',i+'_username');
434 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);
435 r.appendChild(username);
436 if (typeof obj.services[i].auth != 'undefined') username.hidden = ! get_bool( obj.services[i].auth );
437 var password = document.createElement('textbox'); password.setAttribute('id',i+'_password');
438 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);
439 password.setAttribute('type','password'); r.appendChild(password);
440 if (typeof obj.services[i].auth != 'undefined') password.hidden = ! get_bool( obj.services[i].auth );
445 //obj.services[ 'native-evergreen-catalog' ] = { 'attrs' : { 'author' : {}, 'title' : {} } };
448 if (obj.creds.hosts[ obj.data.server_unadorned ]) {
449 for (var i = 0; i < obj.creds.hosts[ obj.data.server_unadorned ].default_services.length; i++) {
450 var x = document.getElementById(obj.creds.hosts[ obj.data.server_unadorned ].default_services[i]+'_service');
451 if (x) x.checked = true;
453 } else if (obj.creds.default_service) {
454 var x = document.getElementById(obj.creds.default_service+'_service');
455 if (x) x.checked = true;
461 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.obj_controller_init.z39_service_error'),E);
470 obj.controller.render();
472 setTimeout( function() { obj.focus(); }, 0 );
476 obj.data.init({'via':'stash'});
477 if (obj.data.marked_record) {
478 var sel = obj.list.retrieve_selection();
479 if (sel.length > 0) { obj.controller.view.marc_import_overlay.disabled = false; }
480 if ($("overlay_tcn_indicator")) {
481 if (obj.data.marked_record_mvr) {
482 $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.tcn.label',[obj.data.marked_record_mvr.tcn()]));
484 $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getFormattedString('staff.cat.z3950.marked_record_for_overlay_indicator.record_id.label',[obj.data.marked_record]));
488 obj.controller.view.marc_import_overlay.disabled = true;
489 if ($("overlay_tcn_indicator")) {
490 $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getString('staff.cat.z3950.marked_record_for_overlay_indicator.no_record.label'));
497 this.error.sdump('D_ERROR','cat.z3950.init: ' + E + '\n');
501 'focus' : function() {
503 var focus_me; var or_focus_me;
504 if (!obj.active_services) return;
505 for (var i = 0; i < obj.active_services.length; i++) {
506 if (obj.creds.hosts[ obj.data.server_unadorned ] && obj.creds.hosts[ obj.data.server_unadorned ].services[ obj.active_services[i] ]) {
507 var x = obj.creds.hosts[ obj.data.server_unadorned ].services[ obj.active_services[i] ].default_attr;
508 if (x) { focus_me = x; break; }
510 if (obj.services[ obj.active_services[i] ]) for (var i in obj.services[ obj.active_services[i] ].attr) { or_focus_me = i; }
512 if (! focus_me) focus_me = or_focus_me;
513 var xx = document.getElementById(focus_me+'_input'); if (xx) xx.focus();
516 'clear' : function() {
518 var nl = document.getElementsByAttribute('mytype','search_class');
519 for (var i = 0; i < nl.length; i++) { nl[i].value = ''; nl[i].setAttribute('value',''); }
523 'search_params' : {},
525 'initial_search' : function() {
529 obj.number_of_result_sets = 0;
530 obj.results_buffer = [];
533 JSAN.use('util.widgets');
534 util.widgets.remove_children( obj.controller.view.result_message );
535 var x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
536 if (obj.active_services.length < 1) {
537 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.no_search_selection')));
540 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.searching')));
541 obj.search_params = {}; obj.list.clear();
542 obj.controller.view.page_next.disabled = true;
543 obj.controller.view.cmd_z3950_csv_to_file.setAttribute('disabled','true');
544 obj.controller.view.cmd_z3950_csv_to_clipboard.setAttribute('disabled','true');
545 obj.controller.view.cmd_z3950_csv_to_printer.setAttribute('disabled','true');
547 obj.search_params.service_array = [];
548 obj.search_params.username_array = [];
549 obj.search_params.password_array = [];
550 for (var i = 0; i < obj.active_services.length; i++) {
551 obj.search_params.service_array.push( obj.active_services[i] );
552 obj.search_params.username_array.push( document.getElementById( obj.active_services[i]+'_username' ).value );
553 obj.search_params.password_array.push( document.getElementById( obj.active_services[i]+'_password' ).value );
555 obj.search_params.limit = obj.limit;
556 obj.search_params.offset = 0;
558 obj.search_params.search = {};
559 var nl = document.getElementsByAttribute('mytype','search_class');
561 for (var i = 0; i < nl.length; i++) {
562 if (nl[i].disabled) continue;
563 if (nl[i].value == '') continue;
565 obj.search_params.search[ nl[i].getAttribute('search_class') ] = nl[i].value;
570 util.widgets.remove_children( obj.controller.view.result_message );
573 this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.initial_search.failed_search'),E);
577 'initial_raw_search' : function(raw) {
581 obj.results_buffer = [];
584 obj.number_of_result_sets = 0;
585 JSAN.use('util.widgets');
586 util.widgets.remove_children( obj.controller.view.result_message );
587 var x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
588 if (obj.active_services.length < 1) {
589 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.no_search_selection')));
592 if (obj.active_services.length > 1) {
593 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.too_many_selections')));
596 if (obj.active_services[0] == 'native-evergreen-catalog') {
597 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.raw_search_unsupported_for_native_catalog')));
600 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.initial_search.searching')));
601 obj.search_params = {}; obj.list.clear();
602 obj.controller.view.page_next.disabled = true;
603 obj.controller.view.cmd_z3950_csv_to_file.setAttribute('disabled','true');
604 obj.controller.view.cmd_z3950_csv_to_clipboard.setAttribute('disabled','true');
605 obj.controller.view.cmd_z3950_csv_to_printer.setAttribute('disabled','true');
607 obj.search_params.service_array = [];
608 obj.search_params.username_array = [];
609 obj.search_params.password_array = [];
610 for (var i = 0; i < obj.active_services.length; i++) {
611 obj.search_params.service_array.push( obj.active_services[i] );
612 obj.search_params.username_array.push( document.getElementById( obj.active_services[i]+'_username' ).value );
613 obj.search_params.password_array.push( document.getElementById( obj.active_services[i]+'_password' ).value );
615 obj.search_params.limit = obj.limit;
616 obj.search_params.offset = 0;
618 obj.search_params.query = raw;
622 this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.initial_search.failed_search'),E);
626 'page_next' : function() {
629 JSAN.use('util.widgets');
630 util.widgets.remove_children( obj.controller.view.result_message );
631 var x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
632 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.page_next.more_results')));
633 obj.search_params.offset += obj.search_params.limit;
636 this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.page_next.subsequent_search_error'),E);
640 'search' : function() {
644 if (typeof obj.search_params.query == 'undefined') {
645 method = 'FM_BLOB_RETRIEVE_VIA_Z3950_SEARCH';
646 obj.search_params.service = obj.search_params.service_array;
647 obj.search_params.username = obj.search_params.username_array;
648 obj.search_params.password = obj.search_params.password_array;
650 method = 'FM_BLOB_RETRIEVE_VIA_Z3950_RAW_SEARCH';
651 obj.search_params.service = obj.search_params.service_array[0];
652 obj.search_params.username = obj.search_params.username_array[0];
653 obj.search_params.password = obj.search_params.password_array[0];
655 obj.network.simple_request(
657 [ ses(), obj.search_params ],
659 obj.handle_results(req.getResultObject())
662 document.getElementById('deck').selectedIndex = 0;
664 this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.search.search_error'),E);
668 'handle_results' : function(results) {
671 JSAN.use('util.widgets');
672 util.widgets.remove_children( obj.controller.view.result_message ); var x;
673 if (results == null) {
674 x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
675 x.appendChild( document.createTextNode($("catStrings").getString('staff.cat.z3950.handle_results.null_server_error')));
678 if (typeof results.ilsevent != 'undefined') {
679 x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
680 x.appendChild( document.createTextNode($("catStrings").getFormattedString('staff.cat.z3950.handle_results.server_error', [results.textcode, results.desc])));
683 obj.controller.view.cmd_z3950_csv_to_file.setAttribute('disabled','false');
684 obj.controller.view.cmd_z3950_csv_to_clipboard.setAttribute('disabled','false');
685 obj.controller.view.cmd_z3950_csv_to_printer.setAttribute('disabled','false');
686 if (typeof results.length == 'undefined') results = [ results ];
688 var total_showing = 0; // On screen
689 var total_count = 0; // available if you want 'em
690 var tooltip_msg = ''; // Tooltip for message under "Results"
691 var set_tally = []; // Keeps track of records per data source
693 /* Pass 1: Move results into FIFO buffers */
694 for (var i = 0; i < results.length; i++) {
695 if (typeof obj.save_count[i] == 'undefined') {
696 obj.save_count[i] = results[i].count; // We'll need this later
698 if (typeof obj.results_buffer[i] == 'undefined') {
699 obj.results_buffer[i] = new Array();
701 while (results[i].records.length) {
702 obj.results_buffer[i].push(results[i].records.pop());
705 /* Set up array that keeps track of # of recs in the buffer */
708 buff_info.ele_count = obj.results_buffer[i].length;
709 set_tally.push(buff_info);
712 /* Pass 2: figure out optimal fill from buffers to result frame and move them */
713 var sorted_tally = set_tally.sort( function(e1, e2) {
714 return e1.ele_count - e2.ele_count;
718 var available = obj.limit; // Slots to fill in this batch
719 for (i = 0; i < sorted_tally.length; i++) {
720 var use_count = Math.floor(available / (sorted_tally.length-i));
721 var res_index = sorted_tally[i].indx;
723 /* Don't use more records than we have */
724 if (sorted_tally[i].ele_count < use_count) {
725 use_count = sorted_tally[i].ele_count;
728 results[res_index].count = use_count > 0 ?
729 obj.save_count[res_index] :
732 available = available - use_count;
734 results[res_index].records.push(
735 obj.results_buffer[res_index].shift()
741 /* Pass 3: Process the records from the results array */
742 for (i = 0; i < results.length; i++) {
743 if (results[i].query) {
744 tooltip_msg += $("catStrings").getFormattedString('staff.cat.z3950.handle_results.raw_query', [results[i].query]) + '\n';
746 if (typeof obj.on_display[i] == 'undefined') {
747 obj.on_display[i] = 0;
749 if (results[i].count) {
750 if (results[i].records) {
751 obj.on_display[i] += results[i].records.length;
752 total_showing += obj.on_display[i];
753 total_count += results[i].count;
754 tooltip_msg += $("catStrings").getFormattedString('staff.cat.z3950.handle_results.showing_results', [obj.on_display[i], results[i].count, results[i].service]) + '\n';
757 total_showing += obj.on_display[i];
758 total_count += obj.on_display[i];
759 tooltip_msg += $("catStrings").getFormattedString('staff.cat.z3950.handle_results.showing_results', [obj.on_display[i], obj.on_display[i], results[i].service]) + '\n';
763 if (results[i].records) {
764 obj.result_set[ ++obj.number_of_result_sets ] = results[i];
765 obj.controller.view.marc_import.disabled = true;
766 obj.controller.view.marc_import_overlay.disabled = true;
767 var x = obj.controller.view.marc_view_btn;
768 if (x.getAttribute('toggle') == '0') x.disabled = true;
769 for (var j = 0; j < obj.result_set[ obj.number_of_result_sets ].records.length; j++) {
771 var n = obj.list.append(
773 'retrieve_id' : String( obj.number_of_result_sets ) + '-' + String( j ),
778 // We have col definitions, etc.
780 a.mvr.doc_id( a.bibid );
783 }(obj.result_set[ obj.number_of_result_sets ].records[j]),
784 'service' : results[i].service
789 n.treeitem_node.setAttribute('isbn', function(a){return a;}(obj.result_set[ obj.number_of_result_sets ].records[j].mvr).isbn());
790 n.treeitem_node.setAttribute(
792 function(a){return a;}(
796 n.treeitem_node.setAttribute(
798 function(a){return a;}(
799 (obj.result_set[ obj.number_of_result_sets ].records[j].mvr)
803 if (!f) { n.treeitem_node.parentNode.focus(); f = n; }
806 x = document.createElement('description'); obj.controller.view.result_message.appendChild(x);
808 document.createTextNode($("catStrings").getString('staff.cat.z3950.handle_results.result_error'))
813 obj.controller.view.page_next.disabled = total_showing >= total_count;
815 x = document.createElement('description');
816 x.setAttribute('crop','end');
817 x.setAttribute('tooltiptext',tooltip_msg);
818 obj.controller.view.result_message.appendChild(x);
820 document.createTextNode($("catStrings").getFormattedString('staff.cat.z3950.handle_results.showing_total_results',
821 [(total_showing > total_count ? total_count : total_showing), total_count]))
824 x = document.createElement('description');
825 x.setAttribute('crop','end');
826 x.setAttribute('tooltiptext',tooltip_msg);
827 obj.controller.view.result_message.appendChild(x);
829 document.createTextNode($("catStrings").getFormattedString('staff.cat.z3950.handle_results.num_of_results', [(total_count ? total_count : 0)]))
834 this.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.handle_results.search_result_error'),E);
838 'replace_tab_with_opac' : function(doc_id) {
839 var opac_url = xulG.url_prefix('opac_rdetail') + doc_id;
840 var content_params = {
842 'authtime' : ses('authtime'),
843 'opac_url' : opac_url,
846 xulG.url_prefix('XUL_OPAC_WRAPPER'),
847 {'tab_name': $("catStrings").getString('staff.cat.z3950.replace_tab_with_opac.tab_name')},
852 'spawn_marc_editor' : function(my_marcxml,biblio_source) {
855 function save_marc (new_marcxml) {
858 // extract the import strip groups
859 var strip_grps = dojo.query('[strip-fields-cbox]').filter(
860 function(grp) { return grp.checked }).map(
861 function(grp) { return grp.getAttribute('value') });
863 var r = obj.network.simple_request(
864 'MARC_XML_RECORD_IMPORT', [
865 ses(), new_marcxml, biblio_source,
866 null, null, strip_grps
870 if (typeof r.ilsevent != 'undefined') {
871 switch(Number(r.ilsevent)) {
872 case 1704 /* TCN_EXISTS */ :
873 var msg = $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor.same_tcn', [r.payload.tcn]);
874 var title = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.title');
875 var btn1 = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.btn1_overlay');
876 var btn2 = typeof r.payload.new_tcn == 'undefined' ? null : $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor.btn2_import', [r.payload.new_tcn]);
878 obj.data.init({'via':'stash'});
879 var robj = obj.network.simple_request(
882 obj.data.list.au[0].id(),
883 obj.data.list.au[0].ws_ou(),
887 if (typeof robj.ilsevent != 'undefined') {
888 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.permission_error'),E);
890 if (robj.length != 0) btn2 = null;
892 var btn3 = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.btn3_cancel_import');
893 var p = obj.error.yns_alert(msg,title,btn1,btn2,btn3,$("catStrings").getString('staff.cat.z3950.spawn_marc_editor.confirm_action'));
894 obj.error.sdump('D_ERROR','option ' + p + 'chosen');
897 var r3 = obj.network.simple_request('MARC_XML_RECORD_UPDATE', [
898 ses(), r.payload.dup_record,
899 new_marcxml, biblio_source, null, strip_grps
901 if (typeof r3.ilsevent != 'undefined') {
904 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.successful_overlay'));
907 'on_complete' : function() {
909 obj.replace_tab_with_opac(r3.id());
918 var r2 = obj.network.request(
919 api.MARC_XML_RECORD_IMPORT.app,
920 api.MARC_XML_RECORD_IMPORT.method + '.override',
921 [ ses(), new_marcxml, biblio_source, null, null, strip_grps ]
923 if (typeof r2.ilsevent != 'undefined') {
926 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.successful_import_with_new_tcn'));
929 'on_complete' : function() {
931 obj.replace_tab_with_opac(r2.id());
941 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.import_cancelled'));
950 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.successful_import'));
953 'on_complete' : function() {
955 obj.replace_tab_with_opac(r.id());
963 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor.import_error'),E);
967 if ( $('marc_editor').checked ) {
969 xulG.url_prefix('XUL_MARC_EDIT'),
970 { 'tab_name' : 'MARC Editor' },
972 'marc_control_number_identifier': obj.data.hash.aous['cat.marc_control_number_identifier'] || 'Set cat.marc_control_number_identifier in Library Settings',
973 'record' : { 'marc' : my_marcxml, "rtype": "bre" },
974 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
976 JSAN.use('cat.util'); return cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
982 'label' : $("catStrings").getString('staff.cat.z3950.spawn_marc_editor.save_button_label'),
985 'lock_tab' : xulG.lock_tab,
986 'unlock_tab' : xulG.unlock_tab
990 save_marc(my_marcxml);
994 'confirm_overlay' : function(record_ids) {
995 var obj = this; // JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
996 var top_xml = '<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" flex="1" >';
997 top_xml += '<description>'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.description')+'</description>';
998 top_xml += '<hbox><button id="lead" disabled="false" label="'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.lead.label')+'" name="fancy_submit"';
999 top_xml += ' accesskey="'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.lead.accesskey')+'"/>';
1000 top_xml += ' <button label="'+$("catStrings").getString('staff.cat.z3950.confirm_overlay.cancel.label')+'" accesskey="'+
1001 $("catStrings").getString('staff.cat.z3950.confirm_overlay.cancel.accesskey')+'" name="fancy_cancel"/></hbox></vbox>';
1003 var xml = '<form xmlns="http://www.w3.org/1999/xhtml">';
1004 xml += '<table width="100%"><tr valign="top">';
1005 for (var i = 0; i < record_ids.length; i++) {
1006 xml += '<td nowrap="nowrap"><iframe src="' + urls.XUL_BIB_BRIEF;
1007 xml += '?docid=' + record_ids[i] + '" oils_force_external="true"/></td>';
1009 xml += '</tr><tr valign="top">';
1010 for (var i = 0; i < record_ids.length; i++) {
1011 xml += '<td nowrap="nowrap"><iframe style="min-height: 1000px; min-width: 300px;" flex="1" src="' + urls.XUL_MARC_VIEW + '?docid=' + record_ids[i] + ' " oils_force_external="true"/></td>';
1013 xml += '</tr></table></form>';
1014 // data.temp_merge_top = top_xml; data.stash('temp_merge_top');
1015 // data.temp_merge_mid = xml; data.stash('temp_merge_mid');
1016 JSAN.use('util.window'); var win = new util.window();
1017 var fancy_prompt_data = win.open(
1018 urls.XUL_FANCY_PROMPT,
1019 'fancy_prompt', 'chrome,resizable,modal,width=700,height=500',
1020 { 'top_xml' : top_xml, 'xml' : xml, 'title' : $("catStrings").getString('staff.cat.z3950.confirm_overlay.title') }
1022 //data.stash_retrieve();
1023 if (fancy_prompt_data.fancy_status == 'incomplete') { alert($("catStrings").getString('staff.cat.z3950.confirm_overlay.aborted')); return false; }
1027 'spawn_marc_editor_for_overlay' : function(my_marcxml,biblio_source) {
1029 obj.data.init({'via':'stash'});
1030 if (!obj.data.marked_record) {
1031 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.try_again'));
1035 function overlay_marc (new_marcxml) {
1037 if (! obj.confirm_overlay( [ obj.data.marked_record ] ) ) { return; }
1039 var strip_grps = dojo.query('[strip-fields-cbox]').filter(
1040 function(grp) { return grp.checked }).map(
1041 function(grp) { return grp.getAttribute('value') });
1043 var r = obj.network.simple_request('MARC_XML_RECORD_REPLACE',
1044 [ ses(), obj.data.marked_record, new_marcxml, biblio_source, null, strip_grps ]);
1046 if (typeof r.ilsevent != 'undefined') {
1047 switch(Number(r.ilsevent)) {
1048 case 1704 /* TCN_EXISTS */ :
1049 var msg = $("catStrings").getFormattedString('staff.cat.z3950.spawn_marc_editor_for_overlay.same_tcn', [r.payload.tcn]);
1050 var title = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.import_collision');
1051 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]);
1053 var robj = obj.network.simple_request(
1056 obj.data.list.au[0].id(),
1057 obj.data.list.au[0].ws_ou(),
1061 if (typeof robj.ilsevent != 'undefined') {
1062 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.permission_error'),E);
1064 if (robj.length != 0) btn1 = null;
1066 var btn2 = $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.btn2_cancel');
1067 var p = obj.error.yns_alert(msg,title,btn1,btn2,null, $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.confirm_action'));
1068 obj.error.sdump('D_ERROR','option ' + p + 'chosen');
1071 var r2 = obj.network.request(
1072 api.MARC_XML_RECORD_REPLACE.app,
1073 api.MARC_XML_RECORD_REPLACE.method + '.override',
1074 [ ses(), obj.data.marked_record, new_marcxml,
1075 biblio_source, null, strip_grps ]
1077 if (typeof r2.ilsevent != 'undefined') {
1080 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.successful_overlay_with_new_TCN'));
1083 'on_complete' : function() {
1085 obj.replace_tab_with_opac(r2.id());
1095 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.cancelled_overlay'));
1104 alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.success_overlay'));
1106 obj.data.marked_record_mvr = null;
1107 obj.data.marked_record = null;
1108 obj.data.stash('marked_record');
1109 obj.data.stash('marked_record_mvr');
1110 obj.controller.view.marc_import_overlay.disabled = true;
1111 if ($("overlay_tcn_indicator")) {
1112 $("overlay_tcn_indicator").setAttribute('value',$("catStrings").getString('staff.cat.z3950.marked_record_for_overlay_indicator.no_record.label'));
1114 xulG.set_statusbar(1, $("catStrings").getString('staff.cat.z3950.marked_record_for_overlay_indicator.no_record.label') );
1116 dump('Error in z3950.js, post-overlay: ' + E + '\n');
1120 'on_complete' : function() {
1122 obj.replace_tab_with_opac(r.id());
1130 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.overlay_error'),E);
1134 if ( $('marc_editor').checked ) {
1136 xulG.url_prefix('XUL_MARC_EDIT'),
1137 { 'tab_name' : $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.tab_name') },
1139 'record' : { 'marc' : my_marcxml },
1140 'fast_add_item' : function(doc_id,cn_label,cp_barcode) {
1142 JSAN.use('cat.util'); cat.util.fast_item_add(doc_id,cn_label,cp_barcode);
1148 'label' : $("catStrings").getString('staff.cat.z3950.spawn_marc_editor_for_overlay.overlay_record_label'),
1149 'func' : overlay_marc
1154 overlay_marc(my_marcxml);
1159 'load_creds' : function() {
1162 obj.creds = { 'version' : g.save_version, 'services' : {}, 'hosts' : {} };
1166 'default_service' : xx,
1172 'default_attr' : xx,
1178 'default_attr' : xx,
1184 'default_services' : [ xx, ... ],
1190 'default_attr' : xx,
1196 'default_attr' : xx,
1203 JSAN.use('util.file'); var file = new util.file('z3950_store');
1204 if (file._file.exists()) {
1205 var creds = file.get_object(); file.close();
1206 if (typeof creds.version != 'undefined') {
1207 if (creds.version >= obj.creds_version) { /* so apparently, this guy is assuming that future versions will be backwards compatible */
1208 if (typeof creds.hosts == 'undefined') creds.hosts = {};
1214 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.load_creds.z3950_cred_error'),E);
1218 'save_creds' : function () {
1221 if (typeof obj.creds.hosts == 'undefined') obj.creds.hosts = {};
1222 if (typeof obj.creds.hosts[ obj.data.server_unadorned ] == 'undefined') obj.creds.hosts[ obj.data.server_unadorned ] = { 'services' : {} };
1223 obj.creds.hosts[ obj.data.server_unadorned ].default_services = obj.active_services;
1224 for (var i = 0; i < obj.creds.hosts[ obj.data.server_unadorned ].default_services.length; i++) {
1225 var service = obj.creds.hosts[ obj.data.server_unadorned ].default_services[i];
1226 if (typeof obj.creds.hosts[ obj.data.server_unadorned ].services[ service ] == 'undefined') {
1227 obj.creds.hosts[ obj.data.server_unadorned ].services[ service ] = {}
1229 obj.creds.hosts[ obj.data.server_unadorned ].services[service].username = document.getElementById(service + '_username').value;
1230 obj.creds.hosts[ obj.data.server_unadorned ].services[service].password = document.getElementById(service + '_password').value;
1231 if (obj.default_attr) {
1232 obj.creds.hosts[ obj.data.server_unadorned ].services[service].default_attr = obj.default_attr;
1235 obj.creds.version = obj.creds_version;
1236 JSAN.use('util.file'); var file = new util.file('z3950_store');
1237 file.set_object(obj.creds);
1240 obj.error.standard_unexpected_error_alert($("catStrings").getString('staff.cat.z3950.save_creds.z3950_cred_error'),E);
1244 'handle_enter' : function(ev) {
1246 if (ev.target.tagName != 'textbox') return;
1247 if (ev.keyCode == 13 /* enter */ || ev.keyCode == 77 /* enter on a mac */) setTimeout( function() { obj.initial_search(); }, 0);
1251 function buildStripTags() {
1253 // give me every non-always-apply trash field
1254 // group owned at my workstation or ancestor,
1260 transform : 'actor.org_unit_ancestors',
1264 where : {id : ses('ws_ou')}}
1268 fieldmapper.standardRequest(
1269 ['open-ils.pcrud', 'open-ils.pcrud.search.vibtg.atomic'],
1271 params : [ses(), query, {order_by : {vibtg : ['label']}}],
1272 oncomplete : function(r) {
1273 var resp = r.recv();
1274 if (resp) buildStripTags2(resp.content());
1280 function buildStripTags2(grps) {
1281 if (!grps || grps.length == 0) return;
1283 $('strip-fields-hbox').className = '';
1285 dojo.forEach(grps, function(grp) {
1286 var cbox = dojo.create('checkbox', {
1287 label : grp.label(),
1289 'strip-fields-cbox' : 1
1291 dojo.place(cbox, $('strip-fields-hbox'));
1296 dump('exiting cat.z3950.js\n');