]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rresult.js
fixed form finder to work if no item type is chosen
[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 args = {};
87         args[PARAM_RDEPTH] = findOrgDepth(globalOrgTree);
88         goTo(buildOPACLink(args));
89 }
90
91 function rresultContractSearch() {
92         var args = {};
93         RDEPTH = null;
94         args[PARAM_OFFSET] = 0;
95         goTo(buildOPACLink(args));
96 }
97
98
99 function rresultGetDepth() {
100         if( getRdepth() != null) return getRdepth();
101         return getDepth();
102 }
103
104
105 function rresultGetForm() {
106         var form;
107
108         if(getTform())  /* did the user select a format from the icon list (temporary) */
109                 form = (getTform() == 'all') ? null : getTform();
110         else  /* did the use select a format from simple search dropdown */
111                 form = (getForm() == 'all') ? null : getForm();
112
113         if(!form) { /* did the user select a format from the advanced search */
114                 form = getItemType();
115                 var f = getItemForm();
116
117                 if(form) {
118                         form = form.replace(/,/,'');
119                         if(f) form += '-' + f;
120                 } else {
121                         if(f) form = '-' + f;
122                 }
123         }
124
125         return form;
126 }
127
128
129 function rresultCollectMARCIds() {
130
131         var args                        = {};
132         args.searches   = JSON2js(getSearches());
133         args.limit              = 200;
134         args.org_unit   = globalOrgTree.id();
135         args.depth              = 0;
136
137         var req = new Request(FETCH_ADV_MARC_MRIDS, args);
138         req.callback(rresultHandleRIds);
139         req.send();
140 }
141
142 function rresultHandleList() {
143         var ids = new CGI().param(PARAM_RLIST);
144         if(ids) _rresultHandleIds(ids, ids.length);
145 }
146
147 var rresultTries = 0;
148 function rresultHandleRIds(r) {
149         var res = r.getResultObject();
150
151         if( res.count == 0 ) {
152
153                 if( rresultTries == 0 ) {
154                         rresultTries++;
155                         var form = rresultGetForm();
156                         var args = { format : form, org : getLocation(), depth : findOrgDepth(globalOrgTree) };
157                         var req = new Request(FETCH_RIDS, getMrid(), args );
158                         req.callback( rresultHandleRIds );
159                         req.send();
160                         unHideMe($('no_formats'));
161                         hideMe($('rresult_show_all'));
162                 }
163
164         } else {
165
166                 _rresultHandleIds(res.ids, res.count);
167         }
168 }
169
170 function _rresultHandleIds(ids, count) {
171         HITCOUNT = parseInt(count);
172         runEvt('result', 'hitCountReceived');
173         runEvt('result', 'idsReceived', ids);
174 }
175
176 function rresultCollectRecords(ids) {
177         runEvt("result", "preCollectRecords");
178         var x = 0;
179         for( var i = getOffset(); i!= getDisplayCount() + getOffset(); i++ ) {
180                 if(ids[i] == null) break;
181                 var req = new Request(FETCH_RMODS, parseInt(ids[i]));
182                 req.callback(rresultHandleMods);
183                 req.request.userdata = x++;
184                 req.send();
185         }
186 }
187
188 function rresultHandleMods(r) {
189         var rec = r.getResultObject();
190         runEvt('result', 'recordReceived', rec, r.userdata, false);
191         resultCollectCopyCounts(rec, r.userdata, FETCH_R_COPY_COUNTS);
192         if(resultPageIsDone()) {
193                 runEvt('result', 'allRecordsReceived', recordsCache);
194                 unHideMe($('copyright_block')); 
195         }
196 }
197
198
199 function rresultLaunchDrawn(id, node) {
200         runEvt("rresult", "recordDrawn", id, node);
201 }
202
203
204 function rresultDoRecordSearch() { 
205         resultCollectSearchIds(true, SEARCH_RS, rresultFilterSearchResults ); }
206 function rresultDoRecordMultiSearch() { 
207         resultCollectSearchIds(false, SEARCH_RS, rresultFilterSearchResults ); }
208
209 /*
210 function _rresultCollectSearchIds( type ) {
211
212         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
213         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
214
215         var form = parseForm(getForm());
216         var item_type = form.item_type;
217         var item_form = form.item_form;
218
219         var args = {};
220
221         if( type ) {
222                 args.searches = {};
223                 args.searches[getRtype()] = {};
224                 args.searches[getRtype()].term = getTerm();
225         } else {
226                 args.searches = JSON2js(getAdvTerm());
227         }
228
229         args.org_unit = getLocation();
230         args.depth    = getDepth();
231         args.limit    = rresultLimit;
232         args.offset   = getOffset();
233
234         if(sort) args.sort = sort;
235         if(sortdir) args.sort_dir = sortdir;
236         if(item_type) args.item_type    = item_type;
237         if(item_form) args.item_form    = item_form;
238
239         var req = new Request(SEARCH_RS, args);
240         req.callback(rresultFilterSearchResults);
241         req.send();
242 }
243 */
244
245
246 function rresultFilterSearchResults(r) {
247         var result = r.getResultObject();
248         var ids = [];
249         for( var i = 0; i != result.ids.length; i++ ) 
250                 ids.push(result.ids[i][0]);
251         _rresultHandleIds( ids, result.count );
252 }
253
254