1 var globalMRResultPage = null; /* our global object */
3 MRResultPage.prototype = new AbstractRecordResultPage();
4 MRResultPage.prototype.constructor = MRResultPage;
5 MRResultPage.baseClass = AbstractRecordResultPage.constructor;
7 /* constructor for our singleton object */
8 function MRResultPage() {
9 debug("MRResultPage()");
10 //this.searchBar = new SearchBarChunk();
12 if( globalMRResultPage != null ) {
13 debug("MRResultPage() exists, returning");
14 return globalMRResultPage;
17 //this.progressBar = new ProgressBar(getById('progress_bar'));
19 globalMRResultPage = this;
23 /* returns the global instance. builds the instance if necessary. All client
24 * code should use this method */
25 MRResultPage.instance = function() {
26 if( globalMRResultPage != null ) {
27 return globalMRResultPage;
29 return new MRResultPage();
32 MRResultPage.prototype.next = function() {
34 "target", "mr_result",
35 "mr_search_type", this.stype,
36 "mr_search_query", this.string,
42 MRResultPage.prototype.prev = function() {
43 if(this.page == 0 ) return;
45 "target", "mr_result",
46 "mr_search_type", this.stype,
47 "mr_search_query", this.string,
53 MRResultPage.prototype.addMenuItems = function(menu, record) {
54 menu.addItem("View Metarecord Details",
55 function() { alert(record.doc_id()); });
56 xulEvtMRResultDisplayed( menu, record );
60 MRResultPage.prototype.mkLink = function(id, type, value) {
67 href = createAppElement("a");
68 add_css_class(href,"record_result_title_link");
69 href.setAttribute("href","?target=record_result&page=0&mrid=" + id );
70 href.appendChild(createAppTextNode(value));
74 href = createAppElement("a");
75 add_css_class(href,"record_result_author_link");
76 href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
77 encodeURIComponent(value));
78 href.appendChild(createAppTextNode(value));
82 throw new EXArg("Unknown link type: " + type );
90 /* performs a new search */
91 MRResultPage.prototype.doSearch = function() {
94 var string = paramObj.__mr_search_query;
95 var stype = paramObj.__mr_search_type;
96 if(!stype || !string) return;
99 if(globalSelectedLocation)
100 orgunit = globalSelectedLocation;
101 else orgunit = globalLocation;
103 if(this.searchDepth == null)
104 this.searchDepth = globalSearchDepth;
106 debug("Current search depth: " + globalSearchDepth);
107 debug("My search depth: " + this.searchDepth);
109 /* see if this is a new search */
110 if( string != this.string ||
111 stype != this.stype ||
112 this.searchLocation != orgunit ||
113 this.searchDepth != globalSearchDepth ) {
116 this.searchDepth = globalSearchDepth;
119 this.searchLocation = orgunit;
121 this.string = string;
122 this.page = parseInt(paramObj.__page);
123 this.searchOffset = this.page * this.hitsPerPage;
126 //this.progressBar.progressStart();
130 var offset = parseInt(this.searchOffset);
131 var hitspp = parseInt(this.hitsPerPage);
133 /* is this just a call to next/prev? */
134 if( this.recordIDs && this.recordIDs[offset] != null ) {
135 debug("We have the first part of the ID's");
136 if( this.recordIDs[offset + (hitspp -1 )] != null ||
137 this.recordIDs[this.hitCount - 1] != null ) {
138 /* we already have all of the IDS */
139 debug("We alread have the required mr " +
140 "ids for the search: [" + this.string + "]");
141 this.collectRecords();
147 debug("MRResultPage doSearch() with type: "
148 + this.stype + " and search [" + this.string + "]"
149 + " and offset " + this.searchOffset );
153 var request = new RemoteRequest(
154 "open-ils.search", "open-ils.search.biblio.class",
155 this.stype, this.string,
156 this.searchLocation.id(),
157 this.searchDepth, "50", this.searchOffset );
160 request.setCompleteCallback(
163 var result = req.getResultObject();
164 debug( "MRSearch returned: " + js2JSON(result) );
165 obj.gatherIDs(result)
166 obj.collectRecords();
167 } catch(E) { throw ("Search Error " + E ); }
175 MRResultPage.prototype.collectRecords = function() {
177 var i = this.searchOffset;
179 var hcell = getById("hit_count_cell");
180 hcell.innerHTML = "Hits";
181 hcell.innerHTML += " ";
182 hcell.innerHTML += this.hitCount;
184 while( i < (this.searchOffset + this.hitsPerPage) ) {
185 var id = this.recordIDs[i];
187 if(id==null){ i++; continue; }
189 var request = new RemoteRequest( "open-ils.search",
190 "open-ils.search.biblio.metarecord.mods_slim.retrieve", id );
191 this.requestBatch.push(request);
193 request.name = "record_request_" + i;
194 request.search_id = i;
195 request.page_id = parseInt(i) - parseInt(this.searchOffset);
197 debug("Collecting metarecord for id " + id + " and search_id " + i);
200 /* define the callback for when we receive the record */
202 request.setCompleteCallback(
205 var record = req.getResultObject();
206 obj.displayRecord( record, req.search_id, req.page_id );
207 obj.doCopyCount( record, req.search_id, req.page_id );
209 // alert("Doc Retrieval Error:\n" + E);
219 MRResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
221 var copy_box = getById("record_result_copy_count_box_" + page_id );
223 /* kick off the copy count search */
224 debug("Grabbing copy count for record " + record.doc_id() );
225 var copy_request = new RemoteRequest( "open-ils.search",
226 "open-ils.search.biblio.metarecord.copy_count", 1, record.doc_id() );
227 this.requestBatch.push(copy_request);
229 copy_request.search_id = search_id;
230 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
232 debug("Sending copy request " + search_id + ":" + record.doc_id() );
235 copy_request.setCompleteCallback(
238 copy_box.innerHTML = req.getResultObject();
240 //alert("Copy Count Retrieval Error:\n" + E );
250 MRResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
252 var copy_box = getById("record_result_copy_count_box_" + page_id );
254 /* kick off the copy count search */
255 var orgunit = globalSelectedLocation;
256 if(!orgunit) orgunit = globalLocation;
258 var copy_request = new RemoteRequest( "open-ils.search",
259 "open-ils.search.biblio.metarecord.copy_count",
260 orgunit.id(), record.doc_id() );
262 this.requestBatch.push(copy_request);
264 copy_request.search_id = search_id;
265 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
267 debug("Sending copy request " + search_id + ":" + record.doc_id() );
270 copy_request.setCompleteCallback(
273 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
275 //alert("Copy Count Retrieval Error:\n" + E );
285 MRResultPage.prototype.gatherIDs = function(result) {
287 this.hitCount = parseInt(result.count);
290 for( var i in result.ids ) {
291 if(result.ids[i]==null || result.ids[i][0] == null) break;
292 var offset = parseInt(i) + parseInt(this.searchOffset);
293 this.recordIDs[offset] = result.ids[i][0];
294 this.ranks[offset] = parseFloat(result.ids[i][1]);
295 debug("adding ranks[" + offset + "] = " + result.ids[i][1] +
296 " \nrecordIDs["+offset+"], result.ids["+i+"][0]");