]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/cn_browse.js
showing a 'you are browsing..' thingy in the call number browser
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / cn_browse.js
1 var cnBrowseCurrent;
2 var cnBrowseTopCn;
3 var cnBrowseTopId;
4 var cnBrowseBottomCn;
5 var cnBrowseBottomId;
6 var cnBrowseDepth;
7 var cnBrowseCache = {};
8 var cnBrowseShowNext = false;
9 var cnBrowseShowPrev = false;
10 var MAX_CN = 9;
11
12 if( findCurrentPage() == CNBROWSE ) {
13         attachEvt("common", "run", cnBrowseLoadSearch);
14         attachEvt( "common", "locationUpdated", cnBrowseResubmit );
15 }
16
17 function cnBrowseLoadSearch() {
18         unHideMe($('cn_browse'));
19         cnBrowseGo(getCallnumber(), getDepth());
20 }
21
22 function cnBrowseResubmit() {
23         var args = {}
24         args[PARAM_CN] = cnBrowseCurrent;
25         args[PARAM_DEPTH] = getNewSearchDepth();
26         args[PARAM_LOCATION] = getNewSearchLocation();
27         goTo(buildOPACLink(args));
28 }
29
30 function cnBrowseGo(cn, depth) { 
31         if(depth == null) depth = getDepth();
32         cnBrowseDepth = depth;
33         cnBrowseCurrent = cn;
34         var req = new Request( FETCH_CNBROWSE_TARGET, 
35                 'org_unit', getLocation(), 
36                 'depth', cnBrowseDepth, 
37                 'label', cnBrowseCurrent,
38                 'page_size', MAX_CN );
39         req.callback( cnBrowseDraw );
40         req.send();
41
42         var o = findOrgUnit(getLocation());
43         var d = findOrgDepth(o);
44         var x = 0;
45         while( d > depth ) {
46                 o = findOrgUnit(o.parent_ou());
47                 d = findOrgDepth(o);
48         }
49         appendClear($('cn_browse_where'), text(o.name()));
50 }
51
52 function cnBrowseNext() {
53         cnBrowseShowNext = true;
54         if( cnBrowseCache.next )  /* if we have it, show it */
55                 cnBrowseClearNext(cnBrowseCache.next);
56 }
57
58 function cnBrowsePrev() {
59         cnBrowseShowPrev = true;
60         if( cnBrowseCache.prev ) 
61                 cnBrowseClearPrev(cnBrowseCache.prev);
62 }
63
64 function cnBrowseGrabNext() {
65         var req = new Request( FETCH_CNBROWSE_NEXT, 
66                 'org_unit', getLocation(), 
67                 'depth', cnBrowseDepth,
68                 'label', cnBrowseBottomCn, 
69                 'boundry_id', cnBrowseBottomId,
70                 'page_size', MAX_CN );
71         req.callback( cnBrowseCacheMe );
72         req.request.next = true;
73         req.send();
74 }
75
76
77 function cnBrowseGrabPrev() {
78         var req = new Request( FETCH_CNBROWSE_PREV,
79                 'org_unit', getLocation(), 
80                 'depth', cnBrowseDepth,
81                 'label', cnBrowseTopCn, 
82                 'boundry_id', cnBrowseTopId,
83                 'page_size', MAX_CN );
84         req.callback( cnBrowseCacheMe );
85         req.request.prev = true;
86         req.send();
87 }
88
89 function cnBrowseClearNext(list) {
90         cnBrowseCache.next = null; 
91         cnBrowseShowNext = false;
92         _cnBrowseDraw(list);
93 }
94
95 function cnBrowseClearPrev(list) {
96         cnBrowseCache.prev = null; 
97         cnBrowseShowPrev = false;
98         _cnBrowseDraw(list);
99 }
100
101 /* cache next and previous calls unless they are 
102 needed immediately */
103 function cnBrowseCacheMe(r) {
104         var list = r.getResultObject();
105         if( r.next ) {
106                 cnBrowseCache.next = list;
107                 if( cnBrowseShowNext ) {
108                         cnBrowseClearNext(list);
109                 } 
110
111         } else if( r.prev ) {
112                 cnBrowseCache.prev = list;
113                 if( cnBrowseShowPrev )  {
114                         cnBrowseClearPrev(list);
115                 } 
116         }
117 }
118
119
120 function cnBrowseDraw( r ) {
121         var list = r.getResultObject();
122         _cnBrowseDraw(list);
123 }
124
125
126 var cnTbody;
127 var cnRowT;
128 var cnTdT;
129 function _cnBrowseDraw( list ) {
130
131         if(!cnTbody) {
132                 cnTbody = $('cn_tbody');
133                 cnRowT = $('cn_browse_row');
134                 cnTdT = cnRowT.removeChild($('cn_browse_td'));
135                 cnTbody.removeChild(cnRowT);
136         }
137         removeChildren(cnTbody);
138
139         var counter = 1;
140         var currentRow = cnRowT.cloneNode(true);
141         cnTbody.appendChild(currentRow);
142
143         for( var idx in list ) {
144                 
145
146                 var currentTd = cnTdT.cloneNode(true);
147                 currentRow.appendChild(currentTd);
148
149                 var td = cnTdT.cloneNode(true);
150                 var label       = list[idx][0];
151                 var lib         = list[idx][1];
152                 var record      = list[idx][2];
153                 var id          = list[idx][3];
154
155                 if( idx == 0 ) { cnBrowseTopCn = label; cnBrowseTopId = id; } 
156                 cnBrowseBottomCn = label;
157                 cnBrowseBottomId = id;
158
159                 var cn_td                       = $n(currentTd, 'cn_browse_cn');
160                 var lib_td                      = $n(currentTd, 'cn_browse_lib');
161                 var title_td            = $n(currentTd, 'cn_browse_title');
162                 var author_td           = $n(currentTd, 'cn_browse_author');
163                 var pic_td                      = $n(currentTd, 'cn_browse_pic');
164
165                 cn_td.appendChild(text(label));
166                 lib_td.appendChild(text(findOrgUnit(lib).name()));
167
168                 var req = new Request( FETCH_RMODS, record );
169                 req.request.title_td            = title_td;
170                 req.request.author_td   = author_td;
171                 req.request.pic_td              = pic_td;
172                 req.callback( cnBrowseDrawTitle );
173                 req.send();
174
175         
176                 if( counter++ % 3 == 0 ) {
177                         counter = 1;
178                         currentRow = cnRowT.cloneNode(true);
179                         cnTbody.appendChild(currentRow);
180                 }
181         }
182         cnBrowseGrabNext();
183         cnBrowseGrabPrev();
184 }
185
186 function cnBrowseDrawTitle(r) {
187         var mods = r.getResultObject();
188
189         buildTitleDetailLink(mods, r.title_td); 
190         buildSearchLink(STYPE_AUTHOR, mods.author(), r.author_td);
191         r.pic_td.setAttribute("src", buildISBNSrc(cleanISBN(mods.isbn())));
192
193         var args = {};
194         args.page = RDETAIL;
195         args[PARAM_OFFSET] = 0;
196         args[PARAM_RID] = mods.doc_id();
197         args[PARAM_MRID] = 0;
198         r.pic_td.parentNode.setAttribute("href", buildOPACLink(args));
199 }
200