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 )
100 RecordResultPage.prototype.addMenuItems = function(menu, record) {
102 var func = buildViewMARCWindow(record);
103 menu.addItem("View MARC", func);
105 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 var win = window.open("about:blank","MARC_" + id,
124 "location=0,menubar=0,status=0,resizeable,resize," +
125 "outerHeight=500,outerWidth=400,height=500," +
126 "width=400,scrollbars=1,screenX=100," +
127 "screenY=100,top=100,left=100,alwaysraised,chrome" )
129 win.document.write(html);
130 win.document.close();
131 win.document.title = "View MARC";
139 RecordResultPage.prototype.mkLink = function(id, type, value) {
143 var org = globalSelectedLocation;
145 org = globalLocation;
151 href = createAppElement("a");
152 add_css_class(href,"record_result_title_link");
153 href.setAttribute("href",
154 "?target=record_detail&record=" + id +
155 "&location=" + org.id() +
156 "&depth=" + globalSearchDepth );
157 href.appendChild(createAppTextNode(value));
158 href.title = "View title details for " + value;
162 href = createAppElement("a");
163 add_css_class(href,"record_result_author_link");
164 href.setAttribute("href","?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
165 encodeURIComponent(value));
166 href.appendChild(createAppTextNode(value));
167 href.title = "Author search for " + value + "";
171 href = createAppElement("a");
172 add_css_class(href,"record_result_image_link");
173 href.setAttribute("href",
174 "?target=record_detail&page=0&mrid=" + id +
175 "&location=" + org.id() +
176 "&depth=" + globalSearchDepth );
177 href.title = "View title details for " + value;
181 throw new EXArg("Unknown link type: " + type );
188 RecordResultPage.prototype.toString = function() {
190 return "\nRecordResultPage:\n" +
191 "page: " + this.page + "\n" +
192 "searchOffset: " + this.searchOffset + "\n" +
193 "recordIDs: " + this.recordIDs + "\n" +
194 "hitCount: " + this.hitCount + "\n" +
195 "hitsPerPage: " + this.hitsPerPage + "\n";
200 RecordResultPage.prototype.isNewSearch = function() {
207 /* performs a new search */
208 RecordResultPage.prototype.doSearch = function() {
210 if(recordResultRedirect) {
211 /* if the user is just hitting the 'back' button */
212 recordResultRedirect = false;
217 debug( "Key Value Array \n" + js2JSON( paramObj ) );
219 this.page = parseInt(paramObj.__page);
220 var hitsper = paramObj.__hits_per_page;
221 this.format = paramObj.__format;
222 if(!this.format) this.format = "all";
225 this.hitsPerPage = parseInt(hitsper);
227 debug("******* Hits per = " + this.hitsPerPage);
229 this.hitsPerPageSelector = getById('hits_per_page');
230 for( var i in this.hitsPerPageSelector.options ) {
231 var hits_obj = this.hitsPerPageSelector.options[i];
232 if(hits_obj == null) continue;
233 var hits = hits_obj.value;
235 if( this.hitsPerPage == parseInt(hits) ) {
236 this.hitsPerPageSelector.options[i].selected = true;
237 debug("Setting selected on selector with hits " + hits);
241 if(this.page == null)
244 this.searchOffset = this.page * this.hitsPerPage;
247 if(this.isNewSearch()) {
248 debug("RecordResultPage resetting search..");
252 var offset = parseInt(this.searchOffset);
253 var hitspp = parseInt(this.hitsPerPage);
255 /* is this just a call to next/prev? */
256 if( this.recordIDs && this.recordIDs[offset] != null ) {
257 debug("We have the first part of the ID's");
258 if( this.recordIDs[offset + (hitspp -1 )] != null ||
259 this.recordIDs[this.hitCount - 1] != null ) {
260 /* we already have all of the IDS */
261 debug("We alread have the required mr " +
262 "ids for the search: [" + this.string + "]");
263 this.collectRecords();
269 if( paramObj.__mrid != null ) {
270 this.mrSearch(paramObj.__mrid);
274 if( paramObj.__search == "global" ) {
276 if( paramObj.__tcn != null ) {
277 this.globalSearch("tcn", paramObj.__tcn);
281 if( paramObj.__isbn != null ) {
282 this.globalSearch("isbn", paramObj.__isbn);
285 if( paramObj.__barcode != null ) {
286 this.globalSearch("barcode", paramObj.__barcode);
295 /* these are the simple global searches */
296 RecordResultPage.prototype.globalSearch = function(type, term) {
298 if( !term || term.length < 2 )
299 throw new EXArg( "globalSearch needs valid term: " + term );
301 debug("Performing Global search [" + type + "] for term: " + term );
306 method = "open-ils.search.biblio.tcn";
310 method = "open-ils.search.biblio.isbn";
314 method = "open-ils.search.biblio.find_by_barcode";
318 var request = new RemoteRequest( "open-ils.search", method, term );
321 request.setCompleteCallback(
324 var result = req.getResultObject();
325 debug( "Global Search returned: " + js2JSON(result) );
326 obj.gatherIDs(result)
327 obj.collectRecords();
328 } catch(E) { throw ("Search Error " + E ); }
335 RecordResultPage.prototype.mrSearch = function(mrid) {
338 var method = "open-ils.search.biblio.metarecord_to_records";
339 if(this.format == "all")
340 request = new RemoteRequest("open-ils.search", method, mrid );
342 request = new RemoteRequest("open-ils.search", method, mrid, this.format );
344 debug("Gathering doc ids for metarecord " + mrid );
347 request.setCompleteCallback(
350 var ids = req.getResultObject();
353 if(!recordResultRedirect) { /* if the user isn't just hitting the 'back' button */
354 if(parseInt(obj.hitCount) == 1) {
355 recordResultRedirect = true;
356 debug("Redirecting to record detail page with record " + obj.recordIDs[0] );
359 "target", "record_detail",
360 "record", obj.recordIDs[0] ] );
364 recordResultRedirect = false;
368 obj.collectRecords();
369 } catch(E) { throw ("Search Error " + E ); }
375 RecordResultPage.prototype.collectRecords = function() {
377 var i = this.searchOffset;
379 while( i < (this.searchOffset + this.hitsPerPage) ) {
380 var id = this.recordIDs[i];
382 if(id==null){ i++; continue; }
384 var request = new RemoteRequest( "open-ils.search",
385 "open-ils.search.biblio.record.mods_slim.retrieve", id );
387 request.name = "record_request_" + i;
388 request.search_id = i;
389 request.page_id = parseInt(i) - parseInt(this.searchOffset);
391 /* define the callback for when we receive the record */
393 request.setCompleteCallback(
395 var record = req.getResultObject();
396 obj.displayRecord( record, req.search_id, req.page_id );
397 obj.doCopyCount( record, req.search_id, req.page_id );
406 RecordResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
408 var copy_box = getById("record_result_copy_count_box_" + page_id );
410 /* kick off the copy count search */
411 var orgunit = globalSelectedLocation;
412 if(!orgunit) orgunit = globalLocation;
414 var copy_request = new RemoteRequest( "open-ils.search",
415 "open-ils.search.biblio.record.copy_count",
416 orgunit.id(), record.doc_id() );
419 copy_request.search_id = search_id;
420 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
422 debug("Sending copy request " + search_id + ":" + record.doc_id() );
425 copy_request.setCompleteCallback(
428 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
430 debug("****** Copy Count Retrieval Error:\n" + E );