fixed bug in result type switch block
[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         table = G.ui.result.main_table;
17         hideMe(G.ui.result.row_template);
18         while( table.parentNode.rows.length <= (getDisplayCount() +1) ) 
19                 hideMe(table.appendChild(G.ui.result.row_template.cloneNode(true)));
20         rresultCollectIds();
21 }
22
23 function rresultCollectIds() {
24         var ids;
25         switch(getRtype()) {
26
27                 case RTYPE_COOKIE:
28                         ids = JSON2js(cookieManager.read(COOKIE_RIDS));
29                         _rresultHandleIds( ids, ids.length );
30                         break;
31
32                 case RTYPE_TITLE:
33                 case RTYPE_AUTHOR:
34                 case RTYPE_SUBJECT:
35                 case RTYPE_SERIES:
36                 case RTYPE_KEYWORD:
37                         rresultDoRecordSearch();
38                         break;
39
40                 case RTYPE_LIST :
41                         rresultHandleList();
42                         break;
43
44                 case RTYPE_MRID :
45                 case null :
46                 case "" :
47                 defaut:
48                         var form = (getForm() == "all") ? null : getForm();
49                         var req = new Request(FETCH_RIDS, getMrid(), form );
50                         req.callback( rresultHandleRIds );
51                         req.send();
52         }
53 }
54
55 function rresultHandleList() {
56         var ids = new CGI().param(PARAM_RLIST);
57         if(ids) _rresultHandleIds(ids, ids.length);
58 }
59
60 function rresultHandleRIds(r) {
61         var res = r.getResultObject();
62         _rresultHandleIds(res.ids, res.count);
63 }
64
65 function _rresultHandleIds(ids, count) {
66         HITCOUNT = parseInt(count);
67         runEvt('result', 'hitCountReceived');
68         runEvt('result', 'idsReceived', ids);
69 }
70
71 function rresultCollectRecords(ids) {
72         runEvt("result", "preCollectRecords");
73         var x = 0;
74         for( var i = getOffset(); i!= getDisplayCount() + getOffset(); i++ ) {
75                 if(ids[i] == null) break;
76                 var req = new Request(FETCH_RMODS, parseInt(ids[i]));
77                 req.callback(rresultHandleMods);
78                 req.request.userdata = x++;
79                 req.send();
80         }
81 }
82
83 function rresultHandleMods(r) {
84         var rec = r.getResultObject();
85         runEvt('result', 'recordReceived', rec, r.userdata, false);
86         resultCollectCopyCounts(rec, r.userdata, FETCH_R_COPY_COUNTS);
87         if(resultPageIsDone()) {
88                 runEvt('result', 'allRecordsReceived', recordsCache);
89                 unHideMe($('copyright_block')); 
90         }
91 }
92
93
94 function rresultLaunchDrawn(id, node) {
95         runEvt("rresult", "recordDrawn", id, node);
96 }
97
98
99 function rresultDoRecordSearch() {
100
101         var form                = (!getForm() || getForm() == "all") ? null : getForm();
102         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
103         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
104
105         var req = new Request(FETCH_SEARCH_RIDS, getRtype(), 
106                 {       term            : getTerm(), 
107                         sort            : sort,
108                         sort_dir        : sortdir,
109                         org_unit : getLocation(),
110                         depth           : getDepth(),
111                         limit           : rresultLimit,
112                         offset  : getOffset(),
113                         format  : form } );
114
115         req.callback(rresultFilterSearchResults);
116         req.send();
117 }
118
119 function rresultFilterSearchResults(r) {
120         var result = r.getResultObject();
121         var ids = [];
122         for( var i = 0; i != result.ids.length; i++ ) 
123                 ids.push(result.ids[i][0]);
124         _rresultHandleIds( ids, result.count );
125 }
126
127