From: Lebbeous Fogle-Weekley Date: Wed, 29 Jun 2011 19:45:40 +0000 (-0400) Subject: Finally starting to get somewhere: record display X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bbefc2e9ef49dfe0cecbff3f5afb5d99d057291c;p=evergreen%2Fpines.git Finally starting to get somewhere: record display Record display kind of works. Need paging and links to bibs. Signed-off-by: Lebbeous Fogle-Weekley --- diff --git a/Open-ILS/web/js/dojo/MARC/Record.js b/Open-ILS/web/js/dojo/MARC/Record.js index 8bb6a1b8cb..861f200a3f 100644 --- a/Open-ILS/web/js/dojo/MARC/Record.js +++ b/Open-ILS/web/js/dojo/MARC/Record.js @@ -65,7 +65,10 @@ if(!dojo._hasResource["MARC.Record"]) { subfield : function (spec, code) { var f = this.field(spec); - if (dojo.isArray(f)) f = f[0]; + if (dojo.isArray(f)) { + if (!f.length) return f; + f = f[0]; + } return f.subfield(code) }, diff --git a/Open-ILS/web/opac/skin/default/css/layout.css b/Open-ILS/web/opac/skin/default/css/layout.css index 1197a742de..7aaed35b28 100644 --- a/Open-ILS/web/opac/skin/default/css/layout.css +++ b/Open-ILS/web/opac/skin/default/css/layout.css @@ -74,6 +74,11 @@ table { border-collapse: collapse; } /* ---------------------------------------------------------------------- */ +table.authority-record { width: 48em; background-color: #ddd; margin: 1em; } +td.authority-record-right { width: 24em; } +td.authority-record-main { font-weight: bold; } +td.authority-tag-label { font-style: italic; } + #searchbar { margin-top: 22px; width: 100%; } #searchbar table tr td {font-weight: bold; font-size: 8pt; } #searchbar select, input { border-collapse: collapse; font-size: 9pt; } diff --git a/Open-ILS/web/opac/skin/default/js/authbrowse.js b/Open-ILS/web/opac/skin/default/js/authbrowse.js index 5fcb5ecf68..643d6c530c 100644 --- a/Open-ILS/web/opac/skin/default/js/authbrowse.js +++ b/Open-ILS/web/opac/skin/default/js/authbrowse.js @@ -1,4 +1,5 @@ dojo.require("openils.CGI"); +dojo.require("openils.Util"); dojo.require("MARC.FixedFields"); dojo.require("openils.AuthorityControlSet"); var cgi; @@ -7,7 +8,6 @@ attachEvt("common", "init", doAuthorityBrowse); /* repeatable, supports all args or no args */ function doAuthorityBrowse(axis, term, page, per_page) { - console.log("doAuthorityBrowse 1"); if (!axis) { if (!cgi) cgi = new openils.CGI(); axis = cgi.param(PARAM_AUTHORITY_BROWSE_AXIS); @@ -15,7 +15,6 @@ function doAuthorityBrowse(axis, term, page, per_page) { page = 0; per_page = 20; } - console.log("doAuthorityBrowse 2"); var url = '/opac/extras/browse/marcxml/authority.' + axis @@ -24,7 +23,6 @@ function doAuthorityBrowse(axis, term, page, per_page) { + '/' + page + '/' + per_page ; - console.log("doAuthorityBrowse 3: " + url); dojo.xhrGet({ "url": url, "handleAs": "xml", @@ -34,22 +32,110 @@ function doAuthorityBrowse(axis, term, page, per_page) { }); } +function renderAuthorityTagContent(m, af) { + if (af.tag() && af.sf_list()) { + return dojo.filter( + dojo.map( + af.sf_list().split(""), + function(code) { + var result = m.subfield(af.tag(), code); + return (typeof(result[1]) == "undefined") ? "" : result[1]; + } + ), function(datum) { return datum.length > 0; } + ).join(" "); + } else { + return ""; + } +} + +function renderAuthoritySubEntry(m, field, tbody) { + var content = + openils.Util.trimString(renderAuthorityTagContent(m, field)); + if (!content.length) return; /* don't display empty tags */ + + var tr = dojo.create("tr", null, tbody); + dojo.create("td", {"style": {"width": "2em"}, "innerHTML": ""}, tr); + dojo.create( + "td", { + "className": "authority-tag-label", + "innerHTML": field.name() + ":", + "title": field.description() || "" + }, tr + ); + dojo.create( + "td", { + "className": "authority-tag-content authority-record-right", + "innerHTML": content + }, tr + ); + + if (field.sub_entries() && field.sub_entries().length) { + /* I *think* this shouldn't happen with good data? */ + console.log("I, too, have " + field.sub_entries().length + + "sub_entries"); + } +} + +function renderAuthorityMainEntry(m, field, tbody) { + var content = + openils.Util.trimString(renderAuthorityTagContent(m, field)); + if (!content.length) return; /* don't display empty tags */ + + var tr = dojo.create("tr", null, tbody); + dojo.create( + "td", { + "className": "authority-tag-content authority-record-main", + "innerHTML": content, + "colspan": 2 + }, tr + ); + dojo.create( + "td", { + "className": "authority-tag-label authority-record-right", + "innerHTML": field.name(), + "title": field.description() || "" + }, tr + ); + + if (field.sub_entries()) { + dojo.forEach( + field.sub_entries(), + function(f) { renderAuthoritySubEntry(m, f, tbody); } + ); + } +} + +function renderAuthorityRecord(m, control_set) { + var main_entries = openils.Util.objectSort( + dojo.filter( + control_set.authority_fields(), + function(o) { return o.main_entry() == null; } + ), "tag" + ); + + var table = dojo.create("table", {"className": "authority-record"}); + var tbody = dojo.create("tbody", null, table); + + dojo.forEach( + main_entries, function(af) { renderAuthorityMainEntry(m, af, tbody); } + ); + + return table; +} + function displayAuthorityRecords(doc) { - console.log("displayAuthorityRecords"); var acs_helper = new openils.AuthorityControlSet(); - console.log("got acs_helper"); + + /* XXX I wanted to use bibtemplate here, but now I'm not sure it makes + * sense: the template itself would have to be dynamic, as it would vary + * from record to record when different control sets were in use. + */ dojo.query("record", doc).forEach( function(record) { - console.log("record"); var m = new MARC.Record({"xml": record}); var s = m.extractFixedField("Subj"); var cs = acs_helper.controlSetByThesaurusCode(s); - console.log("got cs"); - dojo.create( - "div", { - "innerHTML": "record here, control set is " + cs - }, "test-holder" - ); + dojo.place(renderAuthorityRecord(m, cs.raw), "test-holder"); } ); }