1 var globalRecordResultPage = null; /* our global object */
3 RecordResultPage.prototype = new AbstractRecordResultPage();
4 RecordResultPage.prototype.constructor = RecordResultPage;
5 RecordResultPage.baseClass = AbstractRecordResultPage.constructor;
7 /* constructor for our singleton object */
8 function RecordResultPage() {
10 debug("in RecordResultPage()");
12 if( globalRecordResultPage != null ) {
13 debug("globalRecordResultPage already exists: " +
14 globalRecordResultPage.toString() );
15 return globalRecordResultPage;
17 globalRecordResultPage = this;
19 debug("Built a new RecordResultPage()");
23 /* returns the global instance. builds the instance if necessary. All client
24 * code should use this method */
25 RecordResultPage.instance = function() {
26 if( globalRecordResultPage != null ) {
27 return globalRecordResultPage;
29 return new RecordResultPage();
32 RecordResultPage.prototype.next = function() {
33 paramObj.__page = parseInt(paramObj.__page) + 1;
34 var paramArray = build_param_array();
35 url_redirect( paramArray )
39 RecordResultPage.prototype.prev = function() {
40 paramObj.__page = parseInt(paramObj.__page) - 1;
41 var paramArray = build_param_array();
42 url_redirect( paramArray )
45 RecordResultPage.prototype.addMenuItems = function(menu, record) {
46 menu.addItem("View MARC",
47 function() { alert(record.doc_id()); });
49 xulEvtRecordResultDisplayed( menu, record );
53 RecordResultPage.prototype.mkLink = function(id, type, value) {
60 href = createAppElement("a");
61 add_css_class(href,"record_result_title_link");
62 href.setAttribute("href","?target=record_result&mrid=" + id );
63 href.appendChild(createAppTextNode(value));
67 href = createAppElement("a");
68 add_css_class(href,"record_result_author_link");
69 href.setAttribute("href","?target=mr_result&mr_search_type=author&mr_search_query=" +
70 encodeURIComponent(value));
71 href.appendChild(createAppTextNode(value));
75 throw new EXArg("Unknown link type: " + type );
82 RecordResultPage.prototype.toString = function() {
84 return "\nRecordResultPage:\n" +
85 "page: " + this.page + "\n" +
86 "searchOffset: " + this.searchOffset + "\n" +
87 "recordIDs: " + this.recordIDs + "\n" +
88 "hitCount: " + this.hitCount + "\n" +
89 "hitsPerPage: " + this.hitsPerPage + "\n";
94 RecordResultPage.prototype.isNewSearch = function() {
101 /* performs a new search */
102 RecordResultPage.prototype.doSearch = function() {
104 debug( "Key Value Array \n" + js2JSON( paramObj ) );
106 this.page = parseInt(paramObj.__page);
107 this.searchOffset = this.page * this.hitsPerPage;
110 if(this.isNewSearch()) {
111 debug("RecordResultPage resetting search..");
115 var offset = parseInt(this.searchOffset);
116 var hitspp = parseInt(this.hitsPerPage);
118 /* is this just a call to next/prev? */
119 if( this.recordIDs && this.recordIDs[offset] != null ) {
120 debug("We have the first part of the ID's");
121 if( this.recordIDs[offset + (hitspp -1 )] != null ||
122 this.recordIDs[this.hitCount - 1] != null ) {
123 /* we already have all of the IDS */
124 debug("We alread have the required mr " +
125 "ids for the search: [" + this.string + "]");
126 this.collectRecords();
132 if( paramObj.__mrid != null ) {
133 this.mrSearch(paramObj.__mrid);
137 if( paramObj.__search == "global" ) {
139 if( paramObj.__tcn != null ) {
140 this.globalSearch("tcn", paramObj.__tcn);
144 if( paramObj.__isbn != null ) {
145 this.globalSearch("isbn", paramObj.__isbn);
153 /* these are the simple global searches */
154 RecordResultPage.prototype.globalSearch = function(type, term) {
156 if( !term || term.length < 2 )
157 throw new EXArg( "globalSearch needs valid term: " + term );
159 debug("Performing Global search for term: " + term );
164 method = "open-ils.search.biblio.tcn";
168 method = "open-ils.search.biblio.isbn";
172 var request = new RemoteRequest( "open-ils.search", method, term );
175 request.setCompleteCallback(
178 var result = req.getResultObject();
179 debug( "Global Search returned: " + js2JSON(result) );
180 obj.gatherIDs(result)
181 obj.collectRecords();
182 } catch(E) { throw ("Search Error " + E ); }
189 RecordResultPage.prototype.mrSearch = function(mrid) {
191 var request = new RemoteRequest("open-ils.search",
192 "open-ils.search.biblio.metarecord_to_records", mrid );
193 debug("Gathering doc ids for metarecord " + mrid );
196 request.setCompleteCallback(
199 obj.gatherIDs(req.getResultObject());
200 obj.collectRecords();
201 } catch(E) { throw ("Search Error " + E ); }
207 RecordResultPage.prototype.collectRecords = function() {
209 var i = this.searchOffset;
211 var hcell = getById("hit_count_cell");
212 hcell.innerHTML = "Hits";
213 hcell.innerHTML += " ";
214 hcell.innerHTML += this.hitCount;
216 while( i < (this.searchOffset + this.hitsPerPage) ) {
217 var id = this.recordIDs[i];
219 if(id==null){ i++; continue; }
221 var request = new RemoteRequest( "open-ils.search",
222 "open-ils.search.biblio.record.mods_slim.retrieve", id );
223 this.requestBatch.push(request);
225 request.name = "record_request_" + i;
226 request.search_id = i;
227 request.page_id = parseInt(i) - parseInt(this.searchOffset);
229 /* define the callback for when we receive the record */
231 request.setCompleteCallback(
233 var record = req.getResultObject();
234 obj.displayRecord( record, req.search_id, req.page_id );
235 obj.doCopyCount( record, req.search_id, req.page_id );
244 RecordResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
246 var copy_box = getById("record_result_copy_count_box_" + page_id );
248 /* kick off the copy count search */
249 var orgunit = globalSelectedLocation;
250 if(!orgunit) orgunit = globalLocation;
252 var copy_request = new RemoteRequest( "open-ils.search",
253 "open-ils.search.biblio.record.copy_count",
254 orgunit.id(), record.doc_id() );
256 this.requestBatch.push(copy_request);
258 copy_request.search_id = search_id;
259 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
261 debug("Sending copy request " + search_id + ":" + record.doc_id() );
264 copy_request.setCompleteCallback(
268 //copy_box.innerHTML = req.getResultObject();
269 copy_box.appendChild(
270 createAppTextNode(req.getResultObject()));
272 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
274 alert("Copy Count Retrieval Error:\n" + E );