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,
76 "format", this.format,
82 MRResultPage.prototype.prev = function() {
83 if(this.page == 0 ) return;
86 var depth = globalSearchDepth;
87 var location = globalSelectedLocation;
89 location = globalLocation.id();
91 location = location.id();
93 /* if the user has changed the 'location' of the search, it will be
94 reflected when the user hits this button. the search depth
95 will not change, however, because that is a different search */
97 "target", "mr_result",
98 "mr_search_type", this.stype,
99 "mr_search_query", this.string,
100 "mr_search_location", location,
101 "mr_search_depth", this.searchDepth,
102 "format", this.format,
103 "page", this.page - 1
108 MRResultPage.prototype.addMenuItems = function(menu, record) {
109 menu.addItem("View Metarecord Details",
110 function() { alert(record.doc_id()); });
112 xulEvtMRResultDisplayed( menu, record );
115 MRResultPage.prototype.URLRefresh = function() {
118 "target", "mr_result",
119 "mr_search_type", this.stype,
120 "mr_search_query", this.string,
121 "mr_search_location", this.searchLocation,
122 "mr_search_depth", this.searchDepth,
123 "format", this.format,
128 MRResultPage.prototype.mkLink = function(id, type, value, title) {
135 debug("Making link with title: " + t);
140 href = createAppElement("a");
141 add_css_class(href,"record_result_title_link");
142 href.setAttribute("href",
143 "?target=record_result&page=0&mrid=" + id +
144 "&hits_per_page=" + this.hitsPerPage +
145 "&location=" + this.searchLocation +
146 "&format=" + this.format +
147 "&depth=" + this.searchDepth );
149 href.appendChild(createAppTextNode(value));
150 href.title = "View titles for " + t + "";
154 href = createAppElement("a");
155 add_css_class(href,"record_result_title_link");
156 href.setAttribute("href",
157 "?target=record_result&page=0&mrid=" + id +
158 "&hits_per_page=" + this.hitsPerPage +
159 "&location=" + this.searchLocation +
160 "&format=" + this.format +
161 "&depth=" + this.searchDepth );
163 href.title = "View titles for " + t + "";
168 href = createAppElement("a");
169 add_css_class(href,"record_result_author_link");
170 href.setAttribute("href",
171 "?target=mr_result&mr_search_type=author&page=0&mr_search_query=" +
172 encodeURIComponent(value) +
173 "&format=" + this.format );
175 href.appendChild(createAppTextNode(value));
176 href.title = "Author search for " + t + "";
180 throw new EXArg("Unknown link type: " + type );
188 /* performs a new search */
189 MRResultPage.prototype.doSearch = function() {
192 debug("XUL IS " + isXUL() );
194 var string = paramObj.__mr_search_query;
195 var stype = paramObj.__mr_search_type;
196 var location = paramObj.__mr_search_location;
197 var depth = paramObj.__mr_search_depth;
198 var hitsper = paramObj.__hits_per_page;
199 var format = paramObj.__format;
201 lastSearchString = string;
202 lastSearchType = stype;
205 this.hitsPerPage = parseInt(hitsper);
207 debug("mr search params string " + string + " stype " + stype +
208 " location " + location + " depth " + depth + " format " + format);
210 if(depth == null || depth == "undefined")
211 depth = globalSearchDepth;
214 depth = findOrgDepth(globalLocation.ou_type());
216 if(location == null || location == "undefined") {
217 if(globalSelectedLocation)
218 location = globalSelectedLocation.id();
220 location = globalLocation.id();
223 if(!stype || !string) return;
225 if(this.searchDepth == null)
226 this.searchDepth = globalSearchDepth;
228 /* see if this is a new search */
229 if( isXUL() || /* don't cache client searches */
230 string != this.string ||
231 stype != this.stype ||
232 this.searchLocation != location ||
233 this.format != format ||
234 this.searchDepth != depth ) {
235 debug("Resetting MRSearch for search " + string);
239 debug("Not Resetting MRSearch for search " + string);
242 this.searchDepth = depth;
243 this.searchLocation = location;
245 this.string = string;
246 this.page = parseInt(paramObj.__page);
247 this.format = format;
249 if(this.page == null) this.page = 0;
251 this.searchOffset = this.page * this.hitsPerPage;
255 var offset = parseInt(this.searchOffset);
256 var hitspp = parseInt(this.hitsPerPage);
258 /* is this just a call to next/prev? */
259 if( this.recordIDs && this.recordIDs[offset] != null ) {
260 debug("We have the first part of the ID's");
261 if( this.recordIDs[offset + (hitspp -1 )] != null ||
262 this.recordIDs[this.hitCount - 1] != null ) {
263 /* we already have all of the IDS */
264 debug("We alread have the required mr " +
265 "ids for the search: [" + this.string + "]");
266 this.collectRecords();
272 debug("MRResultPage doSearch() with type: "
273 + this.stype + " and search [" + this.string + "]"
274 + " and offset " + this.searchOffset +
275 " depth: " + depth + " location: " + location);
277 debug("gathering the search count\n");
280 if(this.searchOffset > 0 && this.hitCount > 0) {
281 this.buildNextLinks();
286 var method = "open-ils.search.biblio.class.count";
288 method = method + ".staff";
290 debug("Method: " + method);
292 if(isNaN(this.searchDepth)) this.searchDepth = 0;
293 if(isNaN(this.searchLocation)) this.searchLocation = 1;
295 var form = this.format;
296 if(this.format == "all") form = null;
297 var creq = new RemoteRequest(
298 "open-ils.search", method,
299 this.stype, this.string, this.searchLocation, this.searchDepth, form );
301 /* this request grabs the search count. When the counts come back
302 the metarecord ids are collected */
304 creq.setCompleteCallback(
308 obj.hitCount = req.getResultObject();
309 debug("Received hit count of " + obj.hitCount );
312 if(instanceOf(E, ex)) {
320 var row = getById("hourglass_row");
321 if(row) row.parentNode.removeChild(row);
324 if(obj.hitCount > 0) obj.buildNextLinks();
326 /* do the spell check and make suggestion if possible */
329 var row = getById("hourglass_row");
330 if(row) row.parentNode.removeChild(row);
348 MRResultPage.prototype.checkSpelling = function() {
349 if(this.hitCount > 3) return;
351 debug("Checking spelling on " + this.string );
353 var request = new RemoteRequest(
355 "open-ils.search.spell_check",
359 var response = request.getResultObject();
360 if(response && response != "0") {
362 debug("Received spell check response " + response );
364 var dymb = getById("did_you_mean_box");
365 dymb.appendChild(elem("br"));
369 href: "?target=mr_result&mr_search_type=" + this.stype +
370 "&page=0&mr_search_query=" + encodeURIComponent(response) +
371 "&format=" + this.format
375 add_css_class(ref,"record_result_author_link");
376 ref.appendChild(createAppTextNode(response));
377 ref.title = "Search for " + response + "";
379 dymb.appendChild(createAppTextNode("Did you mean "));
380 var ul = createAppElement("u");
381 dymb.appendChild(ul);
383 dymb.appendChild(createAppTextNode("?"));
387 /* expand search if results are too low... */
388 MRResultPage.prototype.buildExpandSearchLinks = function() {
391 var string = paramObj.__mr_search_query;
392 var stype = paramObj.__mr_search_type;
393 var location = paramObj.__mr_search_location;
394 var depth = paramObj.__mr_search_depth;
397 var div = elem("div");
401 MRResultPage.prototype.doMRSearch = function() {
404 var method = "open-ils.search.biblio.class";
406 /* now the count and search are simultaneous
407 if( this.hitCount > 5000 )
408 method = method + ".unordered";
412 method = method + ".staff";
414 debug("Search method is " + method);
416 var form = this.format;
417 if(this.format == "all") form = null;
419 var request = new RemoteRequest(
420 "open-ils.search", method, obj.stype, obj.string, obj.searchLocation,
421 obj.searchDepth, "50", obj.searchOffset, form );
423 request.setCompleteCallback(
426 var row = getById("hourglass_row");
428 row.parentNode.removeChild(row);
430 var result = req.getResultObject();
431 if(result == null) return;
432 result.count = obj.hitCount;
433 obj.gatherIDs(result)
434 obj.collectRecords();
435 obj.requestBatch.remove(req);
438 obj.requestBatch.add(request);
440 debug("Sent mr id search");
444 MRResultPage.prototype.collectRecords = function() {
446 debug("Collecting records...");
447 var i = this.searchOffset;
449 var row = getById("hourglass_row");
451 row.parentNode.removeChild(row);
453 /* ------------------------------------------------- */
456 var ids = new Array();
457 while( i < (this.searchOffset + this.hitsPerPage) )
458 ids.push(this.recordIDs[i++]);
460 debug("Retrieving IDs " + ids);
462 var request = new RemoteRequest( "open-ils.search",
463 "open-ils.search.biblio.metarecord.mods_slim.batch.retrieve", ids );
464 this.requestBatch.add(request);
468 request.setCompleteCallback(
470 var records = req.getResultObject();
473 for(var i = 0; i!= records.length; i++) {
474 var rec = records[i];
475 debug("Displaying recocord " + rec.doc_id());
476 obj.displayRecord( rec, obj.searchOffset, i );
477 obj.doCopyCount( rec, obj.searchOffset, i );
479 obj.requestBatch.remove(request);
485 /* ------------------------------------------------- */
488 while( i < (this.searchOffset + this.hitsPerPage) ) {
489 var id = this.recordIDs[i];
491 if(id==null){ i++; continue; }
493 var request = new RemoteRequest( "open-ils.search",
494 "open-ils.search.biblio.metarecord.mods_slim.retrieve", id );
495 this.requestBatch.add(request);
496 debug( "Sending mods retrieval for metarecord " + id );
498 request.name = "record_request_" + i;
499 request.search_id = i;
500 request.page_id = parseInt(i) - parseInt(this.searchOffset);
502 /* define the callback for when we receive the record */
504 request.setCompleteCallback(
506 var record = req.getResultObject();
507 obj.displayRecord( record, req.search_id, req.page_id );
508 obj.doCopyCount( record, req.search_id, req.page_id );
509 obj.requestBatch.remove(req);
513 debug("Sending mods retrieval request for " + id);
521 MRResultPage.prototype.doCopyCount = function( record, search_id, page_id ) {
523 if(record==null || !record) return;
525 var copy_box = getById("record_result_copy_count_box_" + page_id );
527 var orgunit = globalSelectedLocation;
528 if(!orgunit) orgunit = globalLocation;
530 var method = "open-ils.search.biblio.metarecord.copy_count";
532 method = method + ".staff";
534 var copy_request = new RemoteRequest(
535 "open-ils.search", method,
536 this.searchLocation, record.doc_id() );
538 copy_request.search_id = search_id;
539 copy_request.name = "copy_request_" + (search_id+this.searchOffset);
542 copy_request.setCompleteCallback(
545 obj.displayCopyCounts(req.getResultObject(), search_id, page_id );
547 debug("****** Copy Count Retrieval Error:\n" + E );