4 var recordsHandled = 0;
6 function resultFinalPageIndex() {
7 if(getHitCount() < (getOffset() + getDisplayCount()))
8 return getHitCount() - 1;
9 return getOffset() + getDisplayCount() - 1;
12 /* set the search result info, number of hits, which results we're
13 displaying, links to the next/prev pages, etc. */
14 function resultSetInfo() {
16 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
17 else c = getDisplayCount() + getOffset();
19 var pages = getHitCount() / getDisplayCount();
20 if(pages % 1) pages = parseInt(pages) + 1;
22 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
23 G.ui.result.num_pages.appendChild(text(pages + ")"));
27 if( !((o + getDisplayCount()) >= getHitCount()) ) {
30 args[PARAM_OFFSET] = o + getDisplayCount();
31 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
32 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
34 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
35 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
36 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
42 args[PARAM_OFFSET] = o - getDisplayCount();
43 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
44 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
46 args[PARAM_OFFSET] = 0;
47 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
48 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
51 G.ui.result.offset_start.appendChild(text(o + 1));
52 G.ui.result.offset_end.appendChild(text(c));
53 G.ui.result.result_count.appendChild(text(getHitCount()));
54 unHideMe(G.ui.result.info);
59 /* display the record info in the record display table
60 'pos' is the zero based position the record should have in the
62 function resultDisplayRecord(rec, rowtemplate, pos, is_mr) {
64 if(rec == null) rec = new mvr(); /* so the page won't die */
67 /* hide the 'now loading...' message */
68 hideMe(G.ui.common.loading);
70 var r = table.rows[pos];
72 var pic = findNodeByName(r, config.names.result.item_jacket);
73 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
75 var title_link = findNodeByName(r, config.names.result.item_title);
76 var author_link = findNodeByName(r, config.names.result.item_author);
78 if( is_mr ) buildTitleLink(rec, title_link);
79 else buildTitleDetailLink(rec, title_link);
80 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
82 /* grab subjects, authors, and series from the record */
83 for( var s in rec.subject() )
84 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
85 authorCache[rec.author()] = 1;
86 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
88 if(resultPageIsDone() && !subjectsAreDrawn) {
89 subjectsAreDrawn = true;
96 var countsrow = findNodeByName(r, config.names.result.counts_row);
98 /* adjust the width according to how many org counts are added */
99 findNodeByName(r, "result_table_title_cell").width =
100 resultAddCopyCounts(countsrow, rec) + "%";
106 var subjectsAreDrawn = false;
107 function resultPageIsDone(pos) {
108 return (recordsHandled == getDisplayCount()
109 || recordsHandled + getOffset() == getHitCount());
113 /* -------------------------------------------------------------------- */
114 /* dynamically add the copy count rows based on the org type
115 'countsrow' is the row into which we will add TD's to hold
117 This code generates copy count cells with an id of
118 'copy_count_cell_<depth>_<record_id>' for later insertion of copy counts
119 return the percent width left over after the each count is added.
120 if 3 counts are added, returns 100 - (cell.width * 3) */
121 function resultAddCopyCounts(countsrow, rec) {
123 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
126 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
128 var type = findOrgType(node.ou_type());
129 ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
130 ccell.title = type.opac_label();
131 addCSSClass(ccell, "copy_count_cell_even");
133 var lastcell = ccell;
138 var d = findOrgDepth(nodes[1]);
139 var d2 = findOrgDepth(nodes[nodes.length -1]);
141 for( var i = d; i <= d2 ; i++ ) {
143 ccell = ccell.cloneNode(true);
146 removeCSSClass(ccell, "copy_count_cell_even");
148 addCSSClass(ccell, "copy_count_cell_even");
150 var node = nodes[x++];
151 var type = findOrgType(node.ou_type());
153 ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
154 ccell.title = type.opac_label();
155 countsrow.insertBefore(ccell, lastcell);
160 return 100 - (nodes.length * 8);
164 /* collect copy counts for a record using method 'methodName' */
165 function resultCollectCopyCounts(rec, methodName) {
166 if(rec == null || rec.doc_id() == null) return;
167 var req = new Request(methodName, getLocation(), rec.doc_id() );
168 req.request.userdata = rec;
169 req.callback(resultHandleCopyCounts);
173 function resultHandleCopyCounts(r) {
174 resultDisplayCopyCounts(r.userdata, r.getResultObject());
178 /* display the collected copy counts */
179 function resultDisplayCopyCounts(rec, copy_counts) {
180 if(copy_counts == null || rec == null) return;
182 while(copy_counts[i] != null) {
183 var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id());
184 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
189 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
191 function resultDrawSubjects() {
194 for( var s in subjectCache )
195 subjs.push( { sub : s, count : subjectCache[s] } );
196 subjs.sort(resultSortSubjects);
198 var template = G.ui.sidebar.subject.removeChild(G.ui.sidebar.subject_item);
200 var newnode = template.cloneNode(true);
203 for( var s in subjs ) {
204 if(isNull(subjs[s])) continue;
206 buildSearchLink(STYPE_SUBJECT, subjs[s].sub,
207 findNodeByName(newnode, config.names.sidebar.subject_item), 30);
208 G.ui.sidebar.subject.appendChild(newnode);
209 newnode = template.cloneNode(true);
212 if(found) unHideMe(G.ui.sidebar.subject);
215 function resultDrawAuthors() {
217 var template = G.ui.sidebar.author.removeChild(G.ui.sidebar.author_item);
219 var newnode = template.cloneNode(true);
221 var auths = new Array();
222 for( var s in authorCache ) auths.push(s);
223 auths = auths.sort();
226 for( var i in auths ) {
227 if(isNull(auths[i])) continue;
229 buildSearchLink(STYPE_AUTHOR, auths[i], findNodeByName(newnode, config.names.sidebar.author_item), 30);
230 G.ui.sidebar.author.appendChild(newnode);
231 newnode = template.cloneNode(true);
234 if(found) unHideMe(G.ui.sidebar.author);
238 function resultDrawSeries() {
239 var template = G.ui.sidebar.series.removeChild(G.ui.sidebar.series_item);
241 var newnode = template.cloneNode(true);
243 var sers = new Array();
244 for( var s in seriesCache ) sers.push(s);
248 for( var i in sers ) {
249 if(isNull(sers[i])) continue;
251 buildSearchLink(STYPE_SERIES, sers[i], findNodeByName(newnode, config.names.sidebar.series_item), 30);
252 G.ui.sidebar.series.appendChild(newnode);
253 newnode = template.cloneNode(true);
256 if(found) unHideMe(G.ui.sidebar.series);