From 4bb9692dd601bba2bff5d942343c008a28b4fbb4 Mon Sep 17 00:00:00 2001 From: dbs Date: Thu, 2 Sep 2010 03:06:33 +0000 Subject: [PATCH] Backport biblio source enhancements from trunk: * Make biblio source selection in Vandelay set the source for imported bib records. * Place a biblio source editor widget on the MARC Editor when invoked with a biblio record that already exists in the database ("rtype": "bre" with a specific ID). git-svn-id: svn://svn.open-ils.org/ILS/branches/rel_2_0@17435 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../perlmods/OpenILS/Application/Cat/BibCommon.pm | 3 + .../src/perlmods/OpenILS/Application/Vandelay.pm | 11 +- Open-ILS/web/js/ui/default/acq/common/li_table.js | 2 +- Open-ILS/web/js/ui/default/vandelay/vandelay.js | 9 +- .../xul/staff_client/chrome/content/cat/opac.js | 2 +- Open-ILS/xul/staff_client/server/cat/marcedit.js | 116 +++++++++++++++++++-- Open-ILS/xul/staff_client/server/cat/marcedit.xul | 6 ++ Open-ILS/xul/staff_client/server/cat/z3950.js | 2 +- 8 files changed, 138 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm b/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm index 4769f095b7..4d928a86a3 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Cat/BibCommon.pm @@ -89,6 +89,9 @@ sub biblio_record_xml_import { return $evt if $evt; } + # Silence warnings when _find_tcn_info() fails + $tcn ||= ''; + $tcn_source ||= ''; $logger->info("user ".$e->requestor->id. " creating new biblio entry with tcn=$tcn and tcn_source $tcn_source"); diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm index f39cb5f82f..da3dca6b0a 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Vandelay.pm @@ -44,6 +44,7 @@ my %record_types = ( x => 'holdings', y => 'holdings', z => 'auth', + ' ' => 'bib', ); sub initialize {} @@ -624,6 +625,13 @@ sub import_record_list_impl { my $update_queue_func = 'update_vandelay_bib_queue'; my $rec_class = 'vqbr'; + my %bib_sources; + my $editor = new_editor(); + my $sources = $editor->search_config_bib_source({id => {'!=' => undef}}); + foreach my $src (@$sources) { + $bib_sources{$src->id} = $src->source; + } + if($type eq 'auth') { $overlay_func =~ s/bib/auth/o; $auto_overlay_func = s/bib/auth/o; @@ -737,8 +745,7 @@ sub import_record_list_impl { # No overlay / merge occurred. Do a traditional record import by creating a new record if($type eq 'bib') { - $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc); #$rec->bib_source - + $record = OpenILS::Application::Cat::BibCommon->biblio_record_xml_import($e, $rec->marc, $bib_sources{$rec->bib_source}); } else { $record = OpenILS::Application::Cat::AuthCommon->import_authority_record($e, $rec->marc); #$source); diff --git a/Open-ILS/web/js/ui/default/acq/common/li_table.js b/Open-ILS/web/js/ui/default/acq/common/li_table.js index 00ae185bf0..52e672cdc1 100644 --- a/Open-ILS/web/js/ui/default/acq/common/li_table.js +++ b/Open-ILS/web/js/ui/default/acq/common/li_table.js @@ -2308,7 +2308,7 @@ function AcqLiTable() { } var self = this; win.xulG = { - record : {marc : li.marc()}, + record : {marc : li.marc(), "rtype": "bre"}, save : { label: 'Save Record', // XXX I18N func: function(xmlString) { diff --git a/Open-ILS/web/js/ui/default/vandelay/vandelay.js b/Open-ILS/web/js/ui/default/vandelay/vandelay.js index 61d0485024..d5828ed425 100644 --- a/Open-ILS/web/js/ui/default/vandelay/vandelay.js +++ b/Open-ILS/web/js/ui/default/vandelay/vandelay.js @@ -1055,6 +1055,13 @@ function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) { netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); win = window.open('/xul/server/cat/marcedit.xul'); // XXX version? + var type; + if (currentType == 'bib') { + type = 'bre'; + } else { + type = 'are'; + } + function onsave(r) { // after the record is saved, reload the HTML display var stat = r.recv().content(); @@ -1066,7 +1073,7 @@ function vlOpenMarcEditWindow(rec, postReloadHTMLHandler) { } win.xulG = { - record : {marc : rec.marc()}, + record : {marc : rec.marc(), "rtype": type}, save : { label: dojo.byId('vl-marc-edit-save-label').innerHTML, func: function(xmlString) { diff --git a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js index e07584b86e..45b3404032 100644 --- a/Open-ILS/xul/staff_client/chrome/content/cat/opac.js +++ b/Open-ILS/xul/staff_client/chrome/content/cat/opac.js @@ -121,7 +121,7 @@ function set_marc_edit() { var a = xulG.url_prefix( urls.XUL_MARC_EDIT ); var b = {}; var c = { - 'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid }, + 'record' : { 'url' : '/opac/extras/supercat/retrieve/marcxml/record/' + docid, "id": docid, "rtype": "bre" }, 'fast_add_item' : function(doc_id,cn_label,cp_barcode) { try { var cat = { util: {} }; /* FIXME: kludge since we can't load remote JSAN libraries into chrome */ diff --git a/Open-ILS/xul/staff_client/server/cat/marcedit.js b/Open-ILS/xul/staff_client/server/cat/marcedit.js index 90435c9e7d..1beb0c199a 100644 --- a/Open-ILS/xul/staff_client/server/cat/marcedit.js +++ b/Open-ILS/xul/staff_client/server/cat/marcedit.js @@ -140,11 +140,30 @@ function my_init() { var cgi = new CGI(); var _rid = cgi.param('record'); if (_rid) { + window.xulG.record.id = _rid; window.xulG.record.url = '/opac/extras/supercat/retrieve/marcxml/record/' + _rid; } } + // End faking part... + /* Check for an explicitly passed record type + * This is not the same as the fixed-field record type; we can't trust + * the fixed fields when making modifications to the attributes for a + * given record (in particular, config.bib_source only applies for bib + * records, but an auth or MFHD record with the same ID and bad fixed + * fields could trample the config.bib_source value for the + * corresponding bib record if we're not careful. + * + * are = authority record + * sre = serial record (MFHD) + * bre = bibliographic record + */ + if (!window.xulG.record.rtype) { + var cgi = new CGI(); + window.xulG.record.rtype = cgi.param('rtype') || false; + } + document.getElementById('save-button').setAttribute('label', window.xulG.save.label); document.getElementById('save-button').setAttribute('oncommand', 'if ($("xul-editor").hidden) swap_editors(); ' + @@ -288,6 +307,19 @@ function my_init() { } document.getElementById('fastItemAdd_textboxes').hidden = document.getElementById('fastItemAdd_checkbox').hidden || !document.getElementById('fastItemAdd_checkbox').checked; + // Only show bib sources for bib records that already exist in the database + if (xulG.record.rtype == 'bre' && xulG.record.id) { + dojo.require('openils.PermaCrud'); + var authtoken = ses(); + // Retrieve the current record attributes + var bib = new openils.PermaCrud({"authtoken": authtoken}).retrieve('bre', xulG.record.id); + + // Remember the current bib source of the record + xulG.record.bre = bib; + + buildBibSourceList(authtoken, xulG.record.id); + } + } catch(E) { alert('FIXME, MARC Editor, my_init: ' + E); } @@ -1865,11 +1897,19 @@ function getAuthorityContextMenu (target, sf) { var fields = xml.datafield; for (var j in fields) { + /* Restrict options to Heading Information fields (1xx) + * and See Also From fields (5xx) rather than displaying + * every field in the authority record */ + var tag = fields[j].@tag; + if (tag.substr(0,1) != 1 && tag.substr(0,1) != 5) { + continue; + } + var row = createRow( {}, - createLabel( { value : fields[j].@tag } ), - createLabel( { value : fields[j].@ind1 } ), - createLabel( { value : fields[j].@ind2 } ) + createLabel( { "value" : tag } ), + createLabel( { "value" : fields[j].@ind1 } ), + createLabel( { "value" : fields[j].@ind2 } ) ); var sf_box = createHbox(); @@ -1878,10 +1918,10 @@ function getAuthorityContextMenu (target, sf) { for (var k in subfields) { sf_box.appendChild( createCheckbox( - { label : '\u2021' + subfields[k].@code + ' ' + subfields[k], - subfield : subfields[k].@code, - tag : subfields[k].parent().@tag, - value : subfields[k] + { "label" : '\u2021' + subfields[k].@code + ' ' + subfields[k], + "subfield" : subfields[k].@code, + "tag" : subfields[k].parent().@tag, + "value" : subfields[k] } ) ); @@ -2295,3 +2335,65 @@ function searchAuthority (term, tag, sf, limit) { } +function buildBibSourceList (authtoken, recId) { + /* TODO: Work out how to set the bib source of the bre that does not yet + * exist - this is specifically in the case of Z39.50 imports. Right now + * we just avoid populating and showing the config.bib_source list + */ + if (!recId) { + return false; + } + + var bib = xulG.record.bre; + + dojo.require('openils.PermaCrud'); + + // cbsList = the XUL menulist that contains the available bib sources + var cbsList = dojo.byId('bib-source-list'); + + // bibSources = an array containing all of the bib source objects + var bibSources = new openils.PermaCrud({"authtoken": authtoken}).retrieveAll('cbs'); + + // A tad ugly, but gives us the index of the bib source ID in cbsList + var x = 0; + var cbsListArr = []; + dojo.forEach(bibSources, function (item) { + cbsList.appendItem(item.source(), item.id()); + cbsListArr[item.id()] = x; + x++; + }); + + // Show the current value of the bib source for this record + cbsList.selectedIndex = cbsListArr[bib.source()]; + + // Display the bib source selection widget + dojo.byId('bib-source-list-caption').hidden = false; + dojo.byId('bib-source-list').hidden = false; + dojo.byId('bib-source-list-button').disabled = true; + dojo.byId('bib-source-list-button').hidden = false; +} + +// Fired when the "Update Source" button is clicked +// Updates the value of the bib source for the current record +function updateBibSource() { + var authtoken = ses(); + var cbs = dojo.byId('bib-source-list').selectedItem.value; + var recId = xulG.record.id; + var pcrud = new openils.PermaCrud({"authtoken": authtoken}); + var bib = pcrud.retrieve('bre', recId); + if (bib.source() != cbs) { + bib.source(cbs); + bib.ischanged = true; + pcrud.update(bib); + } +} + +function onBibSourceSelect() { + var cbs = dojo.byId('bib-source-list').selectedItem.value; + var bib = xulG.record.bre; + if (bib.source() != cbs) { + dojo.byId('bib-source-list-button').disabled = false; + } else { + dojo.byId('bib-source-list-button').disabled = true; + } +} diff --git a/Open-ILS/xul/staff_client/server/cat/marcedit.xul b/Open-ILS/xul/staff_client/server/cat/marcedit.xul index 1c91a6c5f5..83d8a5e50d 100644 --- a/Open-ILS/xul/staff_client/server/cat/marcedit.xul +++ b/Open-ILS/xul/staff_client/server/cat/marcedit.xul @@ -236,6 +236,12 @@ + + + &staff.cat.marcedit.source.caption; + +