e609c37fbdf71c6371ceaf4c7ec3d964a4026282
[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                 defaut:
46                         var form = (getForm() == "all") ? null : getForm();
47                         var req = new Request(FETCH_RIDS, getMrid(), form );
48                         req.callback( rresultHandleRIds );
49                         req.send();
50         }
51 }
52
53 function rresultHandleList() {
54         var ids = new CGI().param(PARAM_RLIST);
55         if(ids) _rresultHandleIds(ids, ids.length);
56 }
57
58 function rresultHandleRIds(r) {
59         var res = r.getResultObject();
60         _rresultHandleIds(res.ids, res.count);
61 }
62
63 function _rresultHandleIds(ids, count) {
64         HITCOUNT = parseInt(count);
65         runEvt('result', 'hitCountReceived');
66         runEvt('result', 'idsReceived', ids);
67 }
68
69 function rresultCollectRecords(ids) {
70         runEvt("result", "preCollectRecords");
71         var x = 0;
72         for( var i = getOffset(); i!= getDisplayCount() + getOffset(); i++ ) {
73                 if(ids[i] == null) break;
74                 var req = new Request(FETCH_RMODS, parseInt(ids[i]));
75                 req.callback(rresultHandleMods);
76                 req.request.userdata = x++;
77                 req.send();
78         }
79 }
80
81 function rresultHandleMods(r) {
82         var rec = r.getResultObject();
83         runEvt('result', 'recordReceived', rec, r.userdata, false);
84         resultCollectCopyCounts(rec, r.userdata, FETCH_R_COPY_COUNTS);
85         if(resultPageIsDone()) {
86                 runEvt('result', 'allRecordsReceived', recordsCache);
87                 unHideMe($('copyright_block')); 
88         }
89 }
90
91
92 function rresultLaunchDrawn(id, node) {
93         runEvt("rresult", "recordDrawn", id, node);
94 }
95
96
97 function rresultDoRecordSearch() {
98
99         var form                = (!getForm() || getForm() == "all") ? null : getForm();
100         var sort                = (getSort() == SORT_TYPE_REL) ? null : getSort(); 
101         var sortdir = (sort) ? ((getSortDir()) ? getSortDir() : SORT_DIR_ASC) : null;
102
103         var req = new Request(FETCH_SEARCH_RIDS, getRtype(), 
104                 {       term            : getTerm(), 
105                         sort            : sort,
106                         sort_dir        : sortdir,
107                         org_unit : getLocation(),
108                         depth           : getDepth(),
109                         limit           : rresultLimit,
110                         offset  : getOffset(),
111                         format  : form } );
112
113         req.callback(rresultFilterSearchResults);
114         req.send();
115 }
116
117 function rresultFilterSearchResults(r) {
118         var result = r.getResultObject();
119         var ids = [];
120         for( var i = 0; i != result.ids.length; i++ ) 
121                 ids.push(result.ids[i][0]);
122         _rresultHandleIds( ids, result.count );
123 }
124
125