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");
52 /** Resets data structures for a new search */
53 AbstractRecordResultPage.prototype.resetPage = function() {
54 this.searchBar.reset();
55 var spot = getById("progress_bar_location");
56 var spot2 = getById("progress_bar_percent_location");
59 spot.removeChild(spot.lastChild);
61 /* progress items for each record and it's hit count listing */
62 this.progressBar = new ProgressBar(parseInt(this.hitsPerPage) * 2);
63 spot.appendChild(this.progressBar.getNode());
65 if(spot2 && this.progressBar)
66 spot2.appendChild(this.progressBar.percentDiv);
69 RemoteRequest.cancelAll();
71 this.requestBatch = new RequestBatch();
72 this.finalized = false;
73 this.builtLinks = false;
75 this.hitsPerPageSelector = getById('hits_per_page');
78 this.hitsPerPageSelector.onchange = function() {
81 var hits_obj = obj.hitsPerPageSelector.options[
82 obj.hitsPerPageSelector.selectedIndex];
89 debug("Hits per page set to " + hits );
91 obj.hitsPerPage = parseInt(hits);
94 var location = globalSelectedLocation;
95 if(location == null) location = globalLocation.id();
97 url_redirect(obj.URLRefresh());
102 for( var i in this.hitsPerPageSelector.options ) {
104 var hits_obj = obj.hitsPerPageSelector.options[i];
105 if(hits_obj == null) continue;
106 var hits = hits_obj.value;
108 if( this.hitsPerPage == parseInt(hits) )
109 this.hitsPerPageSelector.options[i].selected = true;
115 AbstractRecordResultPage.prototype.resetSearch = function() {
116 this.recordIDs = new Array();
117 this.ranks = new Array();
118 this.hitCount = 0; /* hits for the current search */
119 this.searchOffset = 0; /* the offset for the search display */
124 AbstractRecordResultPage.prototype.gatherIDs = function(result) {
125 if(result == null) return;
127 this.hitCount = parseInt(result.count);
129 if(result.ids.length < 1) {
135 /* the 'ids' field consist of [record, rank] */
136 /* gather all of the ID's */
137 if( result.ids && typeof result.ids == 'object'
138 && result.ids[0] != null
139 && result.ids[0].constructor == Array ) {
141 for( var i in result.ids ) {
142 if(result.ids[i]==null || result.ids[i][0] == null) break;
143 var offset = parseInt(i) + parseInt(this.searchOffset);
144 this.recordIDs[offset] = result.ids[i][0];
145 var rank = parseFloat(result.ids[i][1]);
147 rank = 0.00000001; /* protect divide by 0 */
148 this.ranks[offset] = rank;
150 debug("adding ranks[" + offset + "] = " + result.ids[i][1] +
151 " \nrecordIDs["+offset+"], result.ids["+i+"][0]");
157 for( var i in result.ids ) {
158 if(result.ids[i]==null) break;
159 var offset = parseInt(i) + parseInt(this.searchOffset);
160 this.recordIDs[offset] = result.ids[i];
161 debug("adding recordIDs["+offset+"], result.ids["+i+"]");
170 AbstractRecordResultPage.prototype.complete = function() {
175 AbstractRecordResultPage.prototype.displayRecord =
176 function( record, search_id, page_id ) {
178 if(record == null) return;
179 debug("Displaying record " + record.doc_id());
181 if(!instanceOf(record, Fieldmapper)) {
182 debug(" * Received bogus record " + js2JSON(record));
187 this.buildNextLinks();
191 this.progressBar.manualNext();
193 var id = parseInt(page_id);
194 var title_row = table_row_find_or_create(this.recordBox, id * 3 + 1 );
195 var author_row = table_row_find_or_create(this.recordBox, id * 3 + 2 );
196 var misc_row = table_row_find_or_create(this.recordBox, id * 3 + 3 );
198 add_css_class(misc_row, "record_misc_row");
199 add_css_class(title_row, "record_title_row");
202 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 ) {
219 if(instanceOf(this,MRResultPage)) {
220 var prefix = "http://" + globalRootURL + ":" + globalPort + globalRootPath;
221 var res = modsFormatToMARC(resources[i]);
223 {href: prefix + "?target=record_result&mrid=" +
224 record.doc_id() + "&format=" + res +
225 "&page=0&location=" + this.searchLocation +
226 "&depth=" + this.searchDepth} );
228 this.buildResourcePic( c, resources[i], a);
231 author_row.id = "record_result_author_row_" + id;
232 title_row.id = "record_result_title_row_" + id;
234 /* build the appropriate context node for this result */
235 var menu_name = "record_result_row_" + page_id;
236 var menu = globalMenuManager.buildMenu(menu_name);
238 this.addMenuItems( menu, record );
240 globalMenuManager.setContext(title_row, menu);
241 globalMenuManager.setContext(author_row, menu);
242 globalMenuManager.setContext(misc_row, menu);
244 getDocument().body.appendChild(menu.getNode());
246 //var optionsLink = this.buildExtendedLinks(record, page_id);
248 // options_cell.appendChild(optionsLink);
249 /* ------------------------------------ */
252 var pic_cell = title_row.insertCell(0);
253 this.buildRecordImage( pic_cell, record, page_id, record.title());
255 var title_cell = title_row.insertCell(title_row.cells.length);
256 title_cell.id = "record_result_title_box_" + id;
257 add_css_class( title_cell, "record_result_title_box");
259 var author_cell = author_row.insertCell(author_row.cells.length);
260 author_cell.id = "record_result_author_box_" + id;
261 add_css_class(author_cell, "record_result_author_box");
264 /* limit the length of the title and author lines */
268 if( record.title() ) {
269 if(record.title().length > tlength) {
270 record.title(record.title().substr(0,tlength));
271 record.title(record.title() + "...");
273 title = normalize(record.title());
278 if( record.author() ) {
279 if(record.author().length > tlength) {
280 record.author( record.author().substr(0,tlength));
281 record.author(record.author() + "...");
283 author = normalize(record.author());
286 title_cell.appendChild(this.mkLink(record.doc_id(), "title", title, record.title() ));
287 author_cell.innerHTML = " ";
288 author_cell.appendChild(this.mkLink(record.doc_id(), "author", author ));
291 if(instanceOf(this, RecordResultPage)) {
292 var span = createAppElement("span");
293 span.style.marginLeft = "10px";
295 if(record.pubdate() || record.edition())
296 span.appendChild(createAppTextNode(" -- "));
299 span.appendChild(createAppTextNode(" " + record.pubdate()));
302 span.appendChild(createAppTextNode(" " + record.edition()));
304 author_cell.appendChild(span);
306 var marcb = elem( "a",
307 { href:"javascript:void(0)",
308 style: "text-decoration:underline;"
309 }, null, "View MARC" );
311 debug("Setting up view marc callback with record " + record.doc_id());
312 var func = buildViewMARCWindow(record);
313 marcb.onclick = func;
315 marcd = elem( "div", { style: "float:right;font-size:x-small;" } );
316 marcd.appendChild(marcb);
321 if(instanceOf(this, RecordResultPage)) {
323 var holds = elem( "a",
325 href:"javascript:void(0)",
326 style: "text-decoration:underline"
327 }, {}, "Place Hold" );
331 if(instanceOf(this, RecordResultPage))
335 var user = UserSession.instance();
336 if(user.verifySession()) {
337 win = new HoldsWindow(record.doc_id(),
338 type, user.userObject, user.userObject, user.session_id);
340 win = new HoldsWindow(record.doc_id(),
341 type, null, null, null);
345 holds.onclick = function() { win.toggle(holds); }
346 holddiv = elem("div");
348 //if(instanceOf(this,RecordResultPage))
349 holddiv.setAttribute("style", "float:right");
351 holddiv.appendChild(holds);
352 //var space = elem("span", {style:"padding:5px"},null, " ");
353 //c.appendChild(space)
354 //c.appendChild(mktext(" "))
355 //c.appendChild(holddiv)
358 var tab = elem("table",{style:"float:right"});
359 var tr = tab.insertRow(0);
360 var tc = tr.insertCell(0);
361 var tc2 = tr.insertCell(1);
362 var tc3 = tr.insertCell(2);
363 tc.setAttribute("nowrap", "nowrap");
364 tc3.setAttribute("nowrap", "nowrap");
366 if(holddiv) tc.appendChild(holddiv);
367 tc2.appendChild(mktext(" "));
368 if(marcd) tc3.appendChild(marcd);
374 var classname = "result_even";
375 if((page_id % 2) != 0)
376 classname = "result_odd";
378 add_css_class(title_row, classname);
379 add_css_class(author_row, classname);
380 add_css_class(misc_row, classname);
382 /* now grab the record authors and subjects */
384 this.authorBox.addItem( this.mkAuthorLink(author) , author);
387 /* gather the subjects. subjects are either a string or an array of
388 [subject, broader topic]. currently, they're all just treated like
390 var arr = record.subject();
392 for( var sub in arr ) {
393 if(x++ > 5) break; /* too many subjects makes things real sluggish */
397 /* only taking first part of subject (non-topic, etc.) */
398 if( ss.constructor == Array)
401 if( ss.constructor != Array )
405 var s = normalize(ss[i]);
406 this.subjectBox.addItem( this.mkSubjectLink(s), s );
410 var series = record.series();
411 for( var s in series ) {
412 debug("Found series entry: " + series[s] );
413 var ss = normalize(series[s]);
414 this.seriesBox.addItem( this.mkSeriesLink(ss), ss );
417 /* requestBatch will only have one request in it when the current
418 record is the last record requested */
419 if( this.requestBatch.pending() < 2 )
422 debug("Finished displaying record " + record.doc_id());
425 AbstractRecordResultPage.prototype.mkAuthorLink = function(auth) {
426 var href = createAppElement("a");
427 add_css_class(href,"record_result_sidebar_link");
429 href.setAttribute("href",
430 "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
431 encodeURIComponent(auth) +
432 "&mr_search_depth=" + this.searchDepth +
433 "&mr_search_location=" + this.searchLocation +
434 "&location=" + this.searchLocation +
435 "&depth=" + this.searchDepth);
437 href.appendChild(createAppTextNode(auth));
438 href.title = "Author search for " + auth;
442 AbstractRecordResultPage.prototype.mkSeriesLink = function(series) {
443 var href = createAppElement("a");
444 add_css_class(href,"record_result_sidebar_link");
446 debug("Series: " + series + " : " + encodeURIComponent(series));
448 href.setAttribute("href",
449 "?target=mr_result&mr_search_type=series&page=0&mr_search_query=" +
450 encodeURIComponent(series) +
451 "&mr_search_depth=" + this.searchDepth +
452 "&mr_search_location=" + this.searchLocation +
453 "&location=" + this.searchLocation +
454 "&depth=" + this.searchDepth);
456 href.appendChild(createAppTextNode(series));
457 href.title = "Series search for " + series;
461 AbstractRecordResultPage.prototype.mkSubjectLink = function(sub) {
462 var href = createAppElement("a");
463 add_css_class(href,"record_result_sidebar_link");
464 href.setAttribute("href",
465 "?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
466 encodeURIComponent(sub) +
467 "&mr_search_depth=" + this.searchDepth +
468 "&mr_search_location=" + this.searchLocation +
469 "&location=" + this.searchLocation +
470 "&depth=" + this.searchDepth);
472 href.appendChild(createAppTextNode(sub));
473 href.title = "Subject search for " + sub;
477 AbstractRecordResultPage.prototype.finalizePage = function() {
481 this.finalized = true;
484 this.subjectBox.finalize();
485 this.authorBox.finalize();
486 this.seriesBox.finalize();
488 this.sidebarBox.appendChild(this.subjectBox.getNode());
489 this.sidebarBox.appendChild(createAppElement("br"));
491 this.sidebarBox.appendChild(this.authorBox.getNode());
492 this.sidebarBox.appendChild(createAppElement("br"));
494 this.sidebarBox.appendChild(this.seriesBox.getNode());
495 this.sidebarBox.appendChild(createAppElement("br"));
497 // showMe(this.buttonsBox);
499 var ses = UserSession.instance().getSessionId();
500 var box = this.sidebarBox;
503 Survey.retrieveOpacRandom(ses,
505 sur.setSubmitCallback(
506 function() { alert("Thanks!"); return true; });
507 box.appendChild( sur.getNode() );
508 sur.setHidden(false);
512 Survey.retrieveOpacRandomGlobal(
514 sur.setSubmitCallback(
515 function() { alert("Thanks!"); return true; });
516 box.appendChild( sur.getNode() );
517 sur.setHidden(false);
523 if(this.hitCount < 1) {
524 if(this.progressBar) this.progressBar.stop();
527 /* in case we're hidden */
528 showMe(this.bigOlBox);
529 showMe(getById("hit_count_cell_2"));
534 AbstractRecordResultPage.prototype.displayCopyCounts =
535 function(copy_counts, search_id, page_id) {
537 this.progressBar.manualNext();
538 var titlerow = getById("record_result_title_row_" + page_id );
539 var authorrow = getById("record_result_author_row_" + page_id );
541 var tcell = getById("record_result_title_box_" + page_id );
543 if(!this.theadDrawn) {
544 var trow = getById("record_result_thead_row");
545 for( var i in copy_counts) {
546 var cell = trow.insertCell(trow.cells.length);
547 add_css_class(cell,"record_result_thead_header");
549 findOrgType(findOrgUnit(
550 copy_counts[i].org_unit).ou_type()).opac_label();
552 this.theadDrawn = true;
555 for( var i in copy_counts) {
556 var cell = createAppElement("td");
557 add_css_class(cell, "copy_count_cell");
558 cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
559 cell.setAttribute("rowspan","3");
561 cell.title = " Availabie Copies / Total Copies";
562 titlerow.appendChild(cell);
565 if(page_id == (parseInt(this.hitsPerPage) - 1) ) {
566 if(this.progressBar) this.progressBar.stop();
567 if(this.hitCount < 1)
571 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
572 (page_id == (parseInt(this.hitsPerPage) - 1) ))
573 if(this.progressBar) this.progressBar.stop();
578 AbstractRecordResultPage.prototype.noHits = function() {
579 var hcell = getById("hit_count_cell");
580 //hcell.appendChild(createAppElement("br"));
581 hcell.appendChild(createAppTextNode("0 hits were returned for you search"));
585 AbstractRecordResultPage.prototype.buildNextLinks = function() {
589 this.builtLinks = true;
595 debug("Building links");
596 if( this.searchOffset < (parseInt(this.hitCount) - this.hitsPerPage)) {
597 next = createAppElement("a");
598 add_css_class(next,"record_next_button");
599 add_css_class(next,"record_next_button_active");
600 next.href = "javascript:globalPage.next();";
602 next = createAppElement("span");
603 add_css_class(next,"record_next_button_inactive");
606 if(this.searchOffset > 0) {
607 prev = createAppElement("a");
608 add_css_class(prev,"record_next_button");
609 add_css_class(prev,"record_next_button_active");
610 prev.href = "javascript:globalPage.prev();";
612 prev = createAppElement("span");
613 add_css_class(prev,"record_next_button_inactive");
616 next.appendChild(createAppTextNode("Next"));
617 prev.appendChild(createAppTextNode("Previous"));
620 var i = this.searchOffset;
621 var max = parseInt(i) + this.hitsPerPage;
622 if( max > this.hitCount )
625 var hcell = getById("hit_count_cell");
626 var hcell2 = getById("hit_count_cell_2");
631 var ident = "Titles";
632 if(instanceOf(this, MRResultPage))
633 ident = "Title Groups";
636 createAppTextNode( "Displaying " + ident + " " +
637 ( parseInt(i) + 1 ) + " to " + max + " of " + this.hitCount));
639 hcell.appendChild(createAppTextNode(" "));
640 hcell.appendChild(createAppTextNode(" "));
641 hcell.appendChild(createAppTextNode(" "));
643 hcell.appendChild(prev);
644 var span = createAppElement("span");
645 span.appendChild(createAppTextNode(" ... "));
646 hcell.appendChild(span);
647 hcell.appendChild(next);
649 hcell2.innerHTML = hcell.innerHTML;
656 AbstractRecordResultPage.prototype.buildResourcePic = function(c, resource, parent) {
657 return buildResourcePic(c, resource, parent);
660 function buildResourcePic(c, resource, parent) {
662 var pic = createAppElement("img");
664 if(resource.indexOf("sound recording") != -1)
665 resource = "sound recording";
666 pic.setAttribute("src", "/images/" + resource + ".jpg");
667 pic.setAttribute("border", "0");
668 pic.className = "record_resource_pic";
669 pic.setAttribute("width", "20");
670 pic.setAttribute("height", "20");
671 pic.setAttribute("title", resource);
686 case "sound recording":
690 case "software, multimedia":
702 case "mixed material":
706 case "notated music":
710 case "three dimensional object":
718 c.childNodes[index].innerHTML = "";
721 parent.appendChild(pic);
722 c.childNodes[index].appendChild(parent);
724 c.childNodes[index].appendChild(pic);
728 AbstractRecordResultPage.prototype.buildRecordImage = function(pic_cell, record, page_id, title) {
730 debug("Building record image for " + page_id);
733 var isbn = record.isbn();
735 isbn = isbn.replace(/^\s+/,"");
736 var idx = isbn.indexOf(" ");
738 isbn = isbn.substring(0, idx);
744 pic_cell.setAttribute("rowspan","3");
745 pic_cell.rowSpan = 3;
747 pic_cell.noWrap = 'nowrap';
748 pic_cell.setAttribute("nowrap", "nowrap");
750 pic_cell.width = "60";
751 pic_cell.className = "record_image_cell";
755 if( this.ranks.length > 0 ) {
756 var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
757 var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
759 debug("Per is " + per);
760 per = 100 - parseInt(per);
762 rankBox = createAppElement("div");
763 add_css_class(rankBox, "relevance_box");
765 var d = createAppElement("div");
766 d.setAttribute("height", per + "%");
767 d.style.height = per + "%";
769 add_css_class(d, "relevance");
770 rankBox.appendChild(d);
772 rankBox.setAttribute("title", parseInt((100 - parseInt(per))) + "% Relevant");
775 /* use amazon for now */
776 //var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg";
777 //var img_src = "http://www.thecontentserver.com/bin/cntsvr.dll?GetImage&SysID=Content&CustID=Cafe&Return=1&Type=S&Key=" + isbn ;
779 var img_src = buildISBNSrc(cleanISBN(record.isbn()));
780 var big_div = createAppElement("div");
781 add_css_class(big_div, "record_image_big hide_me");
783 var big_pic = createAppElement("img");
784 var pic = createAppElement("img");
786 big_pic.setAttribute("src", img_src);
787 big_pic.setAttribute("border", "0");
788 pic.setAttribute("src", img_src);
789 add_css_class(big_pic, "record_image");
790 add_css_class(pic, "record_image");
792 pic.setAttribute("width", "45");
793 pic.setAttribute("height", "50");
794 pic.style.width = "45";
795 pic.style.height = "50";
798 big_div.style.left = 0;
801 var anch = this.mkLink(record.doc_id(), "img", title );
802 anch.appendChild(big_pic);
803 big_div.appendChild(anch);
804 pic_cell.appendChild(big_div);
806 pic_cell.appendChild(pic);
809 pic_cell.appendChild(rankBox);
811 pic.onmouseover = function() {showMe(big_div);}
812 big_div.onmouseout = function(){hideMe(big_div);}