]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
showing all volumes in the detail page now makes the cn browser show items for
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1 /* */
2
3 attachEvt("common", "run", rdetailDraw);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
5 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
6
7 var record = null;
8 var cp_statuses = null;
9 var recordsCache = [];
10
11 var copyRowParent = null;
12 var copyRow = null;
13 var statusRow = null;
14 var numStatuses = null;
15 var defaultCN;
16 var callnumberCache = {};
17 var rdetailLocalOnly = true;
18
19 function rdetailDraw() {
20
21
22         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
23         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
24         statusRow = G.ui.rdetail.cp_status.parentNode;
25         statusRow.id = '__rdsrow';
26
27         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
28         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
29
30         if(getLocation() == globalOrgTree.id())
31                 hideMe(G.ui.rdetail.cp_info_all);
32
33         var req = new Request(FETCH_RMODS, getRid());
34         req.callback(_rdetailDraw);
35         req.send();
36 }
37
38 var rdeatilMarcFetched = false;
39 function rdetailViewMarc(r) {
40         hideMe($('rdetail_extras_loading'));
41         $('rdetail_view_marc_box').innerHTML = r.getResultObject();
42 }
43
44
45 function rdetailShowLocalCopies() {
46
47         var found = false;
48         var rows = copyRowParent.getElementsByTagName("tr");
49         for( var r in rows ) {
50                 if(rows[r].id == "__rdsrow") continue;
51                 hideMe(rows[r]);
52                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
53                         unHideMe(rows[r]);
54                         found = true;
55                 }
56         }
57
58         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
59         hideMe(G.ui.rdetail.cp_info_local);
60         unHideMe(G.ui.rdetail.cp_info_all);
61         rdetailLocalOnly = true;
62 }
63
64 function rdetailShowAllCopies() {
65         var rows = copyRowParent.getElementsByTagName("tr");
66         for( var r in rows ) 
67                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
68                         unHideMe(rows[r]);
69
70         hideMe(G.ui.rdetail.cp_info_all);
71         unHideMe(G.ui.rdetail.cp_info_local);
72         hideMe(G.ui.rdetail.cp_info_none);
73         rdetailLocalOnly = false;
74 }
75
76
77 function _rdetailDraw(r) {
78         record = r.getResultObject();
79
80         runEvt('rdetail', 'recordRetrieved', record.doc_id());
81
82         G.ui.rdetail.title.appendChild(text(record.title()));
83         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
84         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
85         G.ui.rdetail.edition.appendChild(text(record.edition()));
86         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
87         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
88         G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
89         setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
90         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
91
92
93         $('rdetail_place_hold').setAttribute(
94                 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
95
96         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
97         runEvt("rdetail", "recordDrawn");
98         recordsCache.push(record);
99
100         var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
101         req.callback(rdetailHandleAddedContent);
102         req.send();
103
104         resultBuildCaches( [ record ] );
105         resultDrawSubjects();
106         //resultDrawAuthors();
107         resultDrawSeries();
108
109 }
110
111 var rdetailTocFetched           = false;
112 var rdetailReviewFetched        = false;
113 var rdetailMarcFetched          = false;
114
115 function rdetailShowExtra(type) {
116
117         hideMe($('rdetail_copy_info_div'));
118         hideMe($('rdetail_reviews_div'));
119         hideMe($('rdetail_toc_div'));
120         hideMe($('rdetail_marc_div'));
121         hideMe($('cn_browse'));
122         hideMe($('rdetail_cn_browse_div'));
123
124         var req;
125         switch(type) {
126                 case "copyinfo": 
127                         unHideMe($('rdetail_copy_info_div')); 
128                         break;
129
130                 case "reviews": 
131                         unHideMe($('rdetail_reviews_div')); 
132                         if(rdetailReviewFetched) break;
133                         unHideMe($('rdetail_extras_loading'));
134                         rdetailReviewFetched = true;
135                         req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
136                         req.callback(rdetailShowReviews);
137                         req.send();
138                         break;
139
140                 case "toc": 
141                         unHideMe($('rdetail_toc_div'));
142                         if(rdetailTocFetched) break;
143                         unHideMe($('rdetail_extras_loading'));
144                         rdetailTocFetched = true;
145                         var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
146                         req.callback(rdetailShowTOC);
147                         req.send();
148                         break;
149
150                 case "marc": 
151                         unHideMe($('rdetail_marc_div')); 
152                         if(rdetailMarcFetched) return;
153                         unHideMe($('rdetail_extras_loading'));
154                         rdetailMarcFetched = true;
155                         var req = new Request( FETCH_MARC_HTML, record.doc_id() );
156                         req.callback(rdetailViewMarc); 
157                         req.send();
158                         break;
159
160                 case 'cn':
161                         unHideMe($('rdetail_cn_browse_div'));
162                         rdetailShowCNBrowse(defaultCN, null, true);
163                         break;
164         }
165 }
166
167 function rdetailBuildCNList() {
168         var select = $('cn_browse_selector');
169         var index = 0;
170         for( var cn in callnumberCache ) {
171                 var opt = new Option(cn);
172                 opt.onclick = rdetailGatherCN;
173                 select.options[index++] = opt;
174         }
175 }
176
177 function rdetailGatherCN() {
178         var cn = getSelectorVal($('cn_browse_selector'));
179         rdetailShowCNBrowse( cn, getDepth(), true );
180         setSelector( $('cn_browse_selector'), cn );
181 }
182
183
184 function rdetailShowCNBrowse( cn, depth, fromOnclick ) {
185         if(!cn) return;
186         rdetailBuildCNList();
187         setSelector( $('cn_browse_selector'), cn );
188         hideMe($('rdetail_copy_info_div'));
189         hideMe($('rdetail_reviews_div'));
190         hideMe($('rdetail_toc_div'));
191         hideMe($('rdetail_marc_div'));
192         unHideMe($('rdetail_cn_browse_div'));
193         unHideMe($('cn_browse'));
194         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
195         cnBrowseGo(cn, depth);
196 }
197
198 function rdetailHandleAddedContent(r) {
199         var resp = r.getResultObject();
200         if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
201         if( resp.TOC == 'true' ) unHideMe($('rdetail_toc_link'));
202 }
203
204
205 function rdetailShowReviews(r) {
206         hideMe($('rdetail_extras_loading'));
207         var res = r.getResultObject();
208         var par = $('rdetail_reviews_div');
209         var template = par.removeChild($('rdetail_review_template'));
210         if( res && res.length > 0 ) {
211                 unHideMe($('rdetail_reviews_link'));
212                 for( var i = 0; i != res.length; i++ ) {
213                         var rev = res[i];       
214                         if( rev.text && rev.info ) {
215                                 var node = template.cloneNode(true);
216                                 $n(node, 'review_header').appendChild(text(rev.info));
217                                 $n(node, 'review_text').appendChild(text(rev.text));
218                                 par.appendChild(node);
219                         }
220                 }
221         }
222 }
223
224 function rdetailShowTOC(r) {
225         hideMe($('rdetail_extras_loading'));
226         var resp = r.getResultObject();
227         if(resp) {
228                 unHideMe($('rdetail_toc_link'));
229                 $('rdetail_toc_div').innerHTML = resp;
230         }
231 }
232
233
234 function rdetailBuildInfoRows() {
235         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
236         req.callback(_rdetailBuildInfoRows);
237         req.send();
238 }
239
240 /* pre-allocate the copy info table with all org units in correct order */
241 function _rdetailRows(node) {
242
243         if(node) {
244
245                 var row = copyRow.cloneNode(true);
246                 row.id = "cp_info_" + node.id();
247
248                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
249                 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
250                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
251         
252                 libtd.appendChild(text(node.name()));
253                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
254         
255                 if(!findOrgType(node.ou_type()).can_have_vols()) {
256
257                         row.removeChild(cntd);
258                         row.removeChild(cpctd);
259
260                         libtd.setAttribute("colspan", numStatuses + 2 );
261                         libtd.colSpan = numStatuses + 2;
262                         addCSSClass(row, 'copy_info_region_row');
263                 } 
264         
265                 copyRowParent.appendChild(row);
266
267         } else { node = globalOrgTree; }
268
269         for( var c in node.children() ) 
270                 _rdetailRows(node.children()[c]);
271 }
272
273 /* walk through the copy info and build rows where necessary */
274 var localCNFound = false;
275 function _rdetailBuildInfoRows(r) {
276
277         _rdetailRows();
278
279         var summary = r.getResultObject();
280         if(!summary) return;
281
282         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
283                 G.ui.rdetail.cp_info_loading);
284
285         var found = false;
286         for( var i = 0; i < summary.length; i++ ) {
287
288                 var arr = summary[i];
289                 var thisOrg = findOrgUnit(arr[0]);
290                 var rowNode = $("cp_info_" + thisOrg.id());
291
292                 if(rowNode.getAttribute("used")) {
293
294                         if( rowNode.nextSibling )
295                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
296                         else
297                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
298                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
299                         n.appendChild(text(thisOrg.name()));
300                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
301
302                 } else rowNode.setAttribute("used", "1");
303
304                 var cpc_temp = rowNode.removeChild(
305                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
306
307                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
308
309                 var isLocal = false;
310                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
311                         found = true; 
312                         isLocal = true; 
313                         if(!localCNFound) {
314                                 localCNFound = true;
315                                 defaultCN = arr[1];
316                         }
317                 }
318                 rdetailSetPath( thisOrg, isLocal );
319                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal );
320
321                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
322         }
323
324         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
325
326 }
327
328 function rdetailBuildBrowseInfo(row, cn, local) {
329         /* used for building the shelf browser */
330         if(local) {
331                 var cache = callnumberCache[cn];
332                 if( cache ) cache.count++;
333                 else callnumberCache[cn] = { count : 1 };
334         }
335
336         var depth = getDepth();
337         if( !local ) depth = findOrgDepth(globalOrgTree);
338         var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + cn + '", "'+depth+'");' }, cn);
339         addCSSClass(a, 'classic_link');
340         findNodeByName( row, config.names.rdetail.cn_cell ).appendChild(a);
341 }
342
343 /* sets the path to org as 'active' and displays the 
344         path if it's local */
345 function rdetailSetPath(org, local) {
346         if( findOrgDepth(org) == 0 ) return;
347         var row = $("cp_info_" + org.id());
348         row.setAttribute("hasinfo", "1");
349         if(local) {
350                 unHideMe(row);
351                 row.setAttribute("local", "1");
352         }
353         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
354 }
355
356 function rdetailApplyStatuses( row, template, statuses ) {
357         for( var j in _statusPositions ) {
358                 var stat = _statusPositions[j];
359                 var val = statuses[stat.id()];
360                 var nn = template.cloneNode(true);
361                 if(val) nn.appendChild(text(val));
362                 else nn.appendChild(text(0));
363                 row.appendChild(nn);    
364         }
365 }
366
367
368 /* --------------------------------------------------------------------- */
369 var _statusPositions = {};
370
371 function rdetailBuildStatusColumns() {
372
373         rdetailGrabCopyStatuses();
374         var parent = statusRow;
375         var template = parent.removeChild(G.ui.rdetail.cp_status);
376
377         var i = 0;
378         for( i = 0; i < cp_statuses.length; i++ ) {
379
380                 var c = cp_statuses[i];
381
382                 if(c && c.holdable()) {
383
384                         var name = c.name();
385                         _statusPositions[i] = c;
386                         var node = template.cloneNode(true);
387                         var data = findNodeByName( node, config.names.rdetail.cp_status);
388
389                         data.appendChild(text(name));
390                         parent.appendChild(node);
391                 }       
392         }       
393
394         numStatuses = 0;
395         for(x in _statusPositions) numStatuses++; 
396 }
397
398 function rdetailGrabCopyStatuses() {
399         if(cp_statuses) return cp_statuses;
400    var req = new Request(FETCH_COPY_STATUSES);
401    req.send(true);
402         cp_statuses = req.result();
403         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
404 }
405
406 function _rdetailSortStatuses(a, b) {
407         return parseInt(a.id()) - parseInt(b.id());
408 }
409
410