1 var globalMRResultPage = null; /* our global object */
3 MRResultPage.prototype = new AbstractRecordResultPage();
4 MRResultPage.prototype.constructor = MRResultPage;
5 MRResultPage.baseClass = AbstractRecordResultPage.constructor;
7 /* constructor for our singleton object */
8 function MRResultPage() {
9 debug("MRResultPage()");
10 //this.searchBar = new SearchBarChunk();
12 if( globalMRResultPage != null ) {
13 debug("MRResultPage() exists, returning");
14 return globalMRResultPage;
17 //this.progressBar = new ProgressBar(getById('progress_bar'));
19 globalMRResultPage = this;
23 /* returns the global instance. builds the instance if necessary. All client
24 * code should use this method */
25 MRResultPage.instance = function() {
26 if( globalMRResultPage != null ) {
27 return globalMRResultPage;
29 return new MRResultPage();
33 MRResultPage.buildExtendedLinks = function(record, page_id) {
38 MRResultPage.prototype.setPageTrail = function() {
40 var box = getById("page_trail");
43 var d = this.buildTrailLink("start",true);
47 d = this.buildTrailLink("advanced_search", true);
52 box.appendChild(this.buildDivider());
54 this.buildTrailLink("mr_result", false));
59 MRResultPage.prototype.next = function() {
61 var location = globalSelectedLocation;
63 location = globalLocation.id();
65 location = location.id();
67 /* if the user has changed the 'location' of the search, it will be
68 reflected when the user hits the next button. the search depth
69 will not change, however, because that is a different search */
71 "target", "mr_result",
72 "mr_search_type", this.stype,
73 "mr_search_query", this.string,
74 "mr_search_location", location,
75 "mr_search_depth", this.searchDepth,
81 MRResultPage.prototype.prev = function() {
82 if(this.page == 0 ) return;
85 var depth = globalSearchDepth;
86 var location = globalSelectedLocation;
88 location = globalLocation.id();
90 location = location.id();
92 /* if the user has changed the 'location' of the search, it will be
93 reflected when the user hits this button. the search depth
94 will not change, however, because that is a different search */
96 "target", "mr_result",
97 "mr_search_type", this.stype,
98 "mr_search_query", this.string,
99 "mr_search_location", location,
100 "mr_search_depth", this.searchDepth,
101 "page", this.page - 1
106 MRResultPage.prototype.addMenuItems = function(menu, record) {
107 menu.addItem("View Metarecord Details",
108 function() { alert(record.doc_id()); });
110 xulEvtMRResultDisplayed( menu, record );
113 MRResultPage.prototype.URLRefresh = function() {
116 "target", "mr_result",
117 "mr_search_type", this.stype,
118 "mr_search_query", this.string,
119 "mr_search_location", this.searchLocation,
120 "mr_search_depth", this.searchDepth,
125 MRResultPage.prototype.mkLink = function(id, type, value, title) {
132 debug("Making link with title: " + t);
137 href = createAppElement("a");
138 add_css_class(href,"record_result_title_link");
139 href.setAttribute("href",
140 "?target=record_result&page=0&mrid=" + id +
141 "&hits_per_page=" + this.hitsPerPage +
142 "&location=" + this.searchLocation +
143 "&depth=" + this.searchDepth );
144 href.appendChild(createAppTextNode(value));
145 href.title = "View titles for " + t + "";
149 href = createAppElement("a");
150 add_css_class(href,"record_result_title_link");
151 href.setAttribute("href",
152 "?target=record_result&page=0&mrid=" + id +
153 "&hits_per_page=" + this.hitsPerPage +
154 "&location=" + this.searchLocation +
155 "&depth=" + this.searchDepth );
156 href.title = "View titles for " + t + "";
161 href = createAppElement("a");
162 add_css_class(href,"record_result_author_link");
163 href.setAttribute("href",
164 "?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 " + t + "";
171 throw new EXArg("Unknown link type: " + type );
179 /* performs a new search */
180 MRResultPage.prototype.doSearch = function() {
183 debug("XUL IS " + isXUL() );
185 var string = paramObj.__mr_search_query;
186 var stype = paramObj.__mr_search_type;
187 var location = paramObj.__mr_search_location;
188 var depth = paramObj.__mr_search_depth;
189 var hitsper = paramObj.__hits_per_page;
191 lastSearchString = string;
192 lastSearchType = stype;
195 this.hitsPerPage = parseInt(hitsper);
197 debug("mr search params string " + string + " stype " + stype +
198 " location " + location + " depth " + depth );
200 if(depth == null || depth == "undefined")
201 depth = globalSearchDepth;
204 depth = findOrgDepth(globalLocation.ou_type());
206 if(location == null || location == "undefined") {
207 if(globalSelectedLocation)
208 location = globalSelectedLocation.id();
210 location = globalLocation.id();
213 if(!stype || !string) return;
215 if(this.searchDepth == null)
216 this.searchDepth = globalSearchDepth;
218 /* see if this is a new search */
219 if( isXUL() || /* don't cache client searches */
220 string != this.string ||
221 stype != this.stype ||
222 this.searchLocation != location ||
223 this.searchDepth != depth ) {
224 debug("Resetting MRSearch for search " + string);
228 debug("Not Resetting MRSearch for search " + string);
231 this.searchDepth = depth;
232 this.searchLocation = location;
234 this.string = string;
235 this.page = parseInt(paramObj.__page);
236 if(this.page == null) this.page = 0;
238 this.searchOffset = this.page * this.hitsPerPage;
242 var offset = parseInt(this.searchOffset);
243 var hitspp = parseInt(this.hitsPerPage);
245 /* is this just a call to next/prev? */
246 if( this.recordIDs && this.recordIDs[offset] != null ) {
247 debug("We have the first part of the ID's");
248 if( this.recordIDs[offset + (hitspp -1 )] != null ||
249 this.recordIDs[this.hitCount - 1] != null ) {
250 /* we already have all of the IDS */
251 debug("We alread have the required mr " +
252 "ids for the search: [" + this.string + "]");
253 this.collectRecords();
259 debug("MRResultPage doSearch() with type: "
260 + this.stype + " and search [" + this.string + "]"
261 + " and offset " + this.searchOffset +
262 " depth: " + depth + " location: " + location);
264 debug("gathering the search count\n");
267 if(this.searchOffset > 0 && this.hitCount > 0) {
268 this.buildNextLinks();
273 var method = "open-ils.search.biblio.class.count";
275 method = method + ".staff";
277 debug("Method: " + method);
279 if(isNaN(this.searchDepth)) this.searchDepth = 0;
280 if(isNaN(this.searchLocation)) this.searchLocation = 1;
282 var creq = new RemoteRequest(
283 "open-ils.search", method,
284 this.stype, this.string, this.searchLocation, this.searchDepth );
286 /* this request grabs the search count. When the counts come back
287 the metarecord ids are collected */
289 creq.setCompleteCallback(
293 obj.hitCount = req.getResultObject();
294 debug("Received hit count of " + obj.hitCount );
297 if(instanceOf(E, ex)) {
305 var row = getById("hourglass_row");
306 if(row) row.parentNode.removeChild(row);
309 if(obj.hitCount > 0) obj.buildNextLinks();
311 /* do the spell check and make suggestion if possible */
314 var row = getById("hourglass_row");
315 if(row) row.parentNode.removeChild(row);
333 MRResultPage.prototype.checkSpelling = function() {
334 if(this.hitCount > 3) return;
336 debug("Checking spelling on " + this.string );
338 var request = new RemoteRequest(
340 "open-ils.search.spell_check",
344 var response = request.getResultObject();
345 if(response && response != "0") {
347 debug("Received spell check response " + response );
349 var dymb = getById("did_you_mean_box");
350 dymb.appendChild(elem("br"));
354 href: "?target=mr_result&mr_search_type=" +
355 this.stype + "&page=0&mr_search_query=" +
356 encodeURIComponent(response)
360 add_css_class(ref,"record_result_author_link");
361 ref.appendChild(createAppTextNode(response));
362 ref.title = "Search for " + response + "";
364 dymb.appendChild(createAppTextNode("Did you mean "));
365 var ul = createAppElement("u");
366 dymb.appendChild(ul);
368 dymb.appendChild(createAppTextNode("?"));
372 /* expand search if results are too low... */
373 MRResultPage.prototype.buildExpandSearchLinks = function() {
376 var string = paramObj.__mr_search_query;
377 var stype = paramObj.__mr_search_type;
378 var location = paramObj.__mr_search_location;
379 var depth = paramObj.__mr_search_depth;
382 var div = elem("div");
386 MRResultPage.prototype.doMRSearch = function() {
389 var method = "open-ils.search.biblio.class";
391 /* now the count and search are simultaneous
392 if( this.hitCount > 5000 )
393 method = method + ".unordered";
397 method = method + ".staff";
399 debug("Search method is " + method);
401 var request = new RemoteRequest(
402 "open-ils.search", method,
403 obj.stype, obj.string,
405 obj.searchDepth, "50", obj.searchOffset );
407 request.setCompleteCallback(
410 var row = getById("hourglass_row");
412 row.parentNode.removeChild(row);
414 var result = req.getResultObject();
415 if(result == null) return;
416 result.count = obj.hitCount;
417 obj.gatherIDs(result)
418 obj.collectRecords();
419 obj.requestBatch.remove(req);
422 obj.requestBatch.add(request);
424 debug("Sent mr id search");
428 MRResultPage.prototype.collectRecords = function() {
430 debug("Collecting records...");
431 var i = this.searchOffset;
433 var row = getById("hourglass_row");
435 row.parentNode.removeChild(row);
437 /* ------------------------------------------------- */
440 var ids = new Array();
441 while( i < (this.searchOffset + this.hitsPerPage) )
442 ids.push(this.recordIDs[i++]);
444 debug("Retrieving IDs " + ids);
446 var request = new RemoteRequest( "open-ils.search",
447 "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve", ids );
448 this.requestBatch.add(request);
452 request.setCompleteCallback(
454 var records = req.getResultObject();
457 for(var i = 0; i!= records.length; i++) {
458 var rec = records[i];
459 debug("Displaying recocord " + rec.doc_id());
460 obj.displayRecord( rec, obj.searchOffset, i );
461 obj.doCopyCount( rec, obj.searchOffset, i );
463 obj.requestBatch.remove(request);
469 /* ------------------------------------------------- */
472 while( i < (this.searchOffset + this.hitsPerPage) ) {
473 var id = this.recordIDs[i];
475 if(id==null){ i++; continue; }
477 var request = new RemoteRequest( "open-ils.search",
478 "open-ils.search.biblio.metarecord.mods_slim.retrieve", id );
479 this.requestBatch.add(request);
480 debug( "Sending mods retrieval for metarecord " + id );
482 request.name = "record_request_" + i;
483 request.search_id = i;
484 request.page_id = parseInt(i) - parseInt(this.searchOffset);
486 /* define the callback for when we receive the record */
488 request.setCompleteCallback(
490 var record = req.getResultObject();
491 obj.displayRecord( record, req.search_id, req.page_id );
492 obj.doCopyCount( record, req.search_id, req.page_id );
493 obj.requestBatch.remove(req);
497 debug("Sending mods retrieval request for " + id);
505 MRResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
507 if(record==null || !record) return;
509 var copy_box = getById("record_result_copy_count_box_" + page_id );
511 var orgunit = globalSelectedLocation;
512 if(!orgunit) orgunit = globalLocation;
514 var method = "open-ils.search.biblio.metarecord.copy_count";
516 method = method + ".staff";
518 var copy_request = new RemoteRequest(
519 "open-ils.search", method,
520 this.searchLocation, record.doc_id() );
522 copy_request.search_id = search_id;
523 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
526 copy_request.setCompleteCallback(
529 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
531 debug("****** Copy Count Retrieval Error:\n" + E );