1 dojo.require("openils.CGI");
2 dojo.require("openils.Util");
3 dojo.require("MARC.FixedFields");
4 dojo.require("openils.AuthorityControlSet");
5 var cgi, acs_helper, last_fetched_length = 0;
7 attachEvt("common", "init", doAuthorityBrowse);
9 /* repeatable, supports all args or no args */
10 function doAuthorityBrowse(axis, term, page, per_page) {
11 swapCanvas(dojo.byId("loading_alt"));
14 if (!cgi) cgi = new openils.CGI();
15 axis = cgi.param(PARAM_AUTHORITY_BROWSE_AXIS);
16 term = cgi.param(PARAM_AUTHORITY_BROWSE_TERM);
17 page = cgi.param(PARAM_AUTHORITY_BROWSE_PAGE) || 0;
18 per_page = cgi.param(PARAM_AUTHORITY_BROWSE_PER_PAGE) || 21;
21 var url = '/opac/extras/browse/marcxml/authority.'
23 + '/1' /* this will be OU if OU ever means anything for authorities */
24 + '/' + term /* FIXME urlescape or however it's spelt */
31 "content": {"format": "marcxml"},
33 "load": function(doc) {
34 displayAuthorityRecords(axis, doc);
35 setPagingLinks(axis, term, page, per_page);
40 function setPagingLinks(axis, term, page, per_page) {
41 var up_page = Number(page) - 1;
42 var down_page = Number(page) + 1;
44 unHideMe(dojo.byId("authority-page-up"));
46 "authority-page-up", "onclick", function() {
47 doAuthorityBrowse(axis, term, up_page, per_page);
51 /* XXX In theory this would generally stop the "next page" link from
52 * showing up when it's unwanted, but in practice the supercat/unapi
53 * call we make doesn't return the number of records it's supposed to.
55 // if (last_fetched_length == per_page) {
56 unHideMe(dojo.byId("authority-page-down"));
58 "authority-page-down", "onclick", function() {
59 doAuthorityBrowse(axis, term, down_page, per_page);
63 // hideMe(dojo.byId("authority-page-down"));
67 function renderAuthorityTagContent(m, af) {
68 /* XXX This doesn't take into account possible tag repeatability -- a
69 * bona fide library scientist could probably improve this. :-)
71 if (af.tag() && af.sf_list()) {
74 af.sf_list().split(""),
76 var result = m.subfield(af.tag(), code);
77 return (typeof(result[1]) == "undefined") ? "" : result[1];
79 ), function(datum) { return datum.length > 0; }
86 function renderAuthoritySubEntry(m, field, tbody) {
88 openils.Util.trimString(renderAuthorityTagContent(m, field));
89 if (!content.length) return; /* don't display empty tags */
91 var tr = dojo.create("tr", null, tbody);
92 dojo.create("td", {"style": {"width": "2em"}, "innerHTML": ""}, tr);
95 "className": "authority-tag-label",
96 "innerHTML": field.name() + ":",
97 "title": field.description() || ""
102 "className": "authority-tag-content authority-record-right",
107 if (field.sub_entries() && field.sub_entries().length) {
108 /* I *think* this shouldn't happen with good data? */
109 console.log("I, too, have " + field.sub_entries().length +
114 function renderAuthorityMainEntry(m, field, tbody) {
116 openils.Util.trimString(renderAuthorityTagContent(m, field));
117 if (!content.length) return; /* don't display empty tags */
119 var tr = dojo.create("tr", null, tbody);
120 var content_holder = dojo.create(
122 "className": "authority-tag-content authority-record-main",
128 {"className":"authority-content", "innerHTML": content},
131 dojo.create("span", {"className":"authority-count-holder"}, content_holder);
134 "className": "authority-tag-label authority-record-right",
135 "innerHTML": field.name(),
136 "title": field.description() || ""
140 if (field.sub_entries()) {
143 function(f) { renderAuthoritySubEntry(m, f, tbody); }
148 function renderAuthorityRecord(m, control_set, auth_id) {
149 var main_entries = openils.Util.objectSort(
151 control_set.authority_fields(),
152 function(o) { return o.main_entry() == null; }
156 var table = dojo.create("table", {"className": "authority-record"});
157 var tbody = dojo.create("tbody", {"id": "authority_" + auth_id}, table);
161 main_entries, function(af) { renderAuthorityMainEntry(m, af, tbody); }
167 /* displayAuthorityRecords: given a DOM document object that contains marcxml
168 * records, display each one in a table using the apporiate control set to
169 * determine which fields to show.
171 function displayAuthorityRecords(axis, doc) {
173 acs_helper = new openils.AuthorityControlSet();
175 /* XXX I wanted to use bibtemplate here, but now I'm not sure it makes
176 * sense: the template itself would have to be dynamic, as it would vary
177 * from record to record when different control sets were in use.
181 dojo.empty("authority-record-holder");
183 var records = dojo.query("record", doc);
184 last_fetched_length = records.length;
189 var m = new MARC.Record({"xml": record});
191 var auth_id = m.subfield("901","c")[1];
192 auth_ids.push(auth_id);
195 var t = m.field(/^1/);
196 if (dojo.isArray(t)) t = t[0];
198 var cs = acs_helper.findControlSetsForAuthorityTag( t.tag );
199 if (dojo.isArray(cs)) cs = cs[0];
201 acs_helper.controlSetId( cs );
204 renderAuthorityRecord(m, acs_helper.controlSet().raw, auth_id),
205 "authority-record-holder"
209 displayRecordCounts(axis, auth_ids);
210 swapCanvas(dojo.byId("canvas_main"));
213 function displayRecordCounts(axis, auth_ids) {
214 fieldmapper.standardRequest(
215 ["open-ils.cat", "open-ils.cat.authority.records.count_linked_bibs"], {
216 "params": [auth_ids],
218 "oncomplete": function(r) {
219 if ((r = openils.Util.readResponse(r))) {
220 dojo.forEach(r, function(blob) {
222 displayRecordCount(axis, blob.authority, blob.bibs);
231 function displayRecordCount(axis, id, count) {
232 /* 1) put record count where we can see it */
233 dojo.query("#authority_" + id + " .authority-count-holder")[0].innerHTML =
234 "(" + count + ")"; /* XXX i18n ? */
236 /* 2) also, provide a link to show those records */
237 var span = dojo.query("#authority_" + id + " .authority-content")[0];
241 args[PARAM_DEPTH] = depthSelGetDepth();
242 args[PARAM_FORM] = "all";
243 args[PARAM_LOCATION] = depthSelGetNewLoc();
244 args[PARAM_STYPE] = "keyword";
245 args[PARAM_RTYPE] = "keyword";
246 args[PARAM_TERM] = "identifier|authority_id[" + id + "]";
248 var axis_obj = acs_helper.browseAxisByCode(axis);
249 if (axis_obj.sorter())
250 args[PARAM_TERM] += " sort(" + axis_obj.sorter() + ")";
254 "innerHTML": span.innerHTML,
255 "href": buildOPACLink(args),
256 "className": "authority-content",
257 "title": "Show related bibliographic holdings" /* XXX i18n! */