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);
163 /* collect copy counts for a record using method 'methodName' */
164 function resultCollectCopyCounts(rec, methodName) {
165 if(rec == null || rec.doc_id() == null) return;
166 var req = new Request(methodName, getLocation(), rec.doc_id() );
167 req.request.userdata = rec;
168 req.callback(resultHandleCopyCounts);
172 function resultHandleCopyCounts(r) {
173 resultDisplayCopyCounts(r.userdata, r.getResultObject());
177 /* display the collected copy counts */
178 function resultDisplayCopyCounts(rec, copy_counts) {
179 if(copy_counts == null || rec == null) return;
181 while(copy_counts[i] != null) {
182 var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id());
183 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
188 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
189 function resultDrawSubjects() {
191 for( var s in subjectCache )
192 subjs.push( { sub : s, count : subjectCache[s] } );
193 subjs.sort(resultSortSubjects);
196 for( var s in subjs ) ss.push(subjs[s].sub);
197 resultDrawSidebarStuff(STYPE_SUBJECT, G.ui.sidebar.subject_item,
198 config.names.sidebar.subject_item, ss, G.ui.sidebar.subject);
201 function resultDrawAuthors() {
202 var auths = new Array();
203 for( var s in authorCache ) auths.push(s);
204 resultDrawSidebarStuff(STYPE_AUTHOR, G.ui.sidebar.author_item,
205 config.names.sidebar.author_item, auths.sort(), G.ui.sidebar.author);
208 function resultDrawSeries() {
209 var sers = new Array();
210 for( var s in seriesCache ) sers.push(s);
211 resultDrawSidebarStuff(STYPE_SERIES, G.ui.sidebar.series_item,
212 config.names.sidebar.series_item, sers.sort(), G.ui.sidebar.series);
215 /* search type, template node, href link name, array of text, node to unhide */
216 function resultDrawSidebarStuff(stype, node, linkname, items, wrapperNode) {
217 var parent = node.parentNode;
218 var template = parent.removeChild(node);
220 var newnode = template.cloneNode(true);
222 for( var i in items ) {
223 if(isNull(items[i])) continue;
225 buildSearchLink(stype, items[i], findNodeByName(newnode, linkname), 100);
226 parent.appendChild(newnode);
227 newnode = template.cloneNode(true);
230 if(found) unHideMe(wrapperNode);