]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rresult.js
loaded form from item-type/form if no basic format is selected
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rresult.js
1 var records = new Array();
2 var table;
3 var rowtemplate;
4 var rresultLimit = 200;
5
6 function rresultUnload() { removeChildren(table); table = null;}
7
8 attachEvt("common", "unload", rresultUnload);
9 attachEvt("common", "run", rresultDoSearch);
10 attachEvt("result", "idsReceived", rresultCollectRecords); 
11 attachEvt("result", "recordDrawn", rresultLaunchDrawn); 
12
13 hideMe($('copyright_block')); 
14
15 function rresultDoSearch() {
16
17         swapCanvas($('loading_alt'));
18         /*
19         if(getOffset() == 0) swapCanvas($('loading_alt'));
20         */
21
22         table = G.ui.result.main_table;
23         hideMe(G.ui.result.row_template);
24         while( table.parentNode.rows.length <= (getDisplayCount() +1) ) 
25                 hideMe(table.appendChild(G.ui.result.row_template.cloneNode(true)));
26         rresultCollectIds();
27 }
28
29 function rresultCollectIds() {
30         var ids;
31         switch(getRtype()) {
32
33                 case RTYPE_COOKIE:
34                         ids = JSON2js(cookieManager.read(COOKIE_RIDS));
35                         _rresultHandleIds( ids, ids.length );
36                         break;
37
38                 case RTYPE_TITLE:
39                 case RTYPE_AUTHOR:
40                 case RTYPE_SUBJECT:
41                 case RTYPE_SERIES:
42                 case RTYPE_KEYWORD:
43                         rresultDoRecordSearch();
44                         break;
45
46                 case RTYPE_MULTI:
47                         rresultDoRecordMultiSearch();
48                         break;
49                         
50                 case RTYPE_LIST :
51                         rresultHandleList();
52                         break;
53
54                 case RTYPE_MARC :
55                         rresultCollectMARCIds();
56                         break;
57
58                 case RTYPE_MRID :
59                 case null :
60                 case "" :
61                 defaut:
62                         var form = rresultGetForm();
63                         var args = { format : form, org : getLocation(), depth : rresultGetDepth() };
64                         var req = new Request(FETCH_RIDS, getMrid(), args);
65                         req.callback( rresultHandleRIds );
66                         req.send();
67
68                         if( rresultGetDepth() != findOrgDepth(globalOrgTree) ) {
69                                 unHideMe($('rresult_show_all'));
70                                 var link = $('rresult_show_all_link');
71                                 link.appendChild( text(
72                                         findOrgType(globalOrgTree.ou_type()).opac_label()));
73
74                         } else {
75                                 if( rresultGetDepth() != getDepth() ) { /* inside a limited display */
76                                         var link = $('rresult_show_here_link');
77                                         link.appendChild( text(
78                                                 findOrgType(findOrgUnit(getLocation()).ou_type()).opac_label()));
79                                         unHideMe($('rresult_show_here'));
80                                 }
81                         }
82         }
83 }
84
85 function rresultExpandSearch() {
86         var link = buildOPACLink();
87         link += "&tmpdepth=" + findOrgDepth(globalOrgTree);
88         goTo(link);
89 }
90
91
92 function rresultGetDepth() {
93         var cgi = new CGI();
94         if(cgi.param('tmpdepth'))
95                 return cgi.param('tmpdepth');
96         return getDepth();
97 }
98
99
100 function rresultGetForm() {
101         var form;
102
103         if(getTform())  /* did the user select a format from the icon list (temporary) */
104                 form = (getTform() == 'all') ? null : getTform();
105         else  /* did the use select a format from simple search dropdown */
106                 form = (getForm() == 'all') ? null : getForm();
107
108         if(!form) { /* did the user select a format from the advanced search */
109                 form = getItemType();
110                 if(form) {
111                         form = form.replace(/,/,'');
112                         var f = getItemForm();
113                         if(f) form += '-' + f;
114                 }
115         }
116
117         return form;
118 }
119
120
121 function rresultCollectMARCIds() {
122
123         var args                        = {};
124         args.searches   = JSON2js(getSearches());
125         args.limit              = 200;
126         args.org_unit   = globalOrgTree.id();
127         args.depth              = 0;
128
129         var req = new Request(FETCH_ADV_MARC_MRIDS, args);
130         req.callback(rresultHandleRIds);
131         req.send();
132 }
133
134 function rresultHandleList() {
135         var ids = new CGI().param(PARAM_RLIST);
136         if(ids) _rresultHandleIds(ids, ids.length);
137 }
138
139 var rresultTries = 0;
140 function rresultHandleRIds(r) {
141         var res = r.getResultObject();
142
143         if( res.count == 0 ) {
144
145                 if( rresultTries == 0 ) {
146                         rresultTries++;
147                         var form = rresultGetForm();
148                         var args = { format : form, org : getLocation(), depth : findOrgDepth(globalOrgTree) };
149                         var req = new Request(FETCH_RIDS, getMrid(), args );
150                         req.callback( rresultHandleRIds );
151                         req.send();
152                         unHideMe($('no_formats'));
153                         hideMe($('rresult_show_all'));
154                 }
155
156         } else {
157
158                 _rresultHandleIds(res.ids, res.count);
159         }
160 }
161
162 function _rresultHandleIds(ids, count) {
163         HITCOUNT = parseInt(count);
164         runEvt('result', 'hitCountReceived');
165         runEvt('result', 'idsReceived', ids);
166 }
167
168 function rresultCollectRecords(ids) {
169         runEvt("result", "preCollectRecords");
170         var x = 0;
171         for( var i = getOffset(); i!= getDisplayCount() + getOffset(); i++ ) {
172                 if(ids[i] == null) break;
173                 var req = new Request(FETCH_RMODS, parseInt(ids[i]));
174                 req.callback(rresultHandleMods);
175                 req.request.userdata = x++;
176                 req.send();
177         }
178 }
179
180 function rresultHandleMods(r) {
181         var rec = r.getResultObject();
182         runEvt('result', 'recordReceived', rec, r.userdata, false);
183         resultCollectCopyCounts(rec, r.userdata, FETCH_R_COPY_COUNTS);
184         if(resultPageIsDone()) {
185                 runEvt('result', 'allRecordsReceived', recordsCache);
186                 unHideMe($('copyright_block')); 
187         }
188 }
189
190
191 function rresultLaunchDrawn(id, node) {
192         runEvt("rresult", "recordDrawn", id, node);
193 }
194
195
196 function rresultDoRecordSearch() { 
197         resultCollectSearchIds(true, SEARCH_RS, rresultFilterSearchResults ); }
198 function rresultDoRecordMultiSearch() { 
199         resultCollectSearchIds(false, SEARCH_RS, rresultFilterSearchResults ); }
200
201 /*
202 function _rresultCollectSearchIds( type ) {
203
204         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
205         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
206
207         var form = parseForm(getForm());
208         var item_type = form.item_type;
209         var item_form = form.item_form;
210
211         var args = {};
212
213         if( type ) {
214                 args.searches = {};
215                 args.searches[getRtype()] = {};
216                 args.searches[getRtype()].term = getTerm();
217         } else {
218                 args.searches = JSON2js(getAdvTerm());
219         }
220
221         args.org_unit = getLocation();
222         args.depth    = getDepth();
223         args.limit    = rresultLimit;
224         args.offset   = getOffset();
225
226         if(sort) args.sort = sort;
227         if(sortdir) args.sort_dir = sortdir;
228         if(item_type) args.item_type    = item_type;
229         if(item_form) args.item_form    = item_form;
230
231         var req = new Request(SEARCH_RS, args);
232         req.callback(rresultFilterSearchResults);
233         req.send();
234 }
235 */
236
237
238 function rresultFilterSearchResults(r) {
239         var result = r.getResultObject();
240         var ids = [];
241         for( var i = 0; i != result.ids.length; i++ ) 
242                 ids.push(result.ids[i][0]);
243         _rresultHandleIds( ids, result.count );
244 }
245
246