4 var recordsHandled = 0;
6 /* set the search result info, number of hits, which results we're
7 displaying, links to the next/prev pages, etc. */
8 function resultSetInfo() {
10 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
11 else c = getDisplayCount() + getOffset();
13 var pages = getHitCount() / getDisplayCount();
14 if(pages % 1) pages = parseInt(pages) + 1;
16 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
17 G.ui.result.num_pages.appendChild(text(pages + ")"));
21 if( !((o + getDisplayCount()) >= getHitCount()) ) {
24 args[PARAM_OFFSET] = o + getDisplayCount();
25 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
26 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
28 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
29 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
30 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
36 args[PARAM_OFFSET] = o - getDisplayCount();
37 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
38 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
40 args[PARAM_OFFSET] = 0;
41 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
42 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
45 G.ui.result.offset_start.appendChild(text(o + 1));
46 G.ui.result.offset_end.appendChild(text(c));
47 G.ui.result.result_count.appendChild(text(getHitCount()));
48 unHideMe(G.ui.result.info);
53 /* display the record info in the record display table
54 'pos' is the zero based position the record should have in the
56 function resultDisplayRecord(rec, rowtemplate, pos, is_mr) {
58 if(rec == null) rec = new mvr(); /* so the page won't die */
61 /* hide the 'now loading...' message */
62 hideMe(G.ui.common.loading);
64 var r = table.rows[pos];
66 var pic = findNodeByName(r, config.names.result.item_jacket);
67 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
69 var title_link = findNodeByName(r, config.names.result.item_title);
70 var author_link = findNodeByName(r, config.names.result.item_author);
72 if( is_mr ) buildTitleLink(rec, title_link);
73 else buildTitleDetailLink(rec, title_link);
74 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
76 /* grab subjects, authors, and series from the record */
77 for( var s in rec.subject() )
78 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
79 authorCache[rec.author()] = 1;
80 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
82 if(resultPageIsDone() && !subjectsAreDrawn) {
83 subjectsAreDrawn = true;
90 var countsrow = findNodeByName(r, config.names.result.counts_row);
92 /* adjust the width according to how many org counts are added */
93 findNodeByName(r, "result_table_title_cell").width =
94 resultAddCopyCounts(countsrow, rec) + "%";
100 var subjectsAreDrawn = false;
101 function resultPageIsDone(pos) {
102 return (recordsHandled == getDisplayCount()
103 || recordsHandled + getOffset() == getHitCount());
107 /* -------------------------------------------------------------------- */
108 /* dynamically add the copy count rows based on the org type
109 'countsrow' is the row into which we will add TD's to hold
111 This code generates copy count cells with an id of
112 'copy_count_cell_<depth>_<record_id>' for later insertion of copy counts
113 return the percent width left over after the each count is added.
114 if 3 counts are added, returns 100 - (cell.width * 3) */
115 function resultAddCopyCounts(countsrow, rec) {
117 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
120 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
122 var type = findOrgType(node.ou_type());
123 ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
124 ccell.title = type.opac_label();
125 addCSSClass(ccell, "copy_count_cell_even");
127 var lastcell = ccell;
132 var d = findOrgDepth(nodes[1]);
133 var d2 = findOrgDepth(nodes[nodes.length -1]);
135 for( var i = d; i <= d2 ; i++ ) {
137 ccell = ccell.cloneNode(true);
140 removeCSSClass(ccell, "copy_count_cell_even");
142 addCSSClass(ccell, "copy_count_cell_even");
144 var node = nodes[x++];
145 var type = findOrgType(node.ou_type());
147 ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
148 ccell.title = type.opac_label();
149 countsrow.insertBefore(ccell, lastcell);
154 return 100 - (nodes.length * 8);
158 /* collect copy counts for a record using method 'methodName' */
159 function resultCollectCopyCounts(rec, methodName) {
160 if(rec == null || rec.doc_id() == null) return;
161 var req = new Request(methodName, getLocation(), rec.doc_id() );
162 req.request.userdata = rec;
163 req.callback(resultHandleCopyCounts);
167 function resultHandleCopyCounts(r) {
168 resultDisplayCopyCounts(r.userdata, r.getResultObject());
172 /* display the collected copy counts */
173 function resultDisplayCopyCounts(rec, copy_counts) {
174 if(copy_counts == null || rec == null) return;
176 while(copy_counts[i] != null) {
177 var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id());
178 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
183 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
185 function resultDrawSubjects() {
188 for( var s in subjectCache )
189 subjs.push( { sub : s, count : subjectCache[s] } );
190 subjs.sort(resultSortSubjects);
192 var template = G.ui.sidebar.subject.removeChild(G.ui.sidebar.subject_item);
194 var newnode = template.cloneNode(true);
197 for( var s in subjs ) {
198 if(isNull(subjs[s])) continue;
200 buildSearchLink(STYPE_SUBJECT, subjs[s].sub,
201 findNodeByName(newnode, config.names.sidebar.subject_item), 30);
202 G.ui.sidebar.subject.appendChild(newnode);
203 newnode = template.cloneNode(true);
206 if(found) unHideMe(G.ui.sidebar.subject);
209 function resultDrawAuthors() {
211 var template = G.ui.sidebar.author.removeChild(G.ui.sidebar.author_item);
213 var newnode = template.cloneNode(true);
215 var auths = new Array();
216 for( var s in authorCache ) auths.push(s);
217 auths = auths.sort();
220 for( var i in auths ) {
221 if(isNull(auths[i])) continue;
223 buildSearchLink(STYPE_AUTHOR, auths[i], findNodeByName(newnode, config.names.sidebar.author_item), 30);
224 G.ui.sidebar.author.appendChild(newnode);
225 newnode = template.cloneNode(true);
228 if(found) unHideMe(G.ui.sidebar.author);
232 function resultDrawSeries() {
233 var template = G.ui.sidebar.series.removeChild(G.ui.sidebar.series_item);
235 var newnode = template.cloneNode(true);
237 var sers = new Array();
238 for( var s in seriesCache ) sers.push(s);
242 for( var i in sers ) {
243 if(isNull(sers[i])) continue;
245 buildSearchLink(STYPE_SERIES, sers[i], findNodeByName(newnode, config.names.sidebar.series_item), 30);
246 G.ui.sidebar.series.appendChild(newnode);
247 newnode = template.cloneNode(true);
250 if(found) unHideMe(G.ui.sidebar.series);