Finally starting to get somewhere: record display
authorLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 29 Jun 2011 19:45:40 +0000 (15:45 -0400)
committerMike Rylander <mrylander@gmail.com>
Mon, 11 Jul 2011 17:48:30 +0000 (13:48 -0400)
Record display kind of works.  Need paging and links to bibs.

Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/web/js/dojo/MARC/Record.js
Open-ILS/web/opac/skin/default/css/layout.css
Open-ILS/web/opac/skin/default/js/authbrowse.js

index 8bb6a1b..861f200 100644 (file)
@@ -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)
         },
 
index 1197a74..7aaed35 100644 (file)
@@ -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; }
index 5fcb5ec..643d6c5 100644 (file)
@@ -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");
         }
     );
 }