2 var recordsHandled = 0;
5 /* set up the event handlers */
6 G.evt.result.hitCountReceived.push(resultSetHitInfo);
7 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
8 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
9 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
11 /* do this after we have ID's so the rank for mr pages will be correct */
12 attachEvt("result", "preCollectRecords", resultPaginate);
14 /* returns the last 'index' postion ocurring in this page */
15 function resultFinalPageIndex() {
16 if(getHitCount() < (getOffset() + getDisplayCount()))
17 return getHitCount() - 1;
18 return getOffset() + getDisplayCount() - 1;
21 /* set the search result info, number of hits, which results we're
22 displaying, links to the next/prev pages, etc. */
23 function resultSetHitInfo() {
25 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
26 else c = getDisplayCount() + getOffset();
28 var pages = getHitCount() / getDisplayCount();
29 if(pages % 1) pages = parseInt(pages) + 1;
31 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
32 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
34 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
35 G.ui.result.offset_end.appendChild(text(c));
36 G.ui.result.result_count.appendChild(text(getHitCount()));
37 unHideMe(G.ui.result.info);
41 function resultPaginate() {
44 if( !((o + getDisplayCount()) >= getHitCount()) ) {
47 args[PARAM_OFFSET] = o + getDisplayCount();
48 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
49 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
51 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
52 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
53 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
59 args[PARAM_OFFSET] = o - getDisplayCount();
60 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
61 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
63 args[PARAM_OFFSET] = 0;
64 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
65 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
70 /* display the record info in the record display table 'pos' is the
71 zero based position the record should have in the display table */
72 function resultDisplayRecord(rec, pos, is_mr) {
74 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
76 recordsCache.push(rec);
78 var r = table.rows[pos + 1];
81 var rank = parseFloat(ranks[pos + getOffset()]);
82 rank = ( rank / getTopRank() ) * 100;
83 rank = parseInt(rank) + "%";
84 var relspan = findNodeByName(r, "relevancy_span");
85 relspan.appendChild(text(rank));
86 unHideMe(relspan.parentNode);
89 var pic = findNodeByName(r, config.names.result.item_jacket);
90 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
92 var title_link = findNodeByName(r, config.names.result.item_title);
93 var author_link = findNodeByName(r, config.names.result.item_author);
96 var onlyrec = onlyrecord[ getOffset() + pos ];
99 var id = rec.doc_id();
101 buildTitleDetailLink(rec, title_link);
107 args[PARAM_OFFSET] = 0;
108 args[PARAM_RID] = onlyrec;
109 args[PARAM_MRID] = rec.doc_id();
110 pic.parentNode.setAttribute("href", buildOPACLink(args));
111 title_link.setAttribute("href", buildOPACLink(args));
112 title_link.appendChild(text(normalize(truncate(rec.title(), 65))));
115 buildTitleLink(rec, title_link);
118 args[PARAM_OFFSET] = 0;
119 args[PARAM_MRID] = rec.doc_id();
120 pic.parentNode.setAttribute("href", buildOPACLink(args));
124 buildTitleDetailLink(rec, title_link);
127 args[PARAM_OFFSET] = 0;
128 args[PARAM_RID] = rec.doc_id();
129 pic.parentNode.setAttribute("href", buildOPACLink(args));
132 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
136 if(!isNull(rec.edition())) {
137 unHideMe( findNodeByName(r, "result_table_extra_span"));
138 findNodeByName(r, "result_table_edition_span").appendChild( text( rec.edition()) );
140 if(!isNull(rec.pubdate())) {
141 unHideMe( findNodeByName(r, "result_table_extra_span"));
142 unHideMe(findNodeByName(r, "result_table_pub_span"));
143 findNodeByName(r, "result_table_pub_span").appendChild( text( rec.pubdate() ));
145 if(!isNull(rec.publisher()) ) {
146 unHideMe( findNodeByName(r, "result_table_extra_span"));
147 unHideMe(findNodeByName(r, "result_table_pub_span"));
148 findNodeByName(r, "result_table_pub_span").appendChild( text( " " + rec.publisher() ));
152 resultBuildFormatIcons( r, rec );
156 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
158 if(resultPageIsDone()) {
159 /* hide the 'now loading...' message */
160 hideMe(G.ui.common.loading);
161 runEvt('result', 'allRecordsReceived', recordsCache);
165 function resultBuildFormatIcons( row, rec ) {
167 var ress = rec.types_of_resource();
169 for( var i in ress ) {
172 var link = findNodeByName(row, res + "_link");
174 var img = link.getElementsByTagName("img")[0];
175 removeCSSClass( img, config.css.dim );
180 if( f != modsFormatToMARC(res) )
181 addCSSClass( img, config.css.dim2);
183 addCSSClass( img, "dim2_border");
185 if( f == modsFormatToMARC(res) )
186 addCSSClass( img, "dim2_border");
192 args[PARAM_OFFSET] = 0;
193 args[PARAM_MRID] = rec.doc_id();
194 args[PARAM_FORM] = modsFormatToMARC(res);
196 link.setAttribute("href", buildOPACLink(args));
203 function resultPageIsDone(pos) {
204 return (recordsHandled == getDisplayCount()
205 || recordsHandled + getOffset() == getHitCount());
208 var resultCCHeaderApplied = false;
210 /* -------------------------------------------------------------------- */
211 /* dynamically add the copy count rows based on the org type 'countsrow'
212 is the row into which we will add TD's to hold the copy counts
213 This code generates copy count cells with an id of
214 'copy_count_cell_<depth>_<pagePosition>' */
215 function resultAddCopyCounts(rec, pagePosition) {
217 var r = table.rows[pagePosition + 1];
218 var countsrow = findNodeByName(r, config.names.result.counts_row );
219 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
221 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
223 var type = findOrgType(node.ou_type());
224 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
225 ccell.title = type.opac_label();
226 //addCSSClass(ccell, config.css.result.cc_cell_even);
228 var lastcell = ccell;
229 var lastheadcell = null;
232 var ccheadcell = null;
233 if(!resultCCHeaderApplied) {
234 ccrow = getId('result_thead_row');
235 ccheadcell = ccrow.removeChild(findNodeByName(ccrow, "result_thead_ccell"));
236 var t = ccheadcell.cloneNode(true);
238 t.appendChild(text(type.opac_label()));
239 ccrow.appendChild(t);
240 resultCCHeaderApplied = true;
246 var d = findOrgDepth(nodes[1]);
247 var d2 = findOrgDepth(nodes[nodes.length -1]);
249 for( var i = d; i <= d2 ; i++ ) {
251 ccell = ccell.cloneNode(true);
253 //if((i % 2)) removeCSSClass(ccell, "copy_count_cell_even");
254 //else addCSSClass(ccell, "copy_count_cell_even");
256 var node = nodes[x++];
257 var type = findOrgType(node.ou_type());
259 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
260 ccell.title = type.opac_label();
261 countsrow.insertBefore(ccell, lastcell);
265 var t = ccheadcell.cloneNode(true);
266 t.appendChild(text(type.opac_label()));
267 ccrow.insertBefore(t, lastheadcell);
273 unHideMe(getId("search_info_table"));
276 /* collect copy counts for a record using method 'methodName' */
277 function resultCollectCopyCounts(rec, pagePosition, methodName) {
278 if(rec == null || rec.doc_id() == null) return;
279 var req = new Request(methodName, getLocation(), rec.doc_id() );
280 req.request.userdata = [ rec, pagePosition ];
281 req.callback(resultHandleCopyCounts);
285 function resultHandleCopyCounts(r) {
286 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
290 /* display the collected copy counts */
291 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
292 if(copy_counts == null || rec == null) return;
294 while(copy_counts[i] != null) {
295 var cell = getId("copy_count_cell_" + i +"_" + pagePosition);
297 var span = cell.getElementsByTagName("div")[0];
299 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
306 /* captures extraneous info from each record */
308 var subjectCache = {};
309 var authorCache = {};
310 var seriesCache = {};
312 function resultBuildCaches(records) {
313 for( var r in records ) {
314 var rec = records[r];
315 for( var s in rec.subject() )
316 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
317 authorCache[rec.author()] = 1;
318 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
322 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
323 function resultDrawSubjects() {
326 for( var s in subjectCache )
327 subjs.push( { sub : s, count : subjectCache[s] } );
328 subjs.sort(resultSortSubjects);
331 for( var s in subjs ) ss.push(subjs[s].sub);
332 resultDrawSidebarStuff(STYPE_SUBJECT, G.ui.sidebar.subject_item,
333 config.names.sidebar.subject_item, ss, G.ui.sidebar.subject);
336 function resultDrawAuthors() {
337 var auths = new Array();
338 for( var s in authorCache ) auths.push(s);
339 resultDrawSidebarStuff(STYPE_AUTHOR, G.ui.sidebar.author_item,
340 config.names.sidebar.author_item, auths.sort(), G.ui.sidebar.author);
343 function resultDrawSeries() {
344 var sers = new Array();
345 for( var s in seriesCache ) sers.push(s);
346 resultDrawSidebarStuff(STYPE_SERIES, G.ui.sidebar.series_item,
347 config.names.sidebar.series_item, sers.sort(), G.ui.sidebar.series);
350 /* search type, template node, href link name, array of text, node to unhide */
351 function resultDrawSidebarStuff(stype, node, linkname, items, wrapperNode) {
352 var parent = node.parentNode;
353 var template = parent.removeChild(node);
355 var newnode = template.cloneNode(true);
357 for( var i in items ) {
358 if(isNull(items[i])) continue;
360 buildSearchLink(stype, items[i], findNodeByName(newnode, linkname), 100);
361 parent.appendChild(newnode);
362 newnode = template.cloneNode(true);
365 if(found) unHideMe(wrapperNode);