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.sortByCount();
26 this.subjectBox = new Box();
27 this.subjectBox.init("Relevant Subjects", true, true, 15);
28 this.subjectBox.sortByCount();
30 this.sidebarBox = getById("record_sidebar_box");
33 this.hitsPerPage = 8; /* how many hits are displayed per page */
36 this.statusBar = getById("top_status_bar_table");
37 this.theadDrawn = false;
38 this.bigOlBox = getById("big_ol_box");
44 /** Resets data structures for a new search */
45 AbstractRecordResultPage.prototype.resetPage = function() {
46 this.searchBar.reset();
47 var spot = getById("progress_bar_location");
48 var spot2 = getById("progress_bar_percent_location");
51 spot.removeChild(spot.lastChild);
53 /* progress items for each record and it's hit count listing */
54 this.progressBar = new ProgressBar(parseInt(this.hitsPerPage) * 2);
55 spot.appendChild(this.progressBar.getNode());
57 if(spot2 && this.progressBar)
58 spot2.appendChild(this.progressBar.percentDiv);
61 this.requestBatch = new RequestBatch();
62 this.finalized = false;
65 AbstractRecordResultPage.prototype.resetSearch = function() {
66 this.recordIDs = new Array();
67 this.ranks = new Array();
68 this.hitCount = 0; /* hits for the current search */
69 this.searchOffset = 0; /* the offset for the search display */
73 AbstractRecordResultPage.prototype.gatherIDs = function(result) {
75 this.hitCount = parseInt(result.count);
76 if(this.hitCount < 1 ) {
82 /* the 'ids' field consist of [record, rank] */
83 /* gather all of the ID's */
84 if( result.ids && typeof result.ids == 'object'
85 && result.ids[0] != null
86 && result.ids[0].constructor == Array ) {
88 for( var i in result.ids ) {
89 if(result.ids[i]==null || result.ids[i][0] == null) break;
90 var offset = parseInt(i) + parseInt(this.searchOffset);
91 this.recordIDs[offset] = result.ids[i][0];
92 var rank = parseFloat(result.ids[i][1]);
94 rank = 0.00000001; /* protect divide by 0 */
95 this.ranks[offset] = rank;
97 debug("adding ranks[" + offset + "] = " + result.ids[i][1] +
98 " \nrecordIDs["+offset+"], result.ids["+i+"][0]");
104 for( var i in result.ids ) {
105 if(result.ids[i]==null) break;
106 var offset = parseInt(i) + parseInt(this.searchOffset);
107 this.recordIDs[offset] = result.ids[i];
108 debug("adding recordIDs["+offset+"], result.ids["+i+"]");
117 AbstractRecordResultPage.prototype.complete = function() {
122 AbstractRecordResultPage.prototype.displayRecord =
123 function( record, search_id, page_id ) {
126 this.buildNextLinks();
130 this.progressBar.manualNext();
132 var id = parseInt(page_id);
133 var title_row = table_row_find_or_create(this.recordBox, id * 2 + 1 );
134 var author_row = table_row_find_or_create(this.recordBox, id * 2 + 2 );
136 author_row.id = "record_result_author_row_" + id;
137 title_row.id = "record_result_title_row_" + id;
139 /* build the appropriate context node for this result */
140 var menu = globalMenuManager.buildMenu(
141 "record_result_row_" + page_id );
143 this.addMenuItems( menu, record );
144 globalMenuManager.setContext(title_row, menu);
145 globalMenuManager.setContext(author_row, menu);
146 getDocument().body.appendChild(menu.getNode());
147 /* ------------------------------------ */
150 var isbn = record.isbn();
151 if(isbn) isbn = isbn.replace(/\s+/,"");
154 var pic_cell = title_row.insertCell(0);
155 pic_cell.setAttribute("rowspan","2");
156 pic_cell.rowSpan = 2;
160 if( this.ranks.length > 0 ) {
161 var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
162 var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
163 rankBox = "<div class='relevance_box'><div style='width:" +
164 per + "%' class='relevance'> </div></div>";
168 /* pull from amazon for now... */
169 pic_cell.innerHTML = rankBox +
170 "<img height='50' width='45' src='http://images.amazon.com/images/P/"
171 + isbn + ".01.MZZZZZZZ.jpg'>";
174 var title_cell = title_row.insertCell(title_row.cells.length);
175 title_cell.id = "record_result_title_box_" + id;
176 add_css_class( title_cell, "record_result_title_box");
178 var author_cell = author_row.insertCell(author_row.cells.length);
179 author_cell.id = "record_result_author_box_" + id;
180 add_css_class(author_cell, "record_result_author_box");
183 /* limit the length of the title and author lines */
186 if( record.title() ) {
187 if(record.title().length > tlength) {
188 record.title(record.title().substr(0,tlength));
189 record.title(record.title() + "...");
191 record.title(normalize(record.title()));
194 if( record.author() ) {
195 if(record.author().length > tlength) {
196 record.author( record.author().substr(0,tlength));
197 record.author(record.author() + "...");
199 record.author(normalize(record.author()));
202 title_cell.appendChild(this.mkLink(record.doc_id(), "title", record.title()));
203 author_cell.innerHTML = " ";
204 author_cell.appendChild(this.mkLink(record.doc_id(), "author", record.author()));
206 var classname = "result_even";
208 classname = "result_odd";
210 add_css_class(title_row, classname);
211 add_css_class(author_row, classname);
213 /* now grab the record authors and subjects */
214 if( record.author() ) {
215 this.authorBox.addItem( this.mkAuthorLink(record.author()), record.author() );
218 /* gather the subjects. subjects are either a string or an array of
219 [subject, broader topic]. currently, they're all just treated like
221 var arr = record.subject();
222 for( var sub in arr ) {
225 if( ss.constructor != Array )
229 var s = normalize(ss[i]);
230 this.subjectBox.addItem( this.mkSubjectLink(s), s );
234 /* requestBatch will only have one request in it when the current
235 record is the last record requested */
236 if( this.requestBatch.pending() < 2 )
240 AbstractRecordResultPage.prototype.mkAuthorLink = function(auth) {
241 var href = createAppElement("a");
242 add_css_class(href,"record_result_sidebar_link");
243 href.setAttribute("href",
244 "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
245 encodeURIComponent(auth));
246 href.appendChild(createAppTextNode(auth));
250 AbstractRecordResultPage.prototype.mkSubjectLink = function(sub) {
251 var href = createAppElement("a");
252 add_css_class(href,"record_result_sidebar_link");
253 href.setAttribute("href",
254 "?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
255 encodeURIComponent(sub));
256 href.appendChild(createAppTextNode(sub));
260 AbstractRecordResultPage.prototype.finalizePage = function() {
264 this.finalized = true;
266 this.subjectBox.finalize();
267 this.authorBox.finalize();
269 this.sidebarBox.appendChild(this.subjectBox.getNode());
270 this.sidebarBox.appendChild(createAppElement("br"));
271 this.sidebarBox.appendChild(this.authorBox.getNode());
272 this.sidebarBox.appendChild(createAppElement("br"));
274 // showMe(this.buttonsBox);
276 var ses = UserSession.instance().getSessionId();
277 var box = this.sidebarBox;
280 Survey.retrieveOpacRandom(ses,
282 sur.setSubmitCallback(
283 function() { alert("Thanks!"); return true; });
284 box.appendChild( sur.getNode() );
285 sur.setHidden(false);
289 Survey.retrieveOpacRandomGlobal(
291 sur.setSubmitCallback(
292 function() { alert("Thanks!"); return true; });
293 box.appendChild( sur.getNode() );
294 sur.setHidden(false);
300 if(this.hitCount < 1)
301 if(this.progressBar) this.progressBar.stop();
303 /* in case we're hidden */
304 showMe(this.bigOlBox);
309 AbstractRecordResultPage.prototype.displayCopyCounts =
310 function(copy_counts, search_id, page_id) {
312 this.progressBar.manualNext();
313 var titlerow = getById("record_result_title_row_" + page_id );
314 var authorrow = getById("record_result_author_row_" + page_id );
316 var tcell = getById("record_result_title_box_" + page_id );
318 if(!this.theadDrawn) {
319 var trow = getById("record_result_thead_row");
320 for( var i in copy_counts) {
321 var cell = trow.insertCell(trow.cells.length);
322 add_css_class(cell,"record_result_thead_header");
324 findOrgType(findOrgUnit(copy_counts[i].org_unit).ou_type()).name();
326 this.theadDrawn = true;
329 for( var i in copy_counts) {
330 var cell = createAppElement("td");
331 add_css_class(cell, "copy_count_cell");
332 cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
333 cell.setAttribute("rowspan","2");
335 titlerow.appendChild(cell);
338 if(page_id == (parseInt(this.hitsPerPage) - 1) ) {
339 if(this.progressBar) this.progressBar.stop();
342 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
343 (page_id == (parseInt(this.hitsPerPage) - 1) ))
344 if(this.progressBar) this.progressBar.stop();
349 AbstractRecordResultPage.prototype.buildNextLinks = function() {
356 debug("Building links");
357 if( this.searchOffset < (parseInt(this.hitCount) - this.hitsPerPage)) {
358 next = createAppElement("a");
359 add_css_class(next,"record_next_button");
360 add_css_class(next,"record_next_button_active");
361 next.href = "javascript:globalPage.next();";
363 next = createAppElement("span");
364 add_css_class(next,"record_next_button_inactive");
367 if(this.searchOffset > 0) {
368 prev = createAppElement("a");
369 add_css_class(prev,"record_next_button");
370 add_css_class(prev,"record_next_button_active");
371 prev.href = "javascript:globalPage.prev();";
373 prev = createAppElement("span");
374 add_css_class(prev,"record_next_button_inactive");
377 next.appendChild(createAppTextNode("Next"));
378 prev.appendChild(createAppTextNode("Previous"));
381 var i = this.searchOffset;
382 var max = parseInt(i) + this.hitsPerPage;
383 if( max > this.hitCount )
386 var hcell = getById("hit_count_cell");
389 createAppTextNode( "Displaying " +
390 ( parseInt(i) + 1 ) + " to " + max + " of " + this.hitCount));
392 hcell.appendChild(createAppTextNode(" "));
393 hcell.appendChild(createAppTextNode(" "));
394 hcell.appendChild(createAppTextNode(" "));
397 var div = createAppElement("div");
398 div.appendChild(createAppTextNode("."));
399 div.setAttribute("style", "color:#FFF;float:left;width:10px;border:1px solid black;position:relative");
400 hcell.appendChild(div);
403 hcell.appendChild(prev);
404 var span = createAppElement("span");
405 span.appendChild(createAppTextNode(" ... "));
406 hcell.appendChild(span);
407 hcell.appendChild(next);