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 var location = globalSelectedLocation;
36 location = globalLocation.id();
38 location = location.id();
40 /* if the user has changed the 'location' of the search, it will be
41 reflected when the user hits the next button. the search depth
42 will not change, however, because that is a different search */
44 "target", "mr_result",
45 "mr_search_type", this.stype,
46 "mr_search_query", this.string,
47 "mr_search_location", location,
48 "mr_search_depth", this.searchDepth,
54 MRResultPage.prototype.prev = function() {
55 if(this.page == 0 ) return;
58 var depth = globalSearchDepth;
59 var location = globalSelectedLocation;
61 location = globalLocation.id();
63 location = location.id();
65 /* if the user has changed the 'location' of the search, it will be
66 reflected when the user hits this button. the search depth
67 will not change, however, because that is a different search */
69 "target", "mr_result",
70 "mr_search_type", this.stype,
71 "mr_search_query", this.string,
72 "mr_search_location", location,
73 "mr_search_depth", this.searchDepth,
79 MRResultPage.prototype.addMenuItems = function(menu, record) {
80 menu.addItem("View Metarecord Details",
81 function() { alert(record.doc_id()); });
82 xulEvtMRResultDisplayed( menu, record );
86 MRResultPage.prototype.mkLink = function(id, type, value) {
93 href = createAppElement("a");
94 add_css_class(href,"record_result_title_link");
95 href.setAttribute("href","?target=record_result&page=0&mrid=" + id );
96 href.appendChild(createAppTextNode(value));
100 href = createAppElement("a");
101 add_css_class(href,"record_result_author_link");
102 href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
103 encodeURIComponent(value));
104 href.appendChild(createAppTextNode(value));
108 throw new EXArg("Unknown link type: " + type );
116 /* performs a new search */
117 MRResultPage.prototype.doSearch = function() {
120 var string = paramObj.__mr_search_query;
121 var stype = paramObj.__mr_search_type;
122 var location = paramObj.__mr_search_location;
123 var depth = paramObj.__mr_search_depth;
125 debug("mr search params string " + string + " stype " + stype +
126 " location " + location + " depth " + depth );
129 depth = globalSearchDepth;
131 location = globalLocation.id();
133 if(!stype || !string) return;
135 if(this.searchDepth == null)
136 this.searchDepth = globalSearchDepth;
138 /* see if this is a new search */
139 if( string != this.string ||
140 stype != this.stype ||
141 this.searchLocation != location ||
142 this.searchDepth != depth ) {
146 this.searchDepth = depth;
147 this.searchLocation = location;
149 this.string = string;
150 this.page = parseInt(paramObj.__page);
151 this.searchOffset = this.page * this.hitsPerPage;
155 var offset = parseInt(this.searchOffset);
156 var hitspp = parseInt(this.hitsPerPage);
158 /* is this just a call to next/prev? */
159 if( this.recordIDs && this.recordIDs[offset] != null ) {
160 debug("We have the first part of the ID's");
161 if( this.recordIDs[offset + (hitspp -1 )] != null ||
162 this.recordIDs[this.hitCount - 1] != null ) {
163 /* we already have all of the IDS */
164 debug("We alread have the required mr " +
165 "ids for the search: [" + this.string + "]");
166 this.collectRecords();
172 debug("MRResultPage doSearch() with type: "
173 + this.stype + " and search [" + this.string + "]"
174 + " and offset " + this.searchOffset +
175 " depth: " + depth + " location: " + location);
179 var request = new RemoteRequest(
180 "open-ils.search", "open-ils.search.biblio.class",
181 this.stype, this.string,
183 this.searchDepth, "50", this.searchOffset );
186 request.setCompleteCallback(
188 var result = req.getResultObject();
189 obj.gatherIDs(result)
190 obj.collectRecords();
191 obj.requestBatch.remove(req);
195 this.requestBatch.add(request);
200 MRResultPage.prototype.collectRecords = function() {
203 var i = this.searchOffset;
205 while( i < (this.searchOffset + this.hitsPerPage) ) {
206 var id = this.recordIDs[i];
208 if(id==null){ i++; continue; }
210 var request = new RemoteRequest( "open-ils.search",
211 "open-ils.search.biblio.metarecord.mods_slim.retrieve", id );
212 this.requestBatch.add(request);
213 debug( "Sending mods retrieval for metarecord " + id );
215 request.name = "record_request_" + i;
216 request.search_id = i;
217 request.page_id = parseInt(i) - parseInt(this.searchOffset);
219 /* define the callback for when we receive the record */
221 request.setCompleteCallback(
223 var record = req.getResultObject();
224 obj.displayRecord( record, req.search_id, req.page_id );
225 obj.doCopyCount( record, req.search_id, req.page_id );
226 obj.requestBatch.remove(req);
237 MRResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
239 var copy_box = getById("record_result_copy_count_box_" + page_id );
241 var orgunit = globalSelectedLocation;
242 if(!orgunit) orgunit = globalLocation;
244 var copy_request = new RemoteRequest(
246 "open-ils.search.biblio.metarecord.copy_count",
247 this.searchLocation, record.doc_id() );
249 copy_request.search_id = search_id;
250 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
253 copy_request.setCompleteCallback(
256 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
258 debug("****** Copy Count Retrieval Error:\n" + E );