5 /* set the search result info, number of hits, which results we're
6 displaying, links to the next/prev pages, etc. */
7 function resultSetInfo() {
9 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
10 else c = getDisplayCount() + getOffset();
12 var pages = getHitCount() / getDisplayCount();
13 if(pages % 1) pages = parseInt(pages) + 1;
15 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
16 G.ui.result.num_pages.appendChild(text(pages + ")"));
20 if( !((o + getDisplayCount()) >= getHitCount()) ) {
23 args[PARAM_OFFSET] = o + getDisplayCount();
24 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
25 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
27 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
28 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
29 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
35 args[PARAM_OFFSET] = o - getDisplayCount();
36 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
37 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
39 args[PARAM_OFFSET] = 0;
40 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
41 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
44 G.ui.result.offset_start.appendChild(text(o + 1));
45 G.ui.result.offset_end.appendChild(text(c));
46 G.ui.result.result_count.appendChild(text(getHitCount()));
47 unHideMe(G.ui.result.info);
52 /* display the record info in the record display table
53 'pos' is the zero based position the record should have in the
55 function resultDisplayRecord(rec, rowtemplate, pos, is_mr) {
57 if(rec == null) rec = new mvr(); /* so the page won't die */
59 /* hide the 'now loading...' message */
60 hideMe(G.ui.common.loading);
62 var r = table.rows[pos];
64 var pic = findNodeByName(r, config.names.result.item_jacket);
65 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
67 var title_link = findNodeByName(r, config.names.result.item_title);
68 var author_link = findNodeByName(r, config.names.result.item_author);
70 if( is_mr ) buildTitleLink(rec, title_link);
71 else buildTitleDetailLink(rec, title_link);
72 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
74 /* grab subjects, authors, and series from the record */
75 for( var s in rec.subject() )
76 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
77 authorCache[rec.author()] = 1;
78 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
80 if(resultPageIsDone(pos)) {
87 var countsrow = findNodeByName(r, config.names.result.counts_row);
89 /* adjust the width according to how many org counts are added */
90 findNodeByName(r, "result_table_title_cell").width =
91 resultAddCopyCounts(countsrow, rec) + "%";
97 function resultPageIsDone(pos) {
98 return ((pos+1) == getDisplayCount() || (pos+1 + getOffset()) == getHitCount());
102 /* -------------------------------------------------------------------- */
103 /* dynamically add the copy count rows based on the org type
104 'countsrow' is the row into which we will add TD's to hold
106 This code generates copy count cells with an id of
107 'copy_count_cell_<depth>_<record_id>' for later insertion of copy counts
108 return the percent width left over after the each count is added.
109 if 3 counts are added, returns 100 - (cell.width * 3) */
110 function resultAddCopyCounts(countsrow, rec) {
112 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
115 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
117 var type = findOrgType(node.ou_type());
118 ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
119 ccell.title = type.opac_label();
120 addCSSClass(ccell, "copy_count_cell_even");
122 var lastcell = ccell;
127 var d = findOrgDepth(nodes[1]);
128 var d2 = findOrgDepth(nodes[nodes.length -1]);
130 for( var i = d; i <= d2 ; i++ ) {
132 ccell = ccell.cloneNode(true);
135 removeCSSClass(ccell, "copy_count_cell_even");
137 addCSSClass(ccell, "copy_count_cell_even");
139 var node = nodes[x++];
140 var type = findOrgType(node.ou_type());
142 ccell.id = "copy_count_cell_" + type.depth() + "_" + rec.doc_id();
143 ccell.title = type.opac_label();
144 countsrow.insertBefore(ccell, lastcell);
149 return 100 - (nodes.length * 8);
153 /* collect copy counts for a record using method 'methodName' */
154 function resultCollectCopyCounts(rec, methodName) {
155 if(rec == null || rec.doc_id() == null) return;
156 var req = new Request(methodName, getLocation(), rec.doc_id() );
157 req.request.userdata = rec;
158 req.callback(resultHandleCopyCounts);
162 function resultHandleCopyCounts(r) {
163 resultDisplayCopyCounts(r.userdata, r.getResultObject());
167 /* display the collected copy counts */
168 function resultDisplayCopyCounts(rec, copy_counts) {
169 if(copy_counts == null || rec == null) return;
171 while(copy_counts[i] != null) {
172 var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id());
173 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
178 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
180 function resultDrawSubjects() {
183 for( var s in subjectCache )
184 subjs.push( { sub : s, count : subjectCache[s] } );
185 subjs.sort(resultSortSubjects);
187 var template = G.ui.sidebar.subject.removeChild(G.ui.sidebar.subject_item);
189 var newnode = template.cloneNode(true);
192 for( var s in subjs ) {
193 if(isNull(subjs[s])) continue;
195 buildSearchLink(STYPE_SUBJECT, subjs[s].sub,
196 findNodeByName(newnode, config.names.sidebar.subject_item), 30);
197 G.ui.sidebar.subject.appendChild(newnode);
198 newnode = template.cloneNode(true);
201 if(found) unHideMe(G.ui.sidebar.subject);
204 function resultDrawAuthors() {
206 var template = G.ui.sidebar.author.removeChild(G.ui.sidebar.author_item);
208 var newnode = template.cloneNode(true);
210 var auths = new Array();
211 for( var s in authorCache ) auths.push(s);
212 auths = auths.sort();
215 for( var i in auths ) {
216 if(isNull(auths[i])) continue;
218 buildSearchLink(STYPE_AUTHOR, auths[i], findNodeByName(newnode, config.names.sidebar.author_item), 30);
219 G.ui.sidebar.author.appendChild(newnode);
220 newnode = template.cloneNode(true);
223 if(found) unHideMe(G.ui.sidebar.author);
227 function resultDrawSeries() {
228 var template = G.ui.sidebar.series.removeChild(G.ui.sidebar.series_item);
230 var newnode = template.cloneNode(true);
232 var sers = new Array();
233 for( var s in seriesCache ) sers.push(s);
237 for( var i in sers ) {
238 if(isNull(sers[i])) continue;
240 buildSearchLink(STYPE_SERIES, sers[i], findNodeByName(newnode, config.names.sidebar.series_item), 30);
241 G.ui.sidebar.series.appendChild(newnode);
242 newnode = template.cloneNode(true);
245 if(found) unHideMe(G.ui.sidebar.series);