2 AbstractRecordResultPage.prototype = new Page();
3 AbstractRecordResultPage.prototype.constructor = AbstractRecordResultPage;
4 AbstractRecordResultPage.baseClass = Page.constructor;
7 /* constructor for our singleton object */
8 function AbstractRecordResultPage() {}
11 /* initialize all of the UI components and set up data structures */
12 AbstractRecordResultPage.prototype.init = function() {
14 debug( "Initing an AbstractRecordResultPage" );
16 /* included page chunks */
17 this.searchBar = new SearchBarChunk();
20 this.recordBox = getById("record_result_box");
22 this.authorBox = new Box();
23 this.authorBox.init("Relevant Authors", true, true, 15);
24 this.authorBox.sortByKey();
26 this.subjectBox = new Box();
27 this.subjectBox.init("Relevant Subjects", true, true, 15);
28 this.subjectBox.sortByCount();
30 this.seriesBox = new Box();
31 this.seriesBox.init("Relevant Series", true, true, 15);
32 this.seriesBox.sortByKey();
34 this.sidebarBox = getById("record_sidebar_box");
36 this.sidebarBox.appendChild(this.buildNavBox());
37 this.sidebarBox.appendChild(elem("br"));
40 this.hitsPerPage = 10; /* how many hits are displayed per page */
44 this.statusBar = getById("top_status_bar_table");
45 this.theadDrawn = false;
46 this.bigOlBox = getById("big_ol_box");
53 /** Resets data structures for a new search */
54 AbstractRecordResultPage.prototype.resetPage = function() {
55 this.searchBar.reset();
56 var spot = getById("progress_bar_location");
57 var spot2 = getById("progress_bar_percent_location");
60 spot.removeChild(spot.lastChild);
62 /* progress items for each record and it's hit count listing */
63 this.progressBar = new ProgressBar(parseInt(this.hitsPerPage) * 2);
64 spot.appendChild(this.progressBar.getNode());
66 if(spot2 && this.progressBar)
67 spot2.appendChild(this.progressBar.percentDiv);
70 RemoteRequest.cancelAll();
72 this.requestBatch = new RequestBatch();
73 this.finalized = false;
74 this.builtLinks = false;
76 this.hitsPerPageSelector = getById('hits_per_page');
79 this.hitsPerPageSelector.onchange = function() {
82 var hits_obj = obj.hitsPerPageSelector.options[
83 obj.hitsPerPageSelector.selectedIndex];
90 debug("Hits per page set to " + hits );
92 obj.hitsPerPage = parseInt(hits);
95 var location = globalSelectedLocation;
96 if(location == null) location = globalLocation.id();
98 url_redirect(obj.URLRefresh());
103 for( var i in this.hitsPerPageSelector.options ) {
105 var hits_obj = obj.hitsPerPageSelector.options[i];
106 if(hits_obj == null) continue;
107 var hits = hits_obj.value;
109 if( this.hitsPerPage == parseInt(hits) )
110 this.hitsPerPageSelector.options[i].selected = true;
116 AbstractRecordResultPage.prototype.resetSearch = function() {
117 this.recordIDs = new Array();
118 this.ranks = new Array();
119 this.hitCount = 0; /* hits for the current search */
120 this.searchOffset = 0; /* the offset for the search display */
125 AbstractRecordResultPage.prototype.gatherIDs = function(result) {
126 if(result == null) return;
128 this.hitCount = parseInt(result.count);
130 if(result.ids.length < 1) {
136 /* the 'ids' field consist of [record, rank] */
137 /* gather all of the ID's */
138 if( result.ids && typeof result.ids == 'object'
139 && result.ids[0] != null
140 && result.ids[0].constructor == Array ) {
142 for( var i in result.ids ) {
143 if(result.ids[i]==null || result.ids[i][0] == null) break;
144 var offset = parseInt(i) + parseInt(this.searchOffset);
145 this.recordIDs[offset] = result.ids[i][0];
146 var rank = parseFloat(result.ids[i][1]);
148 rank = 0.00000001; /* protect divide by 0 */
149 this.ranks[offset] = rank;
151 debug("adding ranks[" + offset + "] = " + result.ids[i][1] +
152 " \nrecordIDs["+offset+"], result.ids["+i+"][0]");
158 for( var i in result.ids ) {
159 if(result.ids[i]==null) break;
160 var offset = parseInt(i) + parseInt(this.searchOffset);
161 this.recordIDs[offset] = result.ids[i];
162 debug("adding recordIDs["+offset+"], result.ids["+i+"]");
171 AbstractRecordResultPage.prototype.complete = function() {
176 AbstractRecordResultPage.prototype.displayRecord =
177 function( record, search_id, page_id ) {
179 if(record == null) return;
180 debug("Displaying record " + record.doc_id());
182 if(!instanceOf(record, Fieldmapper)) {
183 debug(" * Received bogus record " + js2JSON(record));
188 this.buildNextLinks();
192 this.progressBar.manualNext();
194 var id = parseInt(page_id);
195 var title_row = table_row_find_or_create(this.recordBox, id * 3 + 1 );
196 var author_row = table_row_find_or_create(this.recordBox, id * 3 + 2 );
197 var misc_row = table_row_find_or_create(this.recordBox, id * 3 + 3 );
199 add_css_class(misc_row, "record_misc_row");
200 add_css_class(title_row, "record_title_row");
203 var c = misc_row.insertCell(0);
204 /* shove in a div for each of the types of resource */
205 for( var i = 0; i!= 9; i++) {
206 var div = createAppElement("div");
207 div.innerHTML = " ";
208 add_css_class(div, "record_resource_div");
211 //var options_cell = misc_row.insertCell(1);
213 c.className = "record_misc_cell";
214 var resources = record.types_of_resource();
216 for( var i in resources )
217 this.buildResourcePic( c, resources[i]);
219 author_row.id = "record_result_author_row_" + id;
220 title_row.id = "record_result_title_row_" + id;
222 /* build the appropriate context node for this result */
223 var menu_name = "record_result_row_" + page_id;
224 var menu = globalMenuManager.buildMenu(menu_name);
226 this.addMenuItems( menu, record );
228 globalMenuManager.setContext(title_row, menu);
229 globalMenuManager.setContext(author_row, menu);
230 globalMenuManager.setContext(misc_row, menu);
232 getDocument().body.appendChild(menu.getNode());
234 //var optionsLink = this.buildExtendedLinks(record, page_id);
236 // options_cell.appendChild(optionsLink);
237 /* ------------------------------------ */
240 var pic_cell = title_row.insertCell(0);
241 this.buildRecordImage( pic_cell, record, page_id, record.title());
243 var title_cell = title_row.insertCell(title_row.cells.length);
244 title_cell.id = "record_result_title_box_" + id;
245 add_css_class( title_cell, "record_result_title_box");
247 var author_cell = author_row.insertCell(author_row.cells.length);
248 author_cell.id = "record_result_author_box_" + id;
249 add_css_class(author_cell, "record_result_author_box");
252 /* limit the length of the title and author lines */
256 if( record.title() ) {
257 if(record.title().length > tlength) {
258 record.title(record.title().substr(0,tlength));
259 record.title(record.title() + "...");
261 title = normalize(record.title());
266 if( record.author() ) {
267 if(record.author().length > tlength) {
268 record.author( record.author().substr(0,tlength));
269 record.author(record.author() + "...");
271 author = normalize(record.author());
274 title_cell.appendChild(this.mkLink(record.doc_id(), "title", title, record.title() ));
275 author_cell.innerHTML = " ";
276 author_cell.appendChild(this.mkLink(record.doc_id(), "author", author ));
278 if(instanceOf(this, RecordResultPage)) {
279 var span = createAppElement("span");
280 span.style.marginLeft = "10px";
282 if(record.pubdate() || record.edition())
283 span.appendChild(createAppTextNode(" -- "));
286 span.appendChild(createAppTextNode(" " + record.pubdate()));
289 span.appendChild(createAppTextNode(" " + record.edition()));
291 author_cell.appendChild(span);
293 var marcb = elem( "a",
295 href:"javascript:void(0)",
296 style: "text-decoration:underline"
300 debug("Setting up view marc callback with record " + record.doc_id());
301 var func = buildViewMARCWindow(record);
302 marcb.onclick = func;
304 var marcd = elem( "div", { style: "float:right" } );
305 marcd.appendChild(marcb);
306 //author_cell.appendChild(marcd);
307 //misc_row.insertCell(misc_row.cells.length).appendChild(marcd);
308 c.appendChild(marcd);
313 var classname = "result_even";
315 classname = "result_odd";
317 add_css_class(title_row, classname);
318 add_css_class(author_row, classname);
319 add_css_class(misc_row, classname);
321 /* now grab the record authors and subjects */
323 this.authorBox.addItem( this.mkAuthorLink(author) , author);
326 /* gather the subjects. subjects are either a string or an array of
327 [subject, broader topic]. currently, they're all just treated like
329 var arr = record.subject();
331 for( var sub in arr ) {
332 if(x++ > 5) break; /* too many subjects makes things real sluggish */
336 /* only taking first part of subject (non-topic, etc.) */
337 if( ss.constructor == Array)
340 if( ss.constructor != Array )
344 var s = normalize(ss[i]);
345 this.subjectBox.addItem( this.mkSubjectLink(s), s );
349 var series = record.series();
350 for( var s in series ) {
351 debug("Found series entry: " + series[s] );
352 var ss = normalize(series[s]);
353 this.seriesBox.addItem( this.mkSeriesLink(ss), ss );
356 /* requestBatch will only have one request in it when the current
357 record is the last record requested */
358 if( this.requestBatch.pending() < 2 )
361 debug("Finished displaying record " + record.doc_id());
364 AbstractRecordResultPage.prototype.mkAuthorLink = function(auth) {
365 var href = createAppElement("a");
366 add_css_class(href,"record_result_sidebar_link");
368 href.setAttribute("href",
369 "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
370 encodeURIComponent(auth) +
371 "&mr_search_depth=" + this.searchDepth +
372 "&mr_search_location=" + this.searchLocation +
373 "&location=" + this.searchLocation +
374 "&depth=" + this.searchDepth);
376 href.appendChild(createAppTextNode(auth));
377 href.title = "Author search for " + auth;
381 AbstractRecordResultPage.prototype.mkSeriesLink = function(series) {
382 var href = createAppElement("a");
383 add_css_class(href,"record_result_sidebar_link");
385 debug("Series: " + series + " : " + encodeURIComponent(series));
387 href.setAttribute("href",
388 "?target=mr_result&mr_search_type=series&page=0&mr_search_query=" +
389 encodeURIComponent(series) +
390 "&mr_search_depth=" + this.searchDepth +
391 "&mr_search_location=" + this.searchLocation +
392 "&location=" + this.searchLocation +
393 "&depth=" + this.searchDepth);
395 href.appendChild(createAppTextNode(series));
396 href.title = "Series search for " + series;
400 AbstractRecordResultPage.prototype.mkSubjectLink = function(sub) {
401 var href = createAppElement("a");
402 add_css_class(href,"record_result_sidebar_link");
403 href.setAttribute("href",
404 "?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
405 encodeURIComponent(sub) +
406 "&mr_search_depth=" + this.searchDepth +
407 "&mr_search_location=" + this.searchLocation +
408 "&location=" + this.searchLocation +
409 "&depth=" + this.searchDepth);
411 href.appendChild(createAppTextNode(sub));
412 href.title = "Subject search for " + sub;
416 AbstractRecordResultPage.prototype.finalizePage = function() {
420 this.finalized = true;
423 this.subjectBox.finalize();
424 this.authorBox.finalize();
425 this.seriesBox.finalize();
427 this.sidebarBox.appendChild(this.subjectBox.getNode());
428 this.sidebarBox.appendChild(createAppElement("br"));
430 this.sidebarBox.appendChild(this.authorBox.getNode());
431 this.sidebarBox.appendChild(createAppElement("br"));
433 this.sidebarBox.appendChild(this.seriesBox.getNode());
434 this.sidebarBox.appendChild(createAppElement("br"));
436 // showMe(this.buttonsBox);
438 var ses = UserSession.instance().getSessionId();
439 var box = this.sidebarBox;
442 Survey.retrieveOpacRandom(ses,
444 sur.setSubmitCallback(
445 function() { alert("Thanks!"); return true; });
446 box.appendChild( sur.getNode() );
447 sur.setHidden(false);
451 Survey.retrieveOpacRandomGlobal(
453 sur.setSubmitCallback(
454 function() { alert("Thanks!"); return true; });
455 box.appendChild( sur.getNode() );
456 sur.setHidden(false);
462 if(this.hitCount < 1) {
463 if(this.progressBar) this.progressBar.stop();
466 /* in case we're hidden */
467 showMe(this.bigOlBox);
468 showMe(getById("hit_count_cell_2"));
473 AbstractRecordResultPage.prototype.displayCopyCounts =
474 function(copy_counts, search_id, page_id) {
476 this.progressBar.manualNext();
477 var titlerow = getById("record_result_title_row_" + page_id );
478 var authorrow = getById("record_result_author_row_" + page_id );
480 var tcell = getById("record_result_title_box_" + page_id );
482 if(!this.theadDrawn) {
483 var trow = getById("record_result_thead_row");
484 for( var i in copy_counts) {
485 var cell = trow.insertCell(trow.cells.length);
486 add_css_class(cell,"record_result_thead_header");
488 findOrgType(findOrgUnit(
489 copy_counts[i].org_unit).ou_type()).opac_label();
491 this.theadDrawn = true;
494 for( var i in copy_counts) {
495 var cell = createAppElement("td");
496 add_css_class(cell, "copy_count_cell");
497 cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
498 cell.setAttribute("rowspan","3");
500 cell.title = " Availabie Copies / Total Copies";
501 titlerow.appendChild(cell);
504 if(page_id == (parseInt(this.hitsPerPage) - 1) ) {
505 if(this.progressBar) this.progressBar.stop();
506 if(this.hitCount < 1)
510 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
511 (page_id == (parseInt(this.hitsPerPage) - 1) ))
512 if(this.progressBar) this.progressBar.stop();
517 AbstractRecordResultPage.prototype.noHits = function() {
518 var hcell = getById("hit_count_cell");
519 //hcell.appendChild(createAppElement("br"));
520 hcell.appendChild(createAppTextNode("0 hits were returned for you search"));
524 AbstractRecordResultPage.prototype.buildNextLinks = function() {
528 this.builtLinks = true;
534 debug("Building links");
535 if( this.searchOffset < (parseInt(this.hitCount) - this.hitsPerPage)) {
536 next = createAppElement("a");
537 add_css_class(next,"record_next_button");
538 add_css_class(next,"record_next_button_active");
539 next.href = "javascript:globalPage.next();";
541 next = createAppElement("span");
542 add_css_class(next,"record_next_button_inactive");
545 if(this.searchOffset > 0) {
546 prev = createAppElement("a");
547 add_css_class(prev,"record_next_button");
548 add_css_class(prev,"record_next_button_active");
549 prev.href = "javascript:globalPage.prev();";
551 prev = createAppElement("span");
552 add_css_class(prev,"record_next_button_inactive");
555 next.appendChild(createAppTextNode("Next"));
556 prev.appendChild(createAppTextNode("Previous"));
559 var i = this.searchOffset;
560 var max = parseInt(i) + this.hitsPerPage;
561 if( max > this.hitCount )
564 var hcell = getById("hit_count_cell");
565 var hcell2 = getById("hit_count_cell_2");
570 var ident = "Titles";
571 if(instanceOf(this, MRResultPage))
572 ident = "Title Groups";
575 createAppTextNode( "Displaying " + ident + " " +
576 ( parseInt(i) + 1 ) + " to " + max + " of " + this.hitCount));
578 hcell.appendChild(createAppTextNode(" "));
579 hcell.appendChild(createAppTextNode(" "));
580 hcell.appendChild(createAppTextNode(" "));
582 hcell.appendChild(prev);
583 var span = createAppElement("span");
584 span.appendChild(createAppTextNode(" ... "));
585 hcell.appendChild(span);
586 hcell.appendChild(next);
588 hcell2.innerHTML = hcell.innerHTML;
595 AbstractRecordResultPage.prototype.buildResourcePic = function(c, resource) {
596 return buildResourcePic(c, resource);
599 function buildResourcePic(c, resource) {
601 var pic = createAppElement("img");
603 pic.setAttribute("src", "/images/" + resource + ".jpg");
604 pic.className = "record_resource_pic";
605 pic.setAttribute("width", "20");
606 pic.setAttribute("height", "20");
607 pic.setAttribute("title", resource);
622 case "sound recording":
626 case "software, multimedia":
638 case "mixed material":
642 case "notated music":
646 case "three dimensional object":
654 c.childNodes[index].innerHTML = "";
655 c.childNodes[index].appendChild(pic);
658 AbstractRecordResultPage.prototype.buildRecordImage = function(pic_cell, record, page_id, title) {
660 debug("Building record image for " + page_id);
661 var isbn = record.isbn();
662 if(isbn) isbn = isbn.replace(/\s+/,"");
665 pic_cell.setAttribute("rowspan","3");
666 pic_cell.rowSpan = 3;
668 pic_cell.noWrap = 'nowrap';
669 pic_cell.setAttribute("nowrap", "nowrap");
671 pic_cell.width = "60";
672 pic_cell.className = "record_image_cell";
676 if( this.ranks.length > 0 ) {
677 var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
678 var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
680 debug("Per is " + per);
681 per = 100 - parseInt(per);
683 rankBox = createAppElement("div");
684 add_css_class(rankBox, "relevance_box");
686 var d = createAppElement("div");
687 d.setAttribute("height", per + "%");
688 d.style.height = per + "%";
690 add_css_class(d, "relevance");
691 rankBox.appendChild(d);
693 rankBox.setAttribute("title", parseInt((100 - parseInt(per))) + "% Relevant");
696 /* use amazon for now */
697 var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg";
698 var big_div = createAppElement("div");
699 add_css_class(big_div, "record_image_big hide_me");
701 var big_pic = createAppElement("img");
702 var pic = createAppElement("img");
704 big_pic.setAttribute("src", img_src);
705 big_pic.setAttribute("border", "0");
706 pic.setAttribute("src", img_src);
707 add_css_class(big_pic, "record_image");
708 add_css_class(pic, "record_image");
710 pic.setAttribute("width", "45");
711 pic.setAttribute("height", "50");
712 pic.style.width = "45";
713 pic.style.height = "50";
716 big_div.style.left = 0;
719 var anch = this.mkLink(record.doc_id(), "img", title );
720 anch.appendChild(big_pic);
721 big_div.appendChild(anch);
722 pic_cell.appendChild(big_div);
724 pic_cell.appendChild(pic);
727 pic_cell.appendChild(rankBox);
729 pic.onmouseover = function() {showMe(big_div);}
730 big_div.onmouseout = function(){hideMe(big_div);}