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 this.ranks[offset] = parseFloat(result.ids[i][1]);
94 debug("adding ranks[" + offset + "] = " + result.ids[i][1] +
95 " \nrecordIDs["+offset+"], result.ids["+i+"][0]");
101 for( var i in result.ids ) {
102 if(result.ids[i]==null) break;
103 var offset = parseInt(i) + parseInt(this.searchOffset);
104 this.recordIDs[offset] = result.ids[i];
105 debug("adding recordIDs["+offset+"], result.ids["+i+"]");
114 AbstractRecordResultPage.prototype.complete = function() {
119 AbstractRecordResultPage.prototype.displayRecord =
120 function( record, search_id, page_id ) {
123 this.buildNextLinks();
127 this.progressBar.manualNext();
129 var id = parseInt(page_id);
130 var title_row = table_row_find_or_create(this.recordBox, id * 2 + 1 );
131 var author_row = table_row_find_or_create(this.recordBox, id * 2 + 2 );
133 author_row.id = "record_result_author_row_" + id;
134 title_row.id = "record_result_title_row_" + id;
136 /* build the appropriate context node for this result */
137 var menu = globalMenuManager.buildMenu(
138 "record_result_row_" + page_id );
140 this.addMenuItems( menu, record );
141 globalMenuManager.setContext(title_row, menu);
142 globalMenuManager.setContext(author_row, menu);
143 getDocument().body.appendChild(menu.getNode());
144 /* ------------------------------------ */
147 var isbn = record.isbn();
148 if(isbn) isbn = isbn.replace(/\s+/,"");
151 var pic_cell = title_row.insertCell(0);
152 pic_cell.setAttribute("rowspan","2");
153 pic_cell.rowSpan = 2;
157 if( this.ranks.length > 0 ) {
158 var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
159 var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
160 rankBox = "<div class='relevance_box'><div style='width:" +
161 per + "%' class='relevance'> </div></div>";
165 /* pull from amazon for now... */
166 pic_cell.innerHTML = rankBox +
167 "<img height='50' width='45' src='http://images.amazon.com/images/P/"
168 + isbn + ".01.MZZZZZZZ.jpg'>";
171 var title_cell = title_row.insertCell(title_row.cells.length);
172 title_cell.id = "record_result_title_box_" + id;
173 add_css_class( title_cell, "record_result_title_box");
175 var author_cell = author_row.insertCell(author_row.cells.length);
176 author_cell.id = "record_result_author_box_" + id;
177 add_css_class(author_cell, "record_result_author_box");
180 /* limit the length of the title and author lines */
183 if( record.title() ) {
184 if(record.title().length > tlength) {
185 record.title(record.title().substr(0,tlength));
186 record.title(record.title() + "...");
188 record.title(normalize(record.title()));
191 if( record.author() ) {
192 if(record.author().length > tlength) {
193 record.author( record.author().substr(0,tlength));
194 record.author(record.author() + "...");
196 record.author(normalize(record.author()));
199 title_cell.appendChild(this.mkLink(record.doc_id(), "title", record.title()));
200 author_cell.innerHTML = " ";
201 author_cell.appendChild(this.mkLink(record.doc_id(), "author", record.author()));
203 var classname = "result_even";
205 classname = "result_odd";
207 add_css_class(title_row, classname);
208 add_css_class(author_row, classname);
210 /* now grab the record authors and subjects */
211 if( record.author() ) {
212 this.authorBox.addItem( this.mkAuthorLink(record.author()), record.author() );
215 /* gather the subjects. subjects are either a string or an array of
216 [subject, broader topic]. currently, they're all just treated like
218 var arr = record.subject();
219 for( var sub in arr ) {
222 if( ss.constructor != Array )
226 var s = normalize(ss[i]);
227 this.subjectBox.addItem( this.mkSubjectLink(s), s );
231 /* requestBatch will only have one request in it when the current
232 record is the last record requested */
233 if( this.requestBatch.pending() < 2 )
237 AbstractRecordResultPage.prototype.mkAuthorLink = function(auth) {
238 var href = createAppElement("a");
239 add_css_class(href,"record_result_sidebar_link");
240 href.setAttribute("href",
241 "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
242 encodeURIComponent(auth));
243 href.appendChild(createAppTextNode(auth));
247 AbstractRecordResultPage.prototype.mkSubjectLink = function(sub) {
248 var href = createAppElement("a");
249 add_css_class(href,"record_result_sidebar_link");
250 href.setAttribute("href",
251 "?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
252 encodeURIComponent(sub));
253 href.appendChild(createAppTextNode(sub));
257 AbstractRecordResultPage.prototype.finalizePage = function() {
261 this.finalized = true;
263 this.subjectBox.finalize();
264 this.authorBox.finalize();
266 this.sidebarBox.appendChild(this.subjectBox.getNode());
267 this.sidebarBox.appendChild(createAppElement("br"));
268 this.sidebarBox.appendChild(this.authorBox.getNode());
269 this.sidebarBox.appendChild(createAppElement("br"));
271 // showMe(this.buttonsBox);
273 var ses = UserSession.instance().getSessionId();
274 var box = this.sidebarBox;
277 Survey.retrieveOpacRandom(ses,
279 sur.setSubmitCallback(
280 function() { alert("Thanks!"); return true; });
281 box.appendChild( sur.getNode() );
282 sur.setHidden(false);
286 Survey.retrieveOpacRandomGlobal(
288 sur.setSubmitCallback(
289 function() { alert("Thanks!"); return true; });
290 box.appendChild( sur.getNode() );
291 sur.setHidden(false);
297 if(this.hitCount < 1)
298 if(this.progressBar) this.progressBar.stop();
300 /* in case we're hidden */
301 showMe(this.bigOlBox);
306 AbstractRecordResultPage.prototype.displayCopyCounts =
307 function(copy_counts, search_id, page_id) {
309 this.progressBar.manualNext();
310 var titlerow = getById("record_result_title_row_" + page_id );
311 var authorrow = getById("record_result_author_row_" + page_id );
313 var tcell = getById("record_result_title_box_" + page_id );
315 if(!this.theadDrawn) {
316 var trow = getById("record_result_thead_row");
317 for( var i in copy_counts) {
318 var cell = trow.insertCell(trow.cells.length);
319 add_css_class(cell,"record_result_thead_header");
321 findOrgType(findOrgUnit(copy_counts[i].org_unit).ou_type()).name();
323 this.theadDrawn = true;
326 for( var i in copy_counts) {
327 var cell = createAppElement("td");
328 add_css_class(cell, "copy_count_cell");
329 cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
330 cell.setAttribute("rowspan","2");
332 titlerow.appendChild(cell);
335 if(page_id == (parseInt(this.hitsPerPage) - 1) ) {
336 if(this.progressBar) this.progressBar.stop();
339 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
340 (page_id == (parseInt(this.hitsPerPage) - 1) ))
341 if(this.progressBar) this.progressBar.stop();
346 AbstractRecordResultPage.prototype.buildNextLinks = function() {
353 debug("Building links");
354 if( this.searchOffset < (parseInt(this.hitCount) - this.hitsPerPage)) {
355 next = createAppElement("a");
356 add_css_class(next,"record_next_button");
357 add_css_class(next,"record_next_button_active");
358 next.href = "javascript:globalPage.next();";
360 next = createAppElement("span");
361 add_css_class(next,"record_next_button_inactive");
364 if(this.searchOffset > 0) {
365 prev = createAppElement("a");
366 add_css_class(prev,"record_next_button");
367 add_css_class(prev,"record_next_button_active");
368 prev.href = "javascript:globalPage.prev();";
370 prev = createAppElement("span");
371 add_css_class(prev,"record_next_button_inactive");
374 next.appendChild(createAppTextNode("Next"));
375 prev.appendChild(createAppTextNode("Previous"));
378 var i = this.searchOffset;
379 var max = parseInt(i) + this.hitsPerPage;
380 if( max > this.hitCount )
383 var hcell = getById("hit_count_cell");
386 createAppTextNode( "Displaying " +
387 ( parseInt(i) + 1 ) + " to " + max + " of " + this.hitCount));
389 hcell.appendChild(createAppTextNode(" "));
390 hcell.appendChild(createAppTextNode(" "));
391 hcell.appendChild(createAppTextNode(" "));
394 var div = createAppElement("div");
395 div.appendChild(createAppTextNode("."));
396 div.setAttribute("style", "color:#FFF;float:left;width:10px;border:1px solid black;position:relative");
397 hcell.appendChild(div);
400 hcell.appendChild(prev);
401 var span = createAppElement("span");
402 span.appendChild(createAppTextNode(" ... "));
403 hcell.appendChild(span);
404 hcell.appendChild(next);