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 if(resultPageIsDone())
100 runEvt('result', 'allRecordsReceived', recordsCache);
103 function resultPageIsDone(pos) {
104 return (recordsHandled == getDisplayCount()
105 || recordsHandled + getOffset() == getHitCount());
108 /* -------------------------------------------------------------------- */
109 /* dynamically add the copy count rows based on the org type 'countsrow'
110 is the row into which we will add TD's to hold the copy counts
111 This code generates copy count cells with an id of
112 'copy_count_cell_<depth>_<pagePosition>' */
113 function resultAddCopyCounts(rec, pagePosition) {
115 var r = table.rows[pagePosition];
116 var countsrow = findNodeByName(r, config.names.result.counts_row );
117 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
119 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
121 var type = findOrgType(node.ou_type());
122 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
123 ccell.title = type.opac_label();
124 addCSSClass(ccell, config.css.result.cc_cell_even);
126 var lastcell = ccell;
131 var d = findOrgDepth(nodes[1]);
132 var d2 = findOrgDepth(nodes[nodes.length -1]);
134 for( var i = d; i <= d2 ; i++ ) {
136 ccell = ccell.cloneNode(true);
139 removeCSSClass(ccell, "copy_count_cell_even");
141 addCSSClass(ccell, "copy_count_cell_even");
143 var node = nodes[x++];
144 var type = findOrgType(node.ou_type());
146 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
147 ccell.title = type.opac_label();
148 countsrow.insertBefore(ccell, lastcell);
154 /* collect copy counts for a record using method 'methodName' */
155 function resultCollectCopyCounts(rec, pagePosition, methodName) {
156 if(rec == null || rec.doc_id() == null) return;
157 var req = new Request(methodName, getLocation(), rec.doc_id() );
158 req.request.userdata = [ rec, pagePosition ];
159 req.callback(resultHandleCopyCounts);
163 function resultHandleCopyCounts(r) {
164 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
168 /* display the collected copy counts */
169 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
170 if(copy_counts == null || rec == null) return;
172 while(copy_counts[i] != null) {
173 var cell = getId("copy_count_cell_" + i +"_" + pagePosition);
174 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
180 /* captures extraneous info from each record */
181 function resultBuildCaches(records) {
182 for( var r in records ) {
183 var rec = records[r];
184 for( var s in rec.subject() )
185 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
186 authorCache[rec.author()] = 1;
187 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
192 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
193 function resultDrawSubjects() {
196 for( var s in subjectCache )
197 subjs.push( { sub : s, count : subjectCache[s] } );
198 subjs.sort(resultSortSubjects);
201 for( var s in subjs ) ss.push(subjs[s].sub);
202 resultDrawSidebarStuff(STYPE_SUBJECT, G.ui.sidebar.subject_item,
203 config.names.sidebar.subject_item, ss, G.ui.sidebar.subject);
206 function resultDrawAuthors() {
207 var auths = new Array();
208 for( var s in authorCache ) auths.push(s);
209 resultDrawSidebarStuff(STYPE_AUTHOR, G.ui.sidebar.author_item,
210 config.names.sidebar.author_item, auths.sort(), G.ui.sidebar.author);
213 function resultDrawSeries() {
214 var sers = new Array();
215 for( var s in seriesCache ) sers.push(s);
216 resultDrawSidebarStuff(STYPE_SERIES, G.ui.sidebar.series_item,
217 config.names.sidebar.series_item, sers.sort(), G.ui.sidebar.series);
220 /* search type, template node, href link name, array of text, node to unhide */
221 function resultDrawSidebarStuff(stype, node, linkname, items, wrapperNode) {
222 var parent = node.parentNode;
223 var template = parent.removeChild(node);
225 var newnode = template.cloneNode(true);
227 for( var i in items ) {
228 if(isNull(items[i])) continue;
230 buildSearchLink(stype, items[i], findNodeByName(newnode, linkname), 100);
231 parent.appendChild(newnode);
232 newnode = template.cloneNode(true);
235 if(found) unHideMe(wrapperNode);