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.buttonsBox = getById("record_next_prev_links_box_1");
21 this.prevButton = getById("record_prev_button_1");
22 this.nextButton = getById("record_next_button_1");
23 this.recordBox = getById("record_result_box");
25 this.subBox = getById("record_subject_sidebar_box");
26 this.authBox = getById("record_author_sidebar_box");
28 this.subBoxL = getById("record_subject_sidebar_box_label");
29 this.authBoxL = getById("record_author_sidebar_box_label");
31 this.hitsPerPage = 8; /* how many hits are displayed per page */
34 this.searchDepth = 0; /* default to the current search location */
35 this.statusBar = getById("top_status_bar_table");
36 this.theadDrawn = false;
37 this.bigOlBox = getById("big_ol_box");
43 /** Resets data structures for a new search */
44 AbstractRecordResultPage.prototype.resetPage = function() {
45 this.subBox.innerHTML = "";
46 this.authBox.innerHTML = "";
47 this.collectedSubjects = new Array();
48 this.collectedAuthors = new Array();
49 this.searchBar.reset();
50 var spot = getById("progress_bar_location");
51 var spot2 = getById("progress_bar_percent_location");
54 spot.removeChild(spot.lastChild);
56 /* progress items for each record and it's hit count listing */
57 this.progressBar = new ProgressBar(parseInt(this.hitsPerPage) * 2);
58 spot.appendChild(this.progressBar.getNode());
60 if(!this.progressBar.running()) {
61 //this.progressBar.start();
64 if(spot2 && this.progressBar)
65 spot2.appendChild(this.progressBar.percentDiv);
68 AbstractRecordResultPage.prototype.resetSearch = function() {
69 this.recordIDs = new Array();
70 this.ranks = new Array();
71 this.collectedSubjects = new Array(); /* subjects attached to the current batch of records */
72 this.collectedAuthors = new Array(); /* subjects attached to the current batch of records */
73 this.requestBatch = new Array(); /* current batch of RemoteRequest objects */
74 this.hitCount = 0; /* hits for the current search */
75 this.searchOffset = 0; /* the offset for the search display */
79 AbstractRecordResultPage.prototype.gatherIDs = function(result) {
81 this.hitCount = parseInt(result.count);
84 /* the 'ids' field consist of [record, rank] */
85 /* gather all of the ID's */
86 if( typeof result.ids == 'object' && result.ids[0].constructor == Array ) {
87 for( var i in result.ids ) {
88 if(result.ids[i]==null || result.ids[i][0] == null) break;
89 var offset = parseInt(i) + parseInt(this.searchOffset);
90 this.recordIDs[offset] = result.ids[i][0];
91 this.ranks[offset] = parseFloat(result.ids[i][1]);
92 debug("adding ranks[" + offset + "] = " + result.ids[i][1] +
93 " \nrecordIDs["+offset+"], result.ids["+i+"][0]");
98 for( var i in result.ids ) {
99 if(result.ids[i]==null) break;
100 var offset = parseInt(i) + parseInt(this.searchOffset);
101 this.recordIDs[offset] = result.ids[i];
102 debug("adding recordIDs["+offset+"], result.ids["+i+"]");
113 AbstractRecordResultPage.prototype.displayRecord =
114 function( record, search_id, page_id ) {
116 this.progressBar.manualNext();
118 var id = parseInt(page_id);
119 var title_row = table_row_find_or_create(this.recordBox, id * 2 + 1 );
120 var author_row = table_row_find_or_create(this.recordBox, id * 2 + 2 );
122 author_row.id = "record_result_author_row_" + id;
123 title_row.id = "record_result_title_row_" + id;
125 /* build the appropriate context node for this result */
126 var menu = globalMenuManager.buildMenu(
127 "record_result_row_" + page_id );
129 this.addMenuItems( menu, record );
130 globalMenuManager.setContext(title_row, menu);
131 globalMenuManager.setContext(author_row, menu);
132 getDocument().body.appendChild(menu.getNode());
133 /* ------------------------------------ */
136 var isbn = record.isbn();
137 if(isbn) isbn = isbn.replace(/\s+/,"");
140 var pic_cell = title_row.insertCell(0);
141 pic_cell.setAttribute("rowspan","2");
142 pic_cell.rowSpan = 2;
146 if( this.ranks.length > 0 ) {
147 debug("AAAAA " + this.page + " " + this.hitsPerPage + " " + page_id );
148 var x = (parseInt(this.page) * parseInt(this.hitsPerPage)) + parseInt(page_id);
149 debug( x + " Ranks: " + this.ranks[x] + " " + this.ranks[0] );
150 var per = parseInt(this.ranks[x] / this.ranks[0] * 100.0);
151 rankBox = "<div class='relevance_box'><div style='width:" +
152 per + "%' class='relevance'> </div></div>";
156 debug("Adding rank box " + rankBox );
158 pic_cell.innerHTML = rankBox +
159 "<img height='50' width='45' src='http://images.amazon.com/images/P/"
160 + isbn + ".01.MZZZZZZZ.jpg'>";
163 var title_cell = title_row.insertCell(title_row.cells.length);
164 title_cell.id = "record_result_title_box_" + id;
165 add_css_class( title_cell, "record_result_title_box");
167 var author_cell = author_row.insertCell(author_row.cells.length);
168 author_cell.id = "record_result_author_box_" + id;
169 add_css_class(author_cell, "record_result_author_box");
172 debug( "Displaying record title: " + record.title() + " author: " + record.author() );
174 /* limit the length of the title and author lines */
177 if( record.title() ) {
178 if(record.title().length > tlength) {
179 record.title(record.title().substr(0,tlength));
180 record.title(record.title() + "...");
182 record.title(normalize(record.title()));
185 if( record.author() ) {
186 if(record.author().length > tlength) {
187 record.author( record.author().substr(0,tlength));
188 record.author(record.author() + "...");
190 record.author(normalize(record.author()));
193 //title_cell.appendChild(createAppTextNode((parseInt(search_id) + 1) + ". "));
194 title_cell.appendChild(this.mkLink(record.doc_id(), "title", record.title()));
195 author_cell.innerHTML = " ";
196 author_cell.appendChild(this.mkLink(record.doc_id(), "author", record.author()));
198 var classname = "result_even";
200 classname = "result_odd";
202 add_css_class(title_row, classname);
203 add_css_class(author_row, classname);
205 /* now grab the record authors and subjects */
206 if( record.author() )
207 this.collectedAuthors[record.author()] = true;
209 /* gather the subjects. subjects are either a string or an array of
210 [subject, broader topic]. currently, they're all just treated like
212 var arr = record.subject();
213 for( var sub in arr ) {
216 if( ss.constructor != Array )
220 var s = normalize(ss[i]);
221 if( this.collectedSubjects[s])
222 this.collectedSubjects[s] += 1;
224 this.collectedSubjects[s] = 1;
228 /* after loading the last record, contine building the page */
230 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
231 (page_id == (parseInt(this.hitsPerPage) - 1) ))
235 AbstractRecordResultPage.prototype.finalizePage = function() {
236 /* sort the arrays */
237 this.collectedSubjects = this.collectedSubjects.sort().reverse();
238 this.collectedAuthors = this.collectedAuthors.sort().reverse();
240 showMe( this.subBox );
241 showMe( this.authBox );
242 showMe( this.subBoxL );
243 showMe( this.authBoxL );
246 debug("Collected Subjects: " + this.collectedSubjects[0] + ":" + this.collectedSubjects);
248 for(var sub in this.collectedSubjects) {
249 debug("makeing subject link: " + sub);
252 var href = createAppElement("a");
253 add_css_class(href,"record_result_sidebar_link");
254 href.setAttribute("href","?target=mr_result&mr_search_type=subject&page=0&mr_search_query=" +
255 encodeURIComponent(sub));
256 href.appendChild(createAppTextNode(sub));
257 this.subBox.appendChild(href);
258 this.subBox.innerHTML += "<br/>";
262 for(var auth in this.collectedAuthors) {
265 var href = createAppElement("a");
266 add_css_class(href,"record_result_sidebar_link");
267 href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
268 encodeURIComponent(auth));
269 href.appendChild(createAppTextNode(auth));
270 this.authBox.appendChild(href);
271 this.authBox.innerHTML += "<br/>";
274 showMe(this.buttonsBox);
276 if( this.searchOffset < (parseInt(this.hitCount) - this.hitsPerPage))
277 showMe(this.nextButton);
278 if(this.searchOffset > 0)
279 showMe(this.prevButton);
283 var box = getById("record_survey_sidebar_box");
284 var ses = UserSession.instance().getSessionId();
288 showMe(getById("record_survey_sidebar_box_label"));
289 Survey.retrieveRandom(ses,
291 var name = sur.getName();
292 sur.setAction( function() { alert("Submitted Survey: " + name); } );
293 box.appendChild( sur.getNode() );
299 var spot = getById("record_sidebar_box");
300 spot.style.border = "1px solid green";
301 spot.appendChild(createAppElement("br"));
302 var sidebar = new Sidebar();
303 var sidebarbox = new SidebarBox("Test");
304 sidebarbox.addItem(createAppTextNode("Hello"));
305 sidebarbox.addItem(createAppTextNode("Hello2"));
306 sidebar.addItem(sidebarbox);
307 spot.appendChild(sidebar.getNode());
313 AbstractRecordResultPage.prototype.displayCopyCounts =
314 function(copy_counts, search_id, page_id) {
316 this.progressBar.manualNext();
317 var titlerow = getById("record_result_title_row_" + page_id );
318 var authorrow = getById("record_result_author_row_" + page_id );
320 var tcell = getById("record_result_title_box_" + page_id );
322 if(!this.theadDrawn) {
323 var trow = getById("record_result_thead_row");
324 for( var i in copy_counts) {
325 var cell = trow.insertCell(trow.cells.length);
326 add_css_class(cell,"record_result_thead_header");
328 findOrgType(findOrgUnit(copy_counts[i].org_unit).ou_type()).name();
330 this.theadDrawn = true;
333 for( var i in copy_counts) {
334 var cell = createAppElement("td");
335 add_css_class(cell, "copy_count_cell");
336 cell.innerHTML = copy_counts[i].available + " / " + copy_counts[i].count;
337 cell.setAttribute("rowspan","2");
339 titlerow.appendChild(cell);
342 if(page_id == (parseInt(this.hitsPerPage) - 1) ) {
343 if(this.progressBar) this.progressBar.stop();
344 showMe(this.bigOlBox);
347 if( (page_id == ((parseInt(this.hitCount) - 1 ) - parseInt(this.searchOffset))) ||
348 (page_id == (parseInt(this.hitsPerPage) - 1) ))
349 if(this.progressBar) this.progressBar.stop();