5 var recordsHandled = 0;
8 /* set up the event handlers */
9 G.evt.result.hitCountReceived.push(resultSetHitInfo, resultPaginate);
10 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
11 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
12 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
15 /* returns the last 'index' postion ocurring in this page */
16 function resultFinalPageIndex() {
17 if(getHitCount() < (getOffset() + getDisplayCount()))
18 return getHitCount() - 1;
19 return getOffset() + getDisplayCount() - 1;
22 /* set the search result info, number of hits, which results we're
23 displaying, links to the next/prev pages, etc. */
24 function resultSetHitInfo() {
26 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
27 else c = getDisplayCount() + getOffset();
29 var pages = getHitCount() / getDisplayCount();
30 if(pages % 1) pages = parseInt(pages) + 1;
32 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
33 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
35 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
36 G.ui.result.offset_end.appendChild(text(c));
37 G.ui.result.result_count.appendChild(text(getHitCount()));
38 unHideMe(G.ui.result.info);
42 function resultPaginate() {
45 if( !((o + getDisplayCount()) >= getHitCount()) ) {
48 args[PARAM_OFFSET] = o + getDisplayCount();
49 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
50 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
52 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
53 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
54 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
60 args[PARAM_OFFSET] = o - getDisplayCount();
61 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
62 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
64 args[PARAM_OFFSET] = 0;
65 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
66 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
71 /* display the record info in the record display table 'pos' is the
72 zero based position the record should have in the display table */
73 function resultDisplayRecord(rec, pos, is_mr) {
75 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
77 recordsCache.push(rec);
79 /* hide the 'now loading...' message */
80 hideMe(G.ui.common.loading);
82 var r = table.rows[pos];
84 var pic = findNodeByName(r, config.names.result.item_jacket);
85 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
87 var title_link = findNodeByName(r, config.names.result.item_title);
88 var author_link = findNodeByName(r, config.names.result.item_author);
90 if( is_mr ) buildTitleLink(rec, title_link);
91 else buildTitleDetailLink(rec, title_link);
92 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
94 findNodeByName(r, "result_table_title_cell").width =
95 100 - (orgNodeTrail(findOrgUnit(getLocation())).length * 8) + "%";
99 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
101 if(resultPageIsDone())
102 runEvt('result', 'allRecordsReceived', recordsCache);
105 function resultPageIsDone(pos) {
106 return (recordsHandled == getDisplayCount()
107 || recordsHandled + getOffset() == getHitCount());
110 /* -------------------------------------------------------------------- */
111 /* dynamically add the copy count rows based on the org type 'countsrow'
112 is the row into which we will add TD's to hold the copy counts
113 This code generates copy count cells with an id of
114 'copy_count_cell_<depth>_<pagePosition>' */
115 function resultAddCopyCounts(rec, pagePosition) {
117 var r = table.rows[pagePosition];
118 var countsrow = findNodeByName(r, config.names.result.counts_row );
119 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
121 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
123 var type = findOrgType(node.ou_type());
124 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
125 ccell.title = type.opac_label();
126 addCSSClass(ccell, config.css.result.cc_cell_even);
128 var lastcell = ccell;
133 var d = findOrgDepth(nodes[1]);
134 var d2 = findOrgDepth(nodes[nodes.length -1]);
136 for( var i = d; i <= d2 ; i++ ) {
138 ccell = ccell.cloneNode(true);
141 removeCSSClass(ccell, "copy_count_cell_even");
143 addCSSClass(ccell, "copy_count_cell_even");
145 var node = nodes[x++];
146 var type = findOrgType(node.ou_type());
148 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
149 ccell.title = type.opac_label();
150 countsrow.insertBefore(ccell, lastcell);
156 /* collect copy counts for a record using method 'methodName' */
157 function resultCollectCopyCounts(rec, pagePosition, methodName) {
158 if(rec == null || rec.doc_id() == null) return;
159 var req = new Request(methodName, getLocation(), rec.doc_id() );
160 req.request.userdata = [ rec, pagePosition ];
161 req.callback(resultHandleCopyCounts);
165 function resultHandleCopyCounts(r) {
166 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
170 /* display the collected copy counts */
171 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
172 if(copy_counts == null || rec == null) return;
174 while(copy_counts[i] != null) {
175 var cell = getId("copy_count_cell_" + i +"_" + pagePosition);
176 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
182 /* captures extraneous info from each record */
183 function resultBuildCaches(records) {
184 for( var r in records ) {
185 var rec = records[r];
186 for( var s in rec.subject() )
187 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
188 authorCache[rec.author()] = 1;
189 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
194 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
195 function resultDrawSubjects() {
198 for( var s in subjectCache )
199 subjs.push( { sub : s, count : subjectCache[s] } );
200 subjs.sort(resultSortSubjects);
203 for( var s in subjs ) ss.push(subjs[s].sub);
204 resultDrawSidebarStuff(STYPE_SUBJECT, G.ui.sidebar.subject_item,
205 config.names.sidebar.subject_item, ss, G.ui.sidebar.subject);
208 function resultDrawAuthors() {
209 var auths = new Array();
210 for( var s in authorCache ) auths.push(s);
211 resultDrawSidebarStuff(STYPE_AUTHOR, G.ui.sidebar.author_item,
212 config.names.sidebar.author_item, auths.sort(), G.ui.sidebar.author);
215 function resultDrawSeries() {
216 var sers = new Array();
217 for( var s in seriesCache ) sers.push(s);
218 resultDrawSidebarStuff(STYPE_SERIES, G.ui.sidebar.series_item,
219 config.names.sidebar.series_item, sers.sort(), G.ui.sidebar.series);
222 /* search type, template node, href link name, array of text, node to unhide */
223 function resultDrawSidebarStuff(stype, node, linkname, items, wrapperNode) {
224 var parent = node.parentNode;
225 var template = parent.removeChild(node);
227 var newnode = template.cloneNode(true);
229 for( var i in items ) {
230 if(isNull(items[i])) continue;
232 buildSearchLink(stype, items[i], findNodeByName(newnode, linkname), 100);
233 parent.appendChild(newnode);
234 newnode = template.cloneNode(true);
237 if(found) unHideMe(wrapperNode);