]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/javascript/lib/js/opac/mresult.js
b650eb58ad9f3f7a76e2a17121a44915557116f6
[working/Evergreen.git] / Open-ILS / src / javascript / lib / js / opac / mresult.js
1 var records = new Array();
2 var ranks = new Array();
3 var table;
4 var rowtemplate;
5
6 function mresultDoSearch() {
7
8         table = getId(config.ids.result.main_table);
9         rowtemplate = table.removeChild(getId(config.ids.result.row_template));
10         removeChildren(table);
11
12         if(getOffset() == 0 || getHitCount() == null ) {
13                 mresultGetCount();
14                 mresultCollectIds();
15         } else { 
16                 resultSetInfo();
17                 mresultCollectIds();
18                 mresultCollectRecords(); 
19         }
20 }
21
22 function mresultGetCount() {
23         var req = new Request(FETCH_MRCOUNT, 
24                         getStype(), getTerm(), getLocation(), getDepth(), getForm() );
25         req.callback( function(r) {
26                 HITCOUNT = parseInt(r.getResultObject());
27                 resultSetInfo(); });
28         req.send();
29 }
30
31
32 /* performs the actual search */
33 function mresultCollectIds() {
34         var req = new Request(FETCH_MRIDS, getStype(), getTerm(), 
35                         getLocation(), getDepth(), getDisplayCount(), getOffset(), getForm() );
36         req.callback( function(r) {
37                 mresultSetRecords(r.getResultObject().ids);
38                 mresultCollectRecords(); });
39         req.send();
40 }
41
42 function mresultSetRecords(idstruct) {
43         var o = getOffset();
44         for( var x = o; x!= idstruct.length + o; x++ ) {
45                 records[x] = idstruct[x - o][0];
46                 ranks[x] = idstruct[x - o][1];
47         }
48 }
49
50
51 function mresultCollectRecords() {
52         for( var x = getOffset(); x!= getDisplayCount() + getOffset(); x++ ) {
53                 if(isNull(records[x])) break;
54
55                 var req = new Request(FETCH_MRMODS, records[x]);
56                 req.callback(function(r){
57                                 var rec = r.getResultObject();
58                                 resultDisplayRecord(rec, rowtemplate, true);
59                                 mresultCollectCopyCounts(rec);
60                 });
61                 req.send();
62
63                 /*              
64                 if( x == (getDisplayCount() + getOffset()) - 1 ) {
65                         getId(config.ids.result.top_div).appendChild(
66                                 getId(config.ids.result.nav_links).cloneNode(true));
67                 }
68                 */
69         }
70 }
71
72 function mresultCollectCopyCounts(rec) {
73         if(rec == null) return;
74         if(rec.doc_id() == null) return;
75
76         var req = new Request(FETCH_MR_COPY_COUNTS, getLocation(), rec.doc_id() );
77         req.callback(function(r){ mresultDisplayCopyCounts(rec, r.getResultObject()); });
78         req.send();
79 }
80
81 function mresultDisplayCopyCounts(rec, copy_counts) {
82         if(copy_counts == null || rec == null) return;
83         var i = 0;
84         while(copy_counts[i] != null) {
85                 var cell = getId("copy_count_cell_" + i +"_" + rec.doc_id());
86                 cell.appendChild(text(copy_counts[i].available + " / " + copy_counts[i].count));
87                 i++;
88         }
89 }
90
91
92