]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rresult.js
moved isbn/issn searches to the rresult page where they belong
[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_ISBN :
59                         rresultCollectISBNIds();
60                         break;
61
62                 case RTYPE_ISSN :
63                         rresultCollectISSNIds();
64                         break;
65
66
67                 case RTYPE_MRID :
68                 case null :
69                 case "" :
70                 defaut:
71                         var form = rresultGetForm();
72                         var args = { format : form, org : getLocation(), depth : rresultGetDepth() };
73                         var req = new Request(FETCH_RIDS, getMrid(), args);
74                         req.callback( rresultHandleRIds );
75                         req.send();
76
77                         if( rresultGetDepth() != findOrgDepth(globalOrgTree) ) {
78                                 unHideMe($('rresult_show_all'));
79                                 var link = $('rresult_show_all_link');
80                                 link.appendChild( text(
81                                         findOrgType(globalOrgTree.ou_type()).opac_label()));
82
83                         } else {
84                                 if( rresultGetDepth() != getDepth() ) { /* inside a limited display */
85                                         var link = $('rresult_show_here_link');
86                                         link.appendChild( text(
87                                                 findOrgType(findOrgUnit(getLocation()).ou_type()).opac_label()));
88                                         unHideMe($('rresult_show_here'));
89                                 }
90                         }
91         }
92 }
93
94 function rresultExpandSearch() {
95         var args = {};
96         args[PARAM_RDEPTH] = findOrgDepth(globalOrgTree);
97         goTo(buildOPACLink(args));
98 }
99
100 function rresultContractSearch() {
101         var args = {};
102         RDEPTH = null;
103         args[PARAM_OFFSET] = 0;
104         goTo(buildOPACLink(args));
105 }
106
107
108 function rresultGetDepth() {
109         if( getRdepth() != null) return getRdepth();
110         return getDepth();
111 }
112
113
114 function rresultGetForm() {
115         var form;
116
117         if(getTform())  /* did the user select a format from the icon list (temporary) */
118                 form = (getTform() == 'all') ? null : getTform();
119         else  /* did the use select a format from simple search dropdown */
120                 form = (getForm() == 'all') ? null : getForm();
121
122         if(!form) { /* did the user select a format from the advanced search */
123                 form = getItemType();
124                 var f = getItemForm();
125
126                 if(form) {
127                         form = form.replace(/,/,'');
128                         if(f) form += '-' + f;
129                 } else {
130                         if(f) form = '-' + f;
131                 }
132         }
133
134         return form;
135 }
136
137
138 function rresultCollectMARCIds() {
139
140         var args                        = {};
141         args.searches   = JSON2js(getSearches());
142         args.limit              = 200;
143         args.org_unit   = globalOrgTree.id();
144         args.depth              = 0;
145
146         var req = new Request(FETCH_ADV_MARC_MRIDS, args);
147         req.callback(rresultHandleRIds);
148         req.send();
149 }
150
151
152 function rresultCollectISBNIds() {
153         var req = new Request(FETCH_ADV_ISBN_RIDS, getAdvTerm() );
154         req.callback(
155                 function(r) {
156                         var blob = r.getResultObject();
157                         _rresultHandleIds(blob.ids, blob.count);
158                 }
159         );
160         req.send();
161 }
162
163 function rresultCollectISSNIds() {
164         var req = new Request(FETCH_ADV_ISSN_RIDS, getAdvTerm() );
165         req.callback(
166                 function(r) {
167                         var blob = r.getResultObject();
168                         _rresultHandleIds(blob.ids, blob.count);
169                 }
170         );
171         req.send();
172 }
173
174 function rresultHandleList() {
175         var ids = new CGI().param(PARAM_RLIST);
176         if(ids) _rresultHandleIds(ids, ids.length);
177 }
178
179 var rresultTries = 0;
180 function rresultHandleRIds(r) {
181         var res = r.getResultObject();
182
183         if( res.count == 0 ) {
184
185                 if( rresultTries == 0 ) {
186                         rresultTries++;
187                         var form = rresultGetForm();
188                         var args = { format : form, org : getLocation(), depth : findOrgDepth(globalOrgTree) };
189                         var req = new Request(FETCH_RIDS, getMrid(), args );
190                         req.callback( rresultHandleRIds );
191                         req.send();
192                         unHideMe($('no_formats'));
193                         hideMe($('rresult_show_all'));
194                 }
195
196         } else {
197
198                 _rresultHandleIds(res.ids, res.count);
199         }
200 }
201
202 function _rresultHandleIds(ids, count) {
203         HITCOUNT = parseInt(count);
204         runEvt('result', 'hitCountReceived');
205         runEvt('result', 'idsReceived', ids);
206 }
207
208 function rresultCollectRecords(ids) {
209         runEvt("result", "preCollectRecords");
210         var x = 0;
211         for( var i = getOffset(); i!= getDisplayCount() + getOffset(); i++ ) {
212                 if(ids[i] == null) break;
213                 var req = new Request(FETCH_RMODS, parseInt(ids[i]));
214                 req.callback(rresultHandleMods);
215                 req.request.userdata = x++;
216                 req.send();
217         }
218 }
219
220 function rresultHandleMods(r) {
221         var rec = r.getResultObject();
222         runEvt('result', 'recordReceived', rec, r.userdata, false);
223         resultCollectCopyCounts(rec, r.userdata, FETCH_R_COPY_COUNTS);
224         if(resultPageIsDone()) {
225                 runEvt('result', 'allRecordsReceived', recordsCache);
226                 unHideMe($('copyright_block')); 
227         }
228 }
229
230
231 function rresultLaunchDrawn(id, node) {
232         runEvt("rresult", "recordDrawn", id, node);
233 }
234
235
236 function rresultDoRecordSearch() { 
237         resultCollectSearchIds(true, SEARCH_RS, rresultFilterSearchResults ); }
238 function rresultDoRecordMultiSearch() { 
239         resultCollectSearchIds(false, SEARCH_RS, rresultFilterSearchResults ); }
240
241 /*
242 function _rresultCollectSearchIds( type ) {
243
244         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
245         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
246
247         var form = parseForm(getForm());
248         var item_type = form.item_type;
249         var item_form = form.item_form;
250
251         var args = {};
252
253         if( type ) {
254                 args.searches = {};
255                 args.searches[getRtype()] = {};
256                 args.searches[getRtype()].term = getTerm();
257         } else {
258                 args.searches = JSON2js(getAdvTerm());
259         }
260
261         args.org_unit = getLocation();
262         args.depth    = getDepth();
263         args.limit    = rresultLimit;
264         args.offset   = getOffset();
265
266         if(sort) args.sort = sort;
267         if(sortdir) args.sort_dir = sortdir;
268         if(item_type) args.item_type    = item_type;
269         if(item_form) args.item_form    = item_form;
270
271         var req = new Request(SEARCH_RS, args);
272         req.callback(rresultFilterSearchResults);
273         req.send();
274 }
275 */
276
277
278 function rresultFilterSearchResults(r) {
279         var result = r.getResultObject();
280         var ids = [];
281         for( var i = 0; i != result.ids.length; i++ ) 
282                 ids.push(result.ids[i][0]);
283         _rresultHandleIds( ids, result.count );
284 }
285
286