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 )
40 RecordResultPage.prototype.URLRefresh = function() {
42 return build_param_array();
47 RecordResultPage.prototype.prev = function() {
48 paramObj.__page = parseInt(paramObj.__page) - 1;
49 var paramArray = build_param_array();
50 url_redirect( paramArray )
53 RecordResultPage.prototype.addMenuItems = function(menu, record) {
55 var func = function() {
56 var req = new RemoteRequest(
58 "open-ils.search.biblio.record.html",
61 buildViewMARCWindow(req.getResultObject(), record.doc_id() );
64 menu.addItem("View MARC", func);
66 xulEvtRecordResultDisplayed( menu, record );
71 function buildViewMARCWindow(html, id) {
72 var win = window.open(null,"MARC_" + id,
73 "location=0,menubar=0,status=0,resizeable,resize," +
74 "outerHeight=500,outerWidth=400,height=500," +
75 "width=400,scrollbars=1,screenX=100," +
76 "screenY=100,top=100,left=100,alwaysraised" )
77 win.document.write(html);
79 win.document.title = "View MARC";
85 RecordResultPage.prototype.mkLink = function(id, type, value) {
92 href = createAppElement("a");
93 add_css_class(href,"record_result_title_link");
94 href.setAttribute("href","?target=record_detail&record=" + id );
95 href.appendChild(createAppTextNode(value));
99 href = createAppElement("a");
100 add_css_class(href,"record_result_author_link");
101 href.setAttribute("href","?target=mr_result&mr_search_type=author&mr_search_query=" +
102 encodeURIComponent(value));
103 href.appendChild(createAppTextNode(value));
107 href = createAppElement("a");
108 add_css_class(href,"record_result_image_link");
109 href.setAttribute("href","?target=record_detail&page=0&mrid=" + id );
113 throw new EXArg("Unknown link type: " + type );
120 RecordResultPage.prototype.toString = function() {
122 return "\nRecordResultPage:\n" +
123 "page: " + this.page + "\n" +
124 "searchOffset: " + this.searchOffset + "\n" +
125 "recordIDs: " + this.recordIDs + "\n" +
126 "hitCount: " + this.hitCount + "\n" +
127 "hitsPerPage: " + this.hitsPerPage + "\n";
132 RecordResultPage.prototype.isNewSearch = function() {
139 /* performs a new search */
140 RecordResultPage.prototype.doSearch = function() {
142 debug( "Key Value Array \n" + js2JSON( paramObj ) );
144 this.page = parseInt(paramObj.__page);
145 var hitsper = paramObj.__hits_per_page;
149 this.hitsPerPage = parseInt(hitsper);
151 debug("******* Hits per = " + this.hitsPerPage);
153 this.hitsPerPageSelector = getById('hits_per_page');
154 for( var i in this.hitsPerPageSelector.options ) {
155 var hits_obj = this.hitsPerPageSelector.options[i];
156 if(hits_obj == null) continue;
157 var hits = hits_obj.value;
159 if( this.hitsPerPage == parseInt(hits) ) {
160 this.hitsPerPageSelector.options[i].selected = true;
161 debug("Setting selected on selector with hits " + hits);
166 if(this.page == null)
169 this.searchOffset = this.page * this.hitsPerPage;
172 if(this.isNewSearch()) {
173 debug("RecordResultPage resetting search..");
177 var offset = parseInt(this.searchOffset);
178 var hitspp = parseInt(this.hitsPerPage);
180 /* is this just a call to next/prev? */
181 if( this.recordIDs && this.recordIDs[offset] != null ) {
182 debug("We have the first part of the ID's");
183 if( this.recordIDs[offset + (hitspp -1 )] != null ||
184 this.recordIDs[this.hitCount - 1] != null ) {
185 /* we already have all of the IDS */
186 debug("We alread have the required mr " +
187 "ids for the search: [" + this.string + "]");
188 this.collectRecords();
194 if( paramObj.__mrid != null ) {
195 this.mrSearch(paramObj.__mrid);
199 if( paramObj.__search == "global" ) {
201 if( paramObj.__tcn != null ) {
202 this.globalSearch("tcn", paramObj.__tcn);
206 if( paramObj.__isbn != null ) {
207 this.globalSearch("isbn", paramObj.__isbn);
210 if( paramObj.__barcode != null ) {
211 this.globalSearch("barcode", paramObj.__barcode);
220 /* these are the simple global searches */
221 RecordResultPage.prototype.globalSearch = function(type, term) {
223 if( !term || term.length < 2 )
224 throw new EXArg( "globalSearch needs valid term: " + term );
226 debug("Performing Global search [" + type + "] for term: " + term );
231 method = "open-ils.search.biblio.tcn";
235 method = "open-ils.search.biblio.isbn";
239 method = "open-ils.search.biblio.find_by_barcode";
243 var request = new RemoteRequest( "open-ils.search", method, term );
246 request.setCompleteCallback(
249 var result = req.getResultObject();
250 debug( "Global Search returned: " + js2JSON(result) );
251 obj.gatherIDs(result)
252 obj.collectRecords();
253 } catch(E) { throw ("Search Error " + E ); }
260 RecordResultPage.prototype.mrSearch = function(mrid) {
262 var request = new RemoteRequest("open-ils.search",
263 "open-ils.search.biblio.metarecord_to_records", mrid );
264 debug("Gathering doc ids for metarecord " + mrid );
267 request.setCompleteCallback(
270 obj.gatherIDs(req.getResultObject());
271 obj.collectRecords();
272 } catch(E) { throw ("Search Error " + E ); }
278 RecordResultPage.prototype.collectRecords = function() {
280 var i = this.searchOffset;
282 while( i < (this.searchOffset + this.hitsPerPage) ) {
283 var id = this.recordIDs[i];
285 if(id==null){ i++; continue; }
287 var request = new RemoteRequest( "open-ils.search",
288 "open-ils.search.biblio.record.mods_slim.retrieve", id );
290 request.name = "record_request_" + i;
291 request.search_id = i;
292 request.page_id = parseInt(i) - parseInt(this.searchOffset);
294 /* define the callback for when we receive the record */
296 request.setCompleteCallback(
298 var record = req.getResultObject();
299 obj.displayRecord( record, req.search_id, req.page_id );
300 obj.doCopyCount( record, req.search_id, req.page_id );
309 RecordResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
311 var copy_box = getById("record_result_copy_count_box_" + page_id );
313 /* kick off the copy count search */
314 var orgunit = globalSelectedLocation;
315 if(!orgunit) orgunit = globalLocation;
317 var copy_request = new RemoteRequest( "open-ils.search",
318 "open-ils.search.biblio.record.copy_count",
319 orgunit.id(), record.doc_id() );
322 copy_request.search_id = search_id;
323 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
325 debug("Sending copy request " + search_id + ":" + record.doc_id() );
328 copy_request.setCompleteCallback(
331 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
333 debug("****** Copy Count Retrieval Error:\n" + E );