2 var recordsHandled = 0;
5 /* set up the event handlers */
6 G.evt.result.hitCountReceived.push(resultSetHitInfo, resultPaginate);
7 G.evt.result.recordReceived.push(resultDisplayRecord, resultAddCopyCounts);
8 G.evt.result.copyCountsReceived.push(resultDisplayCopyCounts);
9 G.evt.result.allRecordsReceived.push(resultBuildCaches, resultDrawSubjects, resultDrawAuthors, resultDrawSeries);
12 /* returns the last 'index' postion ocurring in this page */
13 function resultFinalPageIndex() {
14 if(getHitCount() < (getOffset() + getDisplayCount()))
15 return getHitCount() - 1;
16 return getOffset() + getDisplayCount() - 1;
19 /* set the search result info, number of hits, which results we're
20 displaying, links to the next/prev pages, etc. */
21 function resultSetHitInfo() {
23 if( getDisplayCount() > (getHitCount() - getOffset())) c = getHitCount();
24 else c = getDisplayCount() + getOffset();
26 var pages = getHitCount() / getDisplayCount();
27 if(pages % 1) pages = parseInt(pages) + 1;
29 G.ui.result.current_page.appendChild(text( (getOffset()/getDisplayCount()) + 1));
30 G.ui.result.num_pages.appendChild(text(pages + ")")); /* the ) is dumb */
32 G.ui.result.offset_start.appendChild(text(getOffset() + 1));
33 G.ui.result.offset_end.appendChild(text(c));
34 G.ui.result.result_count.appendChild(text(getHitCount()));
35 unHideMe(G.ui.result.info);
39 function resultPaginate() {
42 if( !((o + getDisplayCount()) >= getHitCount()) ) {
45 args[PARAM_OFFSET] = o + getDisplayCount();
46 G.ui.result.next_link.setAttribute("href", buildOPACLink(args));
47 addCSSClass(G.ui.result.next_link, config.css.result.nav_active);
49 args[PARAM_OFFSET] = getHitCount() - (getHitCount() % getDisplayCount());
50 G.ui.result.end_link.setAttribute("href", buildOPACLink(args));
51 addCSSClass(G.ui.result.end_link, config.css.result.nav_active);
57 args[PARAM_OFFSET] = o - getDisplayCount();
58 G.ui.result.prev_link.setAttribute( "href", buildOPACLink(args));
59 addCSSClass(G.ui.result.prev_link, config.css.result.nav_active);
61 args[PARAM_OFFSET] = 0;
62 G.ui.result.home_link.setAttribute( "href", buildOPACLink(args));
63 addCSSClass(G.ui.result.home_link, config.css.result.nav_active);
68 /* display the record info in the record display table 'pos' is the
69 zero based position the record should have in the display table */
70 function resultDisplayRecord(rec, pos, is_mr) {
72 if(rec == null) rec = new mvr(); /* so the page won't die if there was an error */
74 recordsCache.push(rec);
76 /* hide the 'now loading...' message */
77 hideMe(G.ui.common.loading);
79 var r = table.rows[pos];
81 var pic = findNodeByName(r, config.names.result.item_jacket);
82 pic.setAttribute("src", buildISBNSrc(cleanISBN(rec.isbn())));
84 var title_link = findNodeByName(r, config.names.result.item_title);
85 var author_link = findNodeByName(r, config.names.result.item_author);
87 if( is_mr ) buildTitleLink(rec, title_link);
88 else buildTitleDetailLink(rec, title_link);
89 buildSearchLink(STYPE_AUTHOR, rec.author(), author_link);
91 findNodeByName(r, "result_table_title_cell").width =
92 100 - (orgNodeTrail(findOrgUnit(getLocation())).length * 8) + "%";
94 resultBuildFormatIcons( r, rec );
98 runEvt("result", "recordDrawn", rec.doc_id(), title_link);
100 if(resultPageIsDone())
101 runEvt('result', 'allRecordsReceived', recordsCache);
104 function resultBuildFormatIcons( row, rec ) {
106 var td = findNodeByName( row, config.names.result.format_cell );
107 var linkt = td.removeChild(findNodeByName( row, config.names.result.format_link ));
108 var resources = rec.types_of_resource();
110 for( var i in resources ) {
111 var link = linkt.cloneNode(true);
115 args[PARAM_OFFSET] = 0;
116 args[PARAM_MRID] = rec.doc_id();
117 args[PARAM_FORM] = modsFormatToMARC(resources[i]);
118 link.setAttribute("href", buildOPACLink(args));
120 var img = findNodeByName(link, config.names.result.format_pic);
121 setResourcePic( img, resources[i] );
122 td.appendChild(link);
127 function resultPageIsDone(pos) {
128 return (recordsHandled == getDisplayCount()
129 || recordsHandled + getOffset() == getHitCount());
132 /* -------------------------------------------------------------------- */
133 /* dynamically add the copy count rows based on the org type 'countsrow'
134 is the row into which we will add TD's to hold the copy counts
135 This code generates copy count cells with an id of
136 'copy_count_cell_<depth>_<pagePosition>' */
137 function resultAddCopyCounts(rec, pagePosition) {
139 var r = table.rows[pagePosition];
140 var countsrow = findNodeByName(r, config.names.result.counts_row );
141 var ccell = findNodeByName(countsrow, config.names.result.count_cell);
143 var nodes = orgNodeTrail(findOrgUnit(getLocation()));
145 var type = findOrgType(node.ou_type());
146 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
147 ccell.title = type.opac_label();
148 addCSSClass(ccell, config.css.result.cc_cell_even);
150 var lastcell = ccell;
155 var d = findOrgDepth(nodes[1]);
156 var d2 = findOrgDepth(nodes[nodes.length -1]);
158 for( var i = d; i <= d2 ; i++ ) {
160 ccell = ccell.cloneNode(true);
163 removeCSSClass(ccell, "copy_count_cell_even");
165 addCSSClass(ccell, "copy_count_cell_even");
167 var node = nodes[x++];
168 var type = findOrgType(node.ou_type());
170 ccell.id = "copy_count_cell_" + type.depth() + "_" + pagePosition;
171 ccell.title = type.opac_label();
172 countsrow.insertBefore(ccell, lastcell);
178 /* collect copy counts for a record using method 'methodName' */
179 function resultCollectCopyCounts(rec, pagePosition, methodName) {
180 if(rec == null || rec.doc_id() == null) return;
181 var req = new Request(methodName, getLocation(), rec.doc_id() );
182 req.request.userdata = [ rec, pagePosition ];
183 req.callback(resultHandleCopyCounts);
187 function resultHandleCopyCounts(r) {
188 runEvt('result', 'copyCountsReceived', r.userdata[0], r.userdata[1], r.getResultObject());
192 /* display the collected copy counts */
193 function resultDisplayCopyCounts(rec, pagePosition, copy_counts) {
194 if(copy_counts == null || rec == null) return;
196 while(copy_counts[i] != null) {
197 var cell = getId("copy_count_cell_" + i +"_" + pagePosition);
198 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
204 /* captures extraneous info from each record */
206 var subjectCache = {};
207 var authorCache = {};
208 var seriesCache = {};
210 function resultBuildCaches(records) {
211 for( var r in records ) {
212 var rec = records[r];
213 for( var s in rec.subject() )
214 subjectCache[s] == null ? subjectCache[s] = 1 : subjectCache[s]++;
215 authorCache[rec.author()] = 1;
216 for( var s in rec.series() ) seriesCache[rec.series()[s]] = 1;
220 function resultSortSubjects(a, b) { return -(a.count - b.count); } /* sort in reverse */
221 function resultDrawSubjects() {
224 for( var s in subjectCache )
225 subjs.push( { sub : s, count : subjectCache[s] } );
226 subjs.sort(resultSortSubjects);
229 for( var s in subjs ) ss.push(subjs[s].sub);
230 resultDrawSidebarStuff(STYPE_SUBJECT, G.ui.sidebar.subject_item,
231 config.names.sidebar.subject_item, ss, G.ui.sidebar.subject);
234 function resultDrawAuthors() {
235 var auths = new Array();
236 for( var s in authorCache ) auths.push(s);
237 resultDrawSidebarStuff(STYPE_AUTHOR, G.ui.sidebar.author_item,
238 config.names.sidebar.author_item, auths.sort(), G.ui.sidebar.author);
241 function resultDrawSeries() {
242 var sers = new Array();
243 for( var s in seriesCache ) sers.push(s);
244 resultDrawSidebarStuff(STYPE_SERIES, G.ui.sidebar.series_item,
245 config.names.sidebar.series_item, sers.sort(), G.ui.sidebar.series);
248 /* search type, template node, href link name, array of text, node to unhide */
249 function resultDrawSidebarStuff(stype, node, linkname, items, wrapperNode) {
250 var parent = node.parentNode;
251 var template = parent.removeChild(node);
253 var newnode = template.cloneNode(true);
255 for( var i in items ) {
256 if(isNull(items[i])) continue;
258 buildSearchLink(stype, items[i], findNodeByName(newnode, linkname), 100);
259 parent.appendChild(newnode);
260 newnode = template.cloneNode(true);
263 if(found) unHideMe(wrapperNode);