From 0a4887bd20f1738f5ae1ae8eca15df82027cc0c3 Mon Sep 17 00:00:00 2001 From: dbs Date: Mon, 30 Aug 2010 22:01:10 +0000 Subject: [PATCH] Add a bib_source editor widget to the MARC editor This widget should only be exposed when editing bibliographic MARC records. The existing restriction of not being able to set the bib source when importing via Z39.50 sadly remains in place; I believe the best place to tackle that will be in the Z39.50 import interface itself. Also TODO: i18n git-svn-id: svn://svn.open-ils.org/ILS/trunk@17393 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/web/js/ui/default/cat/authority/list.js | 2 +- Open-ILS/web/opac/skin/craftsman/js/rdetail.js | 2 +- Open-ILS/web/opac/skin/default/js/rdetail.js | 2 +- .../xul/staff_client/chrome/content/cat/opac.js | 2 +- Open-ILS/xul/staff_client/server/cat/marcedit.js | 94 ++++++++++++++++++++++ Open-ILS/xul/staff_client/server/cat/marcedit.xul | 6 ++ Open-ILS/xul/staff_client/server/cat/z3950.js | 2 +- 7 files changed, 105 insertions(+), 5 deletions(-) diff --git a/Open-ILS/web/js/ui/default/cat/authority/list.js b/Open-ILS/web/js/ui/default/cat/authority/list.js index dc55a1fc3..b719ecc08 100644 --- a/Open-ILS/web/js/ui/default/cat/authority/list.js +++ b/Open-ILS/web/js/ui/default/cat/authority/list.js @@ -148,7 +148,7 @@ function loadMarcEditor(pcrud, rec) { win = window.open('/xul/server/cat/marcedit.xul'); // XXX version? win.xulG = { - "record": {"marc": rec.marc()}, + "record": {"marc": rec.marc(), "rtype": "are"}, "save": { "label": "Save", "func": function(xmlString) { diff --git a/Open-ILS/web/opac/skin/craftsman/js/rdetail.js b/Open-ILS/web/opac/skin/craftsman/js/rdetail.js index b6272895a..d7da5c6b2 100644 --- a/Open-ILS/web/opac/skin/craftsman/js/rdetail.js +++ b/Open-ILS/web/opac/skin/craftsman/js/rdetail.js @@ -238,7 +238,7 @@ function OpenMarcEditWindow(pcrud, rec) { dojo.require('openils.PermaCrud'); win.xulG = { - "record": {"marc": rec.marc()}, + "record": {"marc": rec.marc(), "rtype": "sre"}, "save": { "label": opac_strings.SAVE_MFHD_LABEL, "func": function(xmlString) { diff --git a/Open-ILS/web/opac/skin/default/js/rdetail.js b/Open-ILS/web/opac/skin/default/js/rdetail.js index 1221a26f8..dc5cac361 100644 --- a/Open-ILS/web/opac/skin/default/js/rdetail.js +++ b/Open-ILS/web/opac/skin/default/js/rdetail.js @@ -241,7 +241,7 @@ function OpenMarcEditWindow(pcrud, rec) { dojo.require('openils.PermaCrud'); win.xulG = { - "record": {"marc": rec.marc()}, + "record": {"marc": rec.marc(), "rtype": "sre"}, "save": { "label": opac_strings.SAVE_MFHD_LABEL, "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 e07584b86..45b340403 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 edfe1fff6..1beb0c199 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); } @@ -2303,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 1c91a6c5f..23aa10536 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 @@ + + + Bibliographic source + +