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) {
141 var org = globalSelectedLocation;
143 org = globalLocation;
149 href = createAppElement("a");
150 add_css_class(href,"record_result_title_link");
151 href.setAttribute("href",
152 "?target=record_detail&record=" + id +
153 "&location=" + org.id() +
154 "&depth=" + globalSearchDepth );
155 href.appendChild(createAppTextNode(value));
156 href.title = "View title details for " + value;
160 href = createAppElement("a");
161 add_css_class(href,"record_result_author_link");
162 href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
163 encodeURIComponent(value));
164 href.appendChild(createAppTextNode(value));
165 href.title = "Author search for " + value + "";
169 href = createAppElement("a");
170 add_css_class(href,"record_result_image_link");
171 href.setAttribute("href",
172 "?target=record_detail&page=0&mrid=" + id +
173 "&location=" + org.id() +
174 "&depth=" + globalSearchDepth );
175 href.title = "View title details for " + value;
179 throw new EXArg("Unknown link type: " + type );
186 RecordResultPage.prototype.toString = function() {
188 return "\nRecordResultPage:\n" +
189 "page: " + this.page + "\n" +
190 "searchOffset: " + this.searchOffset + "\n" +
191 "recordIDs: " + this.recordIDs + "\n" +
192 "hitCount: " + this.hitCount + "\n" +
193 "hitsPerPage: " + this.hitsPerPage + "\n";
198 RecordResultPage.prototype.isNewSearch = function() {
205 /* performs a new search */
206 RecordResultPage.prototype.doSearch = function() {
208 if(recordResultRedirect) {
209 /* if the user is just hitting the 'back' button */
210 recordResultRedirect = false;
215 debug( "Key Value Array \n" + js2JSON( paramObj ) );
217 this.page = parseInt(paramObj.__page);
218 var hitsper = paramObj.__hits_per_page;
221 this.hitsPerPage = parseInt(hitsper);
223 debug("******* Hits per = " + this.hitsPerPage);
225 this.hitsPerPageSelector = getById('hits_per_page');
226 for( var i in this.hitsPerPageSelector.options ) {
227 var hits_obj = this.hitsPerPageSelector.options[i];
228 if(hits_obj == null) continue;
229 var hits = hits_obj.value;
231 if( this.hitsPerPage == parseInt(hits) ) {
232 this.hitsPerPageSelector.options[i].selected = true;
233 debug("Setting selected on selector with hits " + hits);
237 if(this.page == null)
240 this.searchOffset = this.page * this.hitsPerPage;
243 if(this.isNewSearch()) {
244 debug("RecordResultPage resetting search..");
248 var offset = parseInt(this.searchOffset);
249 var hitspp = parseInt(this.hitsPerPage);
251 /* is this just a call to next/prev? */
252 if( this.recordIDs && this.recordIDs[offset] != null ) {
253 debug("We have the first part of the ID's");
254 if( this.recordIDs[offset + (hitspp -1 )] != null ||
255 this.recordIDs[this.hitCount - 1] != null ) {
256 /* we already have all of the IDS */
257 debug("We alread have the required mr " +
258 "ids for the search: [" + this.string + "]");
259 this.collectRecords();
265 if( paramObj.__mrid != null ) {
266 this.mrSearch(paramObj.__mrid);
270 if( paramObj.__search == "global" ) {
272 if( paramObj.__tcn != null ) {
273 this.globalSearch("tcn", paramObj.__tcn);
277 if( paramObj.__isbn != null ) {
278 this.globalSearch("isbn", paramObj.__isbn);
281 if( paramObj.__barcode != null ) {
282 this.globalSearch("barcode", paramObj.__barcode);
291 /* these are the simple global searches */
292 RecordResultPage.prototype.globalSearch = function(type, term) {
294 if( !term || term.length < 2 )
295 throw new EXArg( "globalSearch needs valid term: " + term );
297 debug("Performing Global search [" + type + "] for term: " + term );
302 method = "open-ils.search.biblio.tcn";
306 method = "open-ils.search.biblio.isbn";
310 method = "open-ils.search.biblio.find_by_barcode";
314 var request = new RemoteRequest( "open-ils.search", method, term );
317 request.setCompleteCallback(
320 var result = req.getResultObject();
321 debug( "Global Search returned: " + js2JSON(result) );
322 obj.gatherIDs(result)
323 obj.collectRecords();
324 } catch(E) { throw ("Search Error " + E ); }
331 RecordResultPage.prototype.mrSearch = function(mrid) {
333 var request = new RemoteRequest("open-ils.search",
334 "open-ils.search.biblio.metarecord_to_records", mrid );
335 debug("Gathering doc ids for metarecord " + mrid );
338 request.setCompleteCallback(
341 obj.gatherIDs(req.getResultObject());
343 if(!recordResultRedirect) { /* if the user isn't just hitting the 'back' button */
344 if(parseInt(obj.hitCount) == 1) {
345 recordResultRedirect = true;
346 debug("Redirecting to record detail page with record " + obj.recordIDs[0] );
348 "target", "record_detail",
349 "record", obj.recordIDs[0] ] );
353 recordResultRedirect = false;
357 obj.collectRecords();
358 } catch(E) { throw ("Search Error " + E ); }
364 RecordResultPage.prototype.collectRecords = function() {
366 var i = this.searchOffset;
368 while( i < (this.searchOffset + this.hitsPerPage) ) {
369 var id = this.recordIDs[i];
371 if(id==null){ i++; continue; }
373 var request = new RemoteRequest( "open-ils.search",
374 "open-ils.search.biblio.record.mods_slim.retrieve", id );
376 request.name = "record_request_" + i;
377 request.search_id = i;
378 request.page_id = parseInt(i) - parseInt(this.searchOffset);
380 /* define the callback for when we receive the record */
382 request.setCompleteCallback(
384 var record = req.getResultObject();
385 obj.displayRecord( record, req.search_id, req.page_id );
386 obj.doCopyCount( record, req.search_id, req.page_id );
395 RecordResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
397 var copy_box = getById("record_result_copy_count_box_" + page_id );
399 /* kick off the copy count search */
400 var orgunit = globalSelectedLocation;
401 if(!orgunit) orgunit = globalLocation;
403 var copy_request = new RemoteRequest( "open-ils.search",
404 "open-ils.search.biblio.record.copy_count",
405 orgunit.id(), record.doc_id() );
408 copy_request.search_id = search_id;
409 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
411 debug("Sending copy request " + search_id + ":" + record.doc_id() );
414 copy_request.setCompleteCallback(
417 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
419 debug("****** Copy Count Retrieval Error:\n" + E );