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.buildExtendedLinks = function(record, page_id) {
35 RecordResultPage.prototype.setPageTrail = function() {
36 var box = getById("page_trail");
39 var d = this.buildTrailLink("start", true);
43 d = this.buildTrailLink("advanced_search", true);
48 var b = this.buildTrailLink("mr_result", true);
51 box.appendChild(this.buildDivider());
55 box.appendChild(this.buildDivider());
57 this.buildTrailLink("record_result",false));
64 /* returns the global instance. builds the instance if necessary. All client
65 * code should use this method */
66 RecordResultPage.instance = function() {
68 var row = getById("hourglass_row");
70 row.parentNode.removeChild(row);
72 if( globalRecordResultPage != null ) {
73 return globalRecordResultPage;
75 return new RecordResultPage();
78 RecordResultPage.prototype.next = function() {
79 paramObj.__page = parseInt(paramObj.__page) + 1;
80 var paramArray = build_param_array();
81 url_redirect( paramArray )
86 RecordResultPage.prototype.URLRefresh = function() {
88 return build_param_array();
93 RecordResultPage.prototype.prev = function() {
94 paramObj.__page = parseInt(paramObj.__page) - 1;
95 var paramArray = build_param_array();
96 url_redirect( paramArray )
99 RecordResultPage.prototype.addMenuItems = function(menu, record) {
101 var func = buildViewMARCWindow(record);
102 menu.addItem("View MARC", func);
104 xulEvtRecordResultDisplayed( menu, record );
109 function buildViewMARCWindow(record) {
111 debug("Setting up view marc with record " + record.doc_id());
112 var func = function() {
113 var req = new RemoteRequest(
115 "open-ils.search.biblio.record.html",
119 var html = req.getResultObject();
120 var id = record.doc_id();
122 var win = window.open(null,"MARC_" + id,
123 "location=0,menubar=0,status=0,resizeable,resize," +
124 "outerHeight=500,outerWidth=400,height=500," +
125 "width=400,scrollbars=1,screenX=100," +
126 "screenY=100,top=100,left=100,alwaysraised" )
127 win.document.write(html);
128 win.document.close();
129 win.document.title = "View MARC";
137 RecordResultPage.prototype.mkLink = function(id, type, value) {
144 href = createAppElement("a");
145 add_css_class(href,"record_result_title_link");
146 href.setAttribute("href","?target=record_detail&record=" + id );
147 href.appendChild(createAppTextNode(value));
148 href.title = "View title details for " + value;
152 href = createAppElement("a");
153 add_css_class(href,"record_result_author_link");
154 href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
155 encodeURIComponent(value));
156 href.appendChild(createAppTextNode(value));
157 href.title = "Author search for " + value + "";
161 href = createAppElement("a");
162 add_css_class(href,"record_result_image_link");
163 href.setAttribute("href","?target=record_detail&page=0&mrid=" + id );
164 href.title = "View title details for " + value;
168 throw new EXArg("Unknown link type: " + type );
175 RecordResultPage.prototype.toString = function() {
177 return "\nRecordResultPage:\n" +
178 "page: " + this.page + "\n" +
179 "searchOffset: " + this.searchOffset + "\n" +
180 "recordIDs: " + this.recordIDs + "\n" +
181 "hitCount: " + this.hitCount + "\n" +
182 "hitsPerPage: " + this.hitsPerPage + "\n";
187 RecordResultPage.prototype.isNewSearch = function() {
194 /* performs a new search */
195 RecordResultPage.prototype.doSearch = function() {
197 debug( "Key Value Array \n" + js2JSON( paramObj ) );
199 this.page = parseInt(paramObj.__page);
200 var hitsper = paramObj.__hits_per_page;
203 this.hitsPerPage = parseInt(hitsper);
205 debug("******* Hits per = " + this.hitsPerPage);
207 this.hitsPerPageSelector = getById('hits_per_page');
208 for( var i in this.hitsPerPageSelector.options ) {
209 var hits_obj = this.hitsPerPageSelector.options[i];
210 if(hits_obj == null) continue;
211 var hits = hits_obj.value;
213 if( this.hitsPerPage == parseInt(hits) ) {
214 this.hitsPerPageSelector.options[i].selected = true;
215 debug("Setting selected on selector with hits " + hits);
219 if(this.page == null)
222 this.searchOffset = this.page * this.hitsPerPage;
225 if(this.isNewSearch()) {
226 debug("RecordResultPage resetting search..");
230 var offset = parseInt(this.searchOffset);
231 var hitspp = parseInt(this.hitsPerPage);
233 /* is this just a call to next/prev? */
234 if( this.recordIDs && this.recordIDs[offset] != null ) {
235 debug("We have the first part of the ID's");
236 if( this.recordIDs[offset + (hitspp -1 )] != null ||
237 this.recordIDs[this.hitCount - 1] != null ) {
238 /* we already have all of the IDS */
239 debug("We alread have the required mr " +
240 "ids for the search: [" + this.string + "]");
241 this.collectRecords();
247 if( paramObj.__mrid != null ) {
248 this.mrSearch(paramObj.__mrid);
252 if( paramObj.__search == "global" ) {
254 if( paramObj.__tcn != null ) {
255 this.globalSearch("tcn", paramObj.__tcn);
259 if( paramObj.__isbn != null ) {
260 this.globalSearch("isbn", paramObj.__isbn);
263 if( paramObj.__barcode != null ) {
264 this.globalSearch("barcode", paramObj.__barcode);
273 /* these are the simple global searches */
274 RecordResultPage.prototype.globalSearch = function(type, term) {
276 if( !term || term.length < 2 )
277 throw new EXArg( "globalSearch needs valid term: " + term );
279 debug("Performing Global search [" + type + "] for term: " + term );
284 method = "open-ils.search.biblio.tcn";
288 method = "open-ils.search.biblio.isbn";
292 method = "open-ils.search.biblio.find_by_barcode";
296 var request = new RemoteRequest( "open-ils.search", method, term );
299 request.setCompleteCallback(
302 var result = req.getResultObject();
303 debug( "Global Search returned: " + js2JSON(result) );
304 obj.gatherIDs(result)
305 obj.collectRecords();
306 } catch(E) { throw ("Search Error " + E ); }
313 RecordResultPage.prototype.mrSearch = function(mrid) {
315 var request = new RemoteRequest("open-ils.search",
316 "open-ils.search.biblio.metarecord_to_records", mrid );
317 debug("Gathering doc ids for metarecord " + mrid );
320 request.setCompleteCallback(
323 obj.gatherIDs(req.getResultObject());
324 obj.collectRecords();
325 } catch(E) { throw ("Search Error " + E ); }
331 RecordResultPage.prototype.collectRecords = function() {
333 var i = this.searchOffset;
335 while( i < (this.searchOffset + this.hitsPerPage) ) {
336 var id = this.recordIDs[i];
338 if(id==null){ i++; continue; }
340 var request = new RemoteRequest( "open-ils.search",
341 "open-ils.search.biblio.record.mods_slim.retrieve", id );
343 request.name = "record_request_" + i;
344 request.search_id = i;
345 request.page_id = parseInt(i) - parseInt(this.searchOffset);
347 /* define the callback for when we receive the record */
349 request.setCompleteCallback(
351 var record = req.getResultObject();
352 obj.displayRecord( record, req.search_id, req.page_id );
353 obj.doCopyCount( record, req.search_id, req.page_id );
362 RecordResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
364 var copy_box = getById("record_result_copy_count_box_" + page_id );
366 /* kick off the copy count search */
367 var orgunit = globalSelectedLocation;
368 if(!orgunit) orgunit = globalLocation;
370 var copy_request = new RemoteRequest( "open-ils.search",
371 "open-ils.search.biblio.record.copy_count",
372 orgunit.id(), record.doc_id() );
375 copy_request.search_id = search_id;
376 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
378 debug("Sending copy request " + search_id + ":" + record.doc_id() );
381 copy_request.setCompleteCallback(
384 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
386 debug("****** Copy Count Retrieval Error:\n" + E );