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 var row = getById("hourglass_row");
14 row.parentNode.removeChild(row);
16 if( globalRecordResultPage != null ) {
17 debug("globalRecordResultPage already exists: " +
18 globalRecordResultPage.toString() );
19 return globalRecordResultPage;
21 globalRecordResultPage = this;
23 debug("Built a new RecordResultPage()");
25 var row = getById("hourglass_row");
27 row.parentNode.removeChild(row);
31 RecordResultPage.prototype.setPageTrail = function() {
32 var box = getById("page_trail");
35 var d = this.buildTrailLink("start", true);
39 d = this.buildTrailLink("advanced_search", true);
44 var b = this.buildTrailLink("mr_result", true);
47 box.appendChild(this.buildDivider());
51 box.appendChild(this.buildDivider());
53 this.buildTrailLink("record_result",false));
60 /* returns the global instance. builds the instance if necessary. All client
61 * code should use this method */
62 RecordResultPage.instance = function() {
64 var row = getById("hourglass_row");
66 row.parentNode.removeChild(row);
68 if( globalRecordResultPage != null ) {
69 return globalRecordResultPage;
71 return new RecordResultPage();
74 RecordResultPage.prototype.next = function() {
75 paramObj.__page = parseInt(paramObj.__page) + 1;
76 var paramArray = build_param_array();
77 url_redirect( paramArray )
82 RecordResultPage.prototype.URLRefresh = function() {
84 return build_param_array();
89 RecordResultPage.prototype.prev = function() {
90 paramObj.__page = parseInt(paramObj.__page) - 1;
91 var paramArray = build_param_array();
92 url_redirect( paramArray )
95 RecordResultPage.prototype.addMenuItems = function(menu, record) {
97 var func = function() {
98 var req = new RemoteRequest(
100 "open-ils.search.biblio.record.html",
103 buildViewMARCWindow(req.getResultObject(), record.doc_id() );
106 menu.addItem("View MARC", func);
108 xulEvtRecordResultDisplayed( menu, record );
113 function buildViewMARCWindow(html, id) {
114 var win = window.open(null,"MARC_" + id,
115 "location=0,menubar=0,status=0,resizeable,resize," +
116 "outerHeight=500,outerWidth=400,height=500," +
117 "width=400,scrollbars=1,screenX=100," +
118 "screenY=100,top=100,left=100,alwaysraised" )
119 win.document.write(html);
120 win.document.close();
121 win.document.title = "View MARC";
127 RecordResultPage.prototype.mkLink = function(id, type, value) {
134 href = createAppElement("a");
135 add_css_class(href,"record_result_title_link");
136 href.setAttribute("href","?target=record_detail&record=" + id );
137 href.appendChild(createAppTextNode(value));
138 href.title = "View title details for " + value;
142 href = createAppElement("a");
143 add_css_class(href,"record_result_author_link");
144 href.setAttribute("href","?target=mr_result&mr_search_type=author&mr_search_query=" +
145 encodeURIComponent(value));
146 href.appendChild(createAppTextNode(value));
147 href.title = "Author search for " + value + "";
151 href = createAppElement("a");
152 add_css_class(href,"record_result_image_link");
153 href.setAttribute("href","?target=record_detail&page=0&mrid=" + id );
154 href.title = "View title details for " + value;
158 throw new EXArg("Unknown link type: " + type );
165 RecordResultPage.prototype.toString = function() {
167 return "\nRecordResultPage:\n" +
168 "page: " + this.page + "\n" +
169 "searchOffset: " + this.searchOffset + "\n" +
170 "recordIDs: " + this.recordIDs + "\n" +
171 "hitCount: " + this.hitCount + "\n" +
172 "hitsPerPage: " + this.hitsPerPage + "\n";
177 RecordResultPage.prototype.isNewSearch = function() {
184 /* performs a new search */
185 RecordResultPage.prototype.doSearch = function() {
187 debug( "Key Value Array \n" + js2JSON( paramObj ) );
189 this.page = parseInt(paramObj.__page);
190 var hitsper = paramObj.__hits_per_page;
194 this.hitsPerPage = parseInt(hitsper);
196 debug("******* Hits per = " + this.hitsPerPage);
198 this.hitsPerPageSelector = getById('hits_per_page');
199 for( var i in this.hitsPerPageSelector.options ) {
200 var hits_obj = this.hitsPerPageSelector.options[i];
201 if(hits_obj == null) continue;
202 var hits = hits_obj.value;
204 if( this.hitsPerPage == parseInt(hits) ) {
205 this.hitsPerPageSelector.options[i].selected = true;
206 debug("Setting selected on selector with hits " + hits);
211 if(this.page == null)
214 this.searchOffset = this.page * this.hitsPerPage;
217 if(this.isNewSearch()) {
218 debug("RecordResultPage resetting search..");
222 var offset = parseInt(this.searchOffset);
223 var hitspp = parseInt(this.hitsPerPage);
225 /* is this just a call to next/prev? */
226 if( this.recordIDs && this.recordIDs[offset] != null ) {
227 debug("We have the first part of the ID's");
228 if( this.recordIDs[offset + (hitspp -1 )] != null ||
229 this.recordIDs[this.hitCount - 1] != null ) {
230 /* we already have all of the IDS */
231 debug("We alread have the required mr " +
232 "ids for the search: [" + this.string + "]");
233 this.collectRecords();
239 if( paramObj.__mrid != null ) {
240 this.mrSearch(paramObj.__mrid);
244 if( paramObj.__search == "global" ) {
246 if( paramObj.__tcn != null ) {
247 this.globalSearch("tcn", paramObj.__tcn);
251 if( paramObj.__isbn != null ) {
252 this.globalSearch("isbn", paramObj.__isbn);
255 if( paramObj.__barcode != null ) {
256 this.globalSearch("barcode", paramObj.__barcode);
265 /* these are the simple global searches */
266 RecordResultPage.prototype.globalSearch = function(type, term) {
268 if( !term || term.length < 2 )
269 throw new EXArg( "globalSearch needs valid term: " + term );
271 debug("Performing Global search [" + type + "] for term: " + term );
276 method = "open-ils.search.biblio.tcn";
280 method = "open-ils.search.biblio.isbn";
284 method = "open-ils.search.biblio.find_by_barcode";
288 var request = new RemoteRequest( "open-ils.search", method, term );
291 request.setCompleteCallback(
294 var result = req.getResultObject();
295 debug( "Global Search returned: " + js2JSON(result) );
296 obj.gatherIDs(result)
297 obj.collectRecords();
298 } catch(E) { throw ("Search Error " + E ); }
305 RecordResultPage.prototype.mrSearch = function(mrid) {
307 var request = new RemoteRequest("open-ils.search",
308 "open-ils.search.biblio.metarecord_to_records", mrid );
309 debug("Gathering doc ids for metarecord " + mrid );
312 request.setCompleteCallback(
315 obj.gatherIDs(req.getResultObject());
316 obj.collectRecords();
317 } catch(E) { throw ("Search Error " + E ); }
323 RecordResultPage.prototype.collectRecords = function() {
325 var i = this.searchOffset;
327 while( i < (this.searchOffset + this.hitsPerPage) ) {
328 var id = this.recordIDs[i];
330 if(id==null){ i++; continue; }
332 var request = new RemoteRequest( "open-ils.search",
333 "open-ils.search.biblio.record.mods_slim.retrieve", id );
335 request.name = "record_request_" + i;
336 request.search_id = i;
337 request.page_id = parseInt(i) - parseInt(this.searchOffset);
339 /* define the callback for when we receive the record */
341 request.setCompleteCallback(
343 var record = req.getResultObject();
344 obj.displayRecord( record, req.search_id, req.page_id );
345 obj.doCopyCount( record, req.search_id, req.page_id );
354 RecordResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
356 var copy_box = getById("record_result_copy_count_box_" + page_id );
358 /* kick off the copy count search */
359 var orgunit = globalSelectedLocation;
360 if(!orgunit) orgunit = globalLocation;
362 var copy_request = new RemoteRequest( "open-ils.search",
363 "open-ils.search.biblio.record.copy_count",
364 orgunit.id(), record.doc_id() );
367 copy_request.search_id = search_id;
368 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
370 debug("Sending copy request " + search_id + ":" + record.doc_id() );
373 copy_request.setCompleteCallback(
376 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
378 debug("****** Copy Count Retrieval Error:\n" + E );