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 ));
292 if(instanceOf(this, RecordResultPage)) {
293 var span = createAppElement("span");
294 span.style.marginLeft = "10px";
296 if(record.pubdate() || record.edition())
297 span.appendChild(createAppTextNode(" -- "));
300 span.appendChild(createAppTextNode(" " + record.pubdate()));
303 span.appendChild(createAppTextNode(" " + record.edition()));
305 author_cell.appendChild(span);
307 var marcb = elem( "a",
308 { href:"javascript:void(0)",
309 style: "text-decoration:underline;"
310 }, null, "View MARC" );
312 debug("Setting up view marc callback with record " + record.doc_id());
313 var func = buildViewMARCWindow(record);
314 marcb.onclick = func;
316 marcd = elem( "div", { style: "float:right;font-size:x-small;" } );
317 marcd.appendChild(marcb);
323 if(instanceOf(this, RecordResultPage)) {
325 var holds = elem( "a",
327 href:"javascript:void(0)",
328 style: "text-decoration:underline"
329 }, {}, "Place Hold" );
333 if(instanceOf(this, RecordResultPage))
337 var user = UserSession.instance();
338 if(user.verifySession()) {
339 win = new HoldsWindow(record.doc_id(),
340 type, user.userObject, user.userObject, user.session_id);
342 win = new HoldsWindow(record.doc_id(),
343 type, null, null, null);
347 holds.onclick = function() { win.toggle(holds); }
348 holddiv = elem("div");
350 holddiv.setAttribute("style", "float:right");
351 holddiv.appendChild(holds);
354 var tab = elem("table",{style:"float:right"});
355 var tr = tab.insertRow(0);
356 var tc = tr.insertCell(0);
357 var tc2 = tr.insertCell(1);
358 var tc3 = tr.insertCell(2);
359 tc.setAttribute("nowrap", "nowrap");
360 tc3.setAttribute("nowrap", "nowrap");
362 if(holddiv) tc.appendChild(holddiv);
363 tc2.appendChild(mktext(" "));
364 //if(marcd) tc3.appendChild(marcd);
370 var classname = "result_even";
371 if((page_id % 2) != 0)
372 classname = "result_odd";
374 add_css_class(title_row, classname);
375 add_css_class(author_row, classname);
376 add_css_class(misc_row, classname);
378 /* now grab the record authors and subjects */
380 this.authorBox.addItem( this.mkAuthorLink(author) , author);
383 /* gather the subjects. subjects are either a string or an array of
384 [subject, broader topic]. currently, they're all just treated like
386 var arr = record.subject();
388 for( var sub in arr ) {
389 if(x++ > 5) break; /* too many subjects makes things real sluggish */
393 /* only taking first part of subject (non-topic, etc.) */
394 if( ss.constructor == Array)
397 if( ss.constructor != Array )
401 var s = normalize(ss[i]);
402 this.subjectBox.addItem( this.mkSubjectLink(s), s );
406 var series = record.series();
407 for( var s in series ) {
408 debug("Found series entry: " + series[s] );
409 var ss = normalize(series[s]);
410 this.seriesBox.addItem( this.mkSeriesLink(ss), ss );
413 /* requestBatch will only have one request in it when the current
414 record is the last record requested */
415 if( this.requestBatch.pending() < 2 )
418 debug("Finished displaying record " + record.doc_id());
421 AbstractRecordResultPage.prototype.mkAuthorLink = function(auth) {
422 var href = createAppElement("a");
423 add_css_class(href,"record_result_sidebar_link");
425 href.setAttribute("href",
426 "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
427 encodeURIComponent(auth) +
428 "&mr_search_depth=" + this.searchDepth +
429 "&mr_search_location=" + this.searchLocation +
430 "&location=" + this.searchLocation +
431 "&format=" + this.format +
432 "&depth=" + this.searchDepth);
434 href.appendChild(createAppTextNode(auth));
435 href.title = "Author search for " + auth;
439 AbstractRecordResultPage.prototype.mkSeriesLink = function(series) {
440 var href = createAppElement("a");
441 add_css_class(href,"record_result_sidebar_link");
443 debug("Series: " + series + " : " + encodeURIComponent(series));
445 href.setAttribute("href",
446 "?target=mr_result&mr_search_type=series&page=0&mr_search_query=" +
447 encodeURIComponent(series) +
448 "&mr_search_depth=" + this.searchDepth +
449 "&mr_search_location=" + this.searchLocation +
450 "&location=" + this.searchLocation +
451 "&format=" + this.format +
452 "&depth=" + this.searchDepth);
454 href.appendChild(createAppTextNode(series));
455 href.title = "Series search for " + series;
459 AbstractRecordResultPage.prototype.mkSubjectLink = function(sub) {
460 var href = createAppElement("a");
461 add_css_class(href,"record_result_sidebar_link");
462 href.setAttribute("href",
463 "?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
464 encodeURIComponent(sub) +
465 "&mr_search_depth=" + this.searchDepth +
466 "&mr_search_location=" + this.searchLocation +
467 "&location=" + this.searchLocation +
468 "&format=" + this.format +
469 "&depth=" + this.searchDepth);
471 href.appendChild(createAppTextNode(sub));
472 href.title = "Subject search for " + sub;
476 AbstractRecordResultPage.prototype.finalizePage = function() {
480 this.finalized = true;
483 this.subjectBox.finalize();
484 this.authorBox.finalize();
485 this.seriesBox.finalize();
487 this.sidebarBox.appendChild(this.subjectBox.getNode());
488 this.sidebarBox.appendChild(createAppElement("br"));
490 this.sidebarBox.appendChild(this.authorBox.getNode());
491 this.sidebarBox.appendChild(createAppElement("br"));
493 this.sidebarBox.appendChild(this.seriesBox.getNode());
494 this.sidebarBox.appendChild(createAppElement("br"));
496 // showMe(this.buttonsBox);
498 var ses = UserSession.instance().getSessionId();
499 var box = this.sidebarBox;
502 Survey.retrieveOpacRandom(ses,
504 sur.setSubmitCallback(
505 function() { alert("Thanks!"); return true; });
506 box.appendChild( sur.getNode() );
507 sur.setHidden(false);
511 Survey.retrieveOpacRandomGlobal(
513 sur.setSubmitCallback(
514 function() { alert("Thanks!"); return true; });
515 box.appendChild( sur.getNode() );
516 sur.setHidden(false);
522 if(this.hitCount < 1) {
523 if(this.progressBar) this.progressBar.stop();
526 /* in case we're hidden */
527 showMe(this.bigOlBox);
528 showMe(getById("hit_count_cell_2"));
533 AbstractRecordResultPage.prototype.displayCopyCounts =
534 function(copy_counts, search_id, page_id) {
536 this.progressBar.manualNext();
537 var titlerow = getById("record_result_title_row_" + page_id );
538 var authorrow = getById("record_result_author_row_" + page_id );
540 var tcell = getById("record_result_title_box_" + page_id );
542 if(!this.theadDrawn) {
543 var trow = getById("record_result_thead_row");
544 for( var i in copy_counts) {
545 var cell = trow.insertCell(trow.cells.length);
546 add_css_class(cell,"record_result_thead_header");
548 findOrgType(findOrgUnit(
549 copy_counts[i].org_unit).ou_type()).opac_label();
551 this.theadDrawn = true;
554 for( var i in copy_counts) {
555 var cell = createAppElement("td");
556 add_css_class(cell, "copy_count_cell");
557 cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
558 cell.setAttribute("rowspan","3");
560 cell.title = " Availabie Copies / Total Copies";
561 titlerow.appendChild(cell);
564 if(page_id == (parseInt(this.hitsPerPage) - 1) ) {
565 if(this.progressBar) this.progressBar.stop();
566 if(this.hitCount < 1)
570 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
571 (page_id == (parseInt(this.hitsPerPage) - 1) ))
572 if(this.progressBar) this.progressBar.stop();
577 AbstractRecordResultPage.prototype.noHits = function() {
578 var hcell = getById("hit_count_cell");
579 //hcell.appendChild(createAppElement("br"));
580 hcell.appendChild(createAppTextNode("0 hits were returned for you search"));
584 AbstractRecordResultPage.prototype.buildNextLinks = function() {
588 this.builtLinks = true;
594 debug("Building links");
595 if( this.searchOffset < (parseInt(this.hitCount) - this.hitsPerPage)) {
596 next = createAppElement("a");
597 add_css_class(next,"record_next_button");
598 add_css_class(next,"record_next_button_active");
599 next.href = "javascript:globalPage.next();";
601 next = createAppElement("span");
602 add_css_class(next,"record_next_button_inactive");
605 if(this.searchOffset > 0) {
606 prev = createAppElement("a");
607 add_css_class(prev,"record_next_button");
608 add_css_class(prev,"record_next_button_active");
609 prev.href = "javascript:globalPage.prev();";
611 prev = createAppElement("span");
612 add_css_class(prev,"record_next_button_inactive");
615 next.appendChild(createAppTextNode("Next"));
616 prev.appendChild(createAppTextNode("Previous"));
619 var i = this.searchOffset;
620 var max = parseInt(i) + this.hitsPerPage;
621 if( max > this.hitCount )
624 var hcell = getById("hit_count_cell");
625 var hcell2 = getById("hit_count_cell_2");
630 var ident = "Titles";
631 if(instanceOf(this, MRResultPage))
632 ident = "Title Groups";
635 createAppTextNode( "Displaying " + ident + " " +
636 ( parseInt(i) + 1 ) + " to " + max + " of " + this.hitCount));
638 hcell.appendChild(createAppTextNode(" "));
639 hcell.appendChild(createAppTextNode(" "));
640 hcell.appendChild(createAppTextNode(" "));
642 hcell.appendChild(prev);
643 var span = createAppElement("span");
644 span.appendChild(createAppTextNode(" ... "));
645 hcell.appendChild(span);
646 hcell.appendChild(next);
648 hcell2.innerHTML = hcell.innerHTML;
655 AbstractRecordResultPage.prototype.buildResourcePic = function(c, resource, parent) {
656 return buildResourcePic(c, resource, parent);
659 function buildResourcePic(c, resource, parent) {
661 var pic = createAppElement("img");
663 if(resource.indexOf("sound recording") != -1)
664 resource = "sound recording";
665 pic.setAttribute("src", "/images/" + resource + ".jpg");
666 pic.setAttribute("border", "0");
667 pic.className = "record_resource_pic";
668 pic.setAttribute("width", "20");
669 pic.setAttribute("height", "20");
670 pic.setAttribute("title", resource);
685 case "sound recording":
689 case "software, multimedia":
701 case "mixed material":
705 case "notated music":
709 case "three dimensional object":
717 c.childNodes[index].innerHTML = "";
720 parent.appendChild(pic);
721 c.childNodes[index].appendChild(parent);
723 c.childNodes[index].appendChild(pic);
727 AbstractRecordResultPage.prototype.buildRecordImage = function(pic_cell, record, page_id, title) {
729 debug("Building record image for " + page_id);
732 var isbn = record.isbn();
734 isbn = isbn.replace(/^\s+/,"");
735 var idx = isbn.indexOf(" ");
737 isbn = isbn.substring(0, idx);
743 pic_cell.setAttribute("rowspan","3");
744 pic_cell.rowSpan = 3;
746 pic_cell.noWrap = 'nowrap';
747 pic_cell.setAttribute("nowrap", "nowrap");
749 pic_cell.width = "60";
750 pic_cell.className = "record_image_cell";
754 if( this.ranks.length > 0 ) {
755 var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
756 var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
758 debug("Per is " + per);
759 per = 100 - parseInt(per);
761 rankBox = createAppElement("div");
762 add_css_class(rankBox, "relevance_box");
764 var d = createAppElement("div");
765 d.setAttribute("height", per + "%");
766 d.style.height = per + "%";
768 add_css_class(d, "relevance");
769 rankBox.appendChild(d);
771 rankBox.setAttribute("title", parseInt((100 - parseInt(per))) + "% Relevant");
774 /* use amazon for now */
775 //var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg";
776 //var img_src = "http://www.thecontentserver.com/bin/cntsvr.dll?GetImage&SysID=Content&CustID=Cafe&Return=1&Type=S&Key=" + isbn ;
778 var img_src = buildISBNSrc(cleanISBN(record.isbn()));
779 var big_div = createAppElement("div");
780 add_css_class(big_div, "record_image_big hide_me");
782 var big_pic = createAppElement("img");
783 var pic = createAppElement("img");
785 big_pic.setAttribute("src", img_src);
786 big_pic.setAttribute("border", "0");
787 pic.setAttribute("src", img_src);
788 add_css_class(big_pic, "record_image");
789 add_css_class(pic, "record_image");
791 pic.setAttribute("width", "45");
792 pic.setAttribute("height", "50");
793 pic.style.width = "45";
794 pic.style.height = "50";
797 big_div.style.left = 0;
800 var anch = this.mkLink(record.doc_id(), "img", title );
801 anch.appendChild(big_pic);
802 big_div.appendChild(anch);
803 pic_cell.appendChild(big_div);
805 pic_cell.appendChild(pic);
808 pic_cell.appendChild(rankBox);
810 pic.onmouseover = function() {showMe(big_div);}
811 big_div.onmouseout = function(){hideMe(big_div);}