]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
added notes to fm core for rdetail notes
[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 var nextContainerIndex;
20
21 function rdetailDraw() {
22
23
24         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
25         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
26         statusRow = G.ui.rdetail.cp_status.parentNode;
27         statusRow.id = '__rdsrow';
28
29         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
30         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
31
32         if(getLocation() == globalOrgTree.id())
33                 hideMe(G.ui.rdetail.cp_info_all);
34
35         var req = new Request(FETCH_RMODS, getRid());
36         req.callback(_rdetailDraw);
37         req.send();
38 }
39
40 function buildunAPISpan (span, type, id) {
41         var cgi = new CGI();
42         var d = new Date();
43
44         addCSSClass(span,'unapi-uri');
45
46         span.appendChild(text('unAPI'));
47         span.setAttribute(
48                 'title',
49                 'tag:' + cgi.server_name + ',' +
50                         d.getFullYear() +
51                         ':' + type + '/' + id
52         );
53 }
54
55 var rdeatilMarcFetched = false;
56 function rdetailViewMarc(r,id) {
57         hideMe($('rdetail_extras_loading'));
58         $('rdetail_view_marc_box').innerHTML = r.getResultObject();
59
60         var d = new Date();
61
62         var div = elem('div', { class : 'hide_me' });
63         var span = div.appendChild( elem('span') );
64
65         buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
66
67         /* add the unapi span inside a hidden div */
68         $('rdetail_view_marc_box').insertBefore(div, $('rdetail_view_marc_box').firstChild);
69 }
70
71
72 function rdetailShowLocalCopies() {
73
74         var found = false;
75         var rows = copyRowParent.getElementsByTagName("tr");
76         for( var r in rows ) {
77                 if(rows[r].id == "__rdsrow") continue;
78                 hideMe(rows[r]);
79                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
80                         unHideMe(rows[r]);
81                         found = true;
82                 }
83         }
84
85         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
86         hideMe(G.ui.rdetail.cp_info_local);
87         unHideMe(G.ui.rdetail.cp_info_all);
88         rdetailLocalOnly = true;
89 }
90
91 function rdetailShowAllCopies() {
92         var rows = copyRowParent.getElementsByTagName("tr");
93         for( var r in rows ) 
94                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
95                         unHideMe(rows[r]);
96
97         hideMe(G.ui.rdetail.cp_info_all);
98         unHideMe(G.ui.rdetail.cp_info_local);
99         hideMe(G.ui.rdetail.cp_info_none);
100         rdetailLocalOnly = false;
101 }
102
103
104 function _rdetailDraw(r) {
105         record = r.getResultObject();
106
107         runEvt('rdetail', 'recordRetrieved', record.doc_id());
108
109         G.ui.rdetail.title.appendChild(text(record.title()));
110         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
111         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
112         G.ui.rdetail.edition.appendChild(text(record.edition()));
113         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
114         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
115         G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
116         setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
117         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
118
119
120         $('rdetail_place_hold').setAttribute(
121                 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
122
123         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
124         runEvt("rdetail", "recordDrawn");
125         recordsCache.push(record);
126
127         rdetailSetExtrasSelector();
128
129         var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
130         req.callback(rdetailHandleAddedContent);
131         req.send();
132
133         resultBuildCaches( [ record ] );
134         resultDrawSubjects();
135         resultDrawSeries();
136 }
137
138 function rdetailSetExtrasSelector() {
139         if(!grabUser()) return;
140         unHideMe($('rdetail_more_actions'));
141
142         var req = new Request( 
143                 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
144         req.callback(rdetailAddBookbags);
145         req.send();
146 }
147
148 function rdetailAddBookbags(r) {
149
150         var containers = r.getResultObject();
151         var selector = $('rdetail_more_actions_selector');
152         var found = false;
153         var index = 3;
154         doSelectorActions(selector);
155
156         for( var i = 0; i != containers.length; i++ ) {
157                 found = true;
158                 var container = containers[i];
159                 insertSelectorVal( selector, index++, container.name(), 
160                         "container_" + container.id(), rdetailAddToBookbag,  1 );
161         }
162
163         nextContainerIndex = index;
164         if(!found) insertSelectorVal( selector, 3, "name", "value", 1 );
165 }
166
167 var _actions = {};
168 function rdetailNewBookbag() {
169         var name = prompt($('rdetail_bb_new').innerHTML,"");
170         if(!name) return;
171
172         var id;
173         if( id = containerCreate( name ) ) {
174                 alert($('rdetail_bb_success').innerHTML);
175                 var selector = $('rdetail_more_actions_selector');
176                 insertSelectorVal( selector, nextContainerIndex++, name, 
177                         "container_" + id, rdetailAddToBookbag, 1 );
178                 setSelector( selector, 'start' );
179         }
180 }
181
182
183 function rdetailAddToBookbag() {
184         var selector = $('rdetail_more_actions_selector');
185         var id = selector.options[selector.selectedIndex].value;
186         setSelector( selector, 'start' );
187
188         if( containerCreateItem( id.substring(10), record.doc_id() )) {
189                 alert($('rdetail_bb_item_success').innerHTML);
190         }
191 }
192
193
194
195 var rdetailTocFetched           = false;
196 var rdetailReviewFetched        = false;
197 var rdetailMarcFetched          = false;
198
199 function rdetailShowExtra(type) {
200
201         hideMe($('rdetail_copy_info_div'));
202         hideMe($('rdetail_reviews_div'));
203         hideMe($('rdetail_toc_div'));
204         hideMe($('rdetail_marc_div'));
205         hideMe($('cn_browse'));
206         hideMe($('rdetail_cn_browse_div'));
207
208         var req;
209         switch(type) {
210                 case "copyinfo": 
211                         unHideMe($('rdetail_copy_info_div')); 
212                         break;
213
214                 case "reviews": 
215                         unHideMe($('rdetail_reviews_div')); 
216                         if(rdetailReviewFetched) break;
217                         unHideMe($('rdetail_extras_loading'));
218                         rdetailReviewFetched = true;
219                         req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
220                         req.callback(rdetailShowReviews);
221                         req.send();
222                         break;
223
224                 case "toc": 
225                         unHideMe($('rdetail_toc_div'));
226                         if(rdetailTocFetched) break;
227                         unHideMe($('rdetail_extras_loading'));
228                         rdetailTocFetched = true;
229                         var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
230                         req.callback(rdetailShowTOC);
231                         req.send();
232                         break;
233
234                 case "marc": 
235                         unHideMe($('rdetail_marc_div')); 
236                         if(rdetailMarcFetched) return;
237                         unHideMe($('rdetail_extras_loading'));
238                         rdetailMarcFetched = true;
239                         var req = new Request( FETCH_MARC_HTML, record.doc_id() );
240                         req.callback(rdetailViewMarc); 
241                         req.send();
242                         break;
243
244                 case 'cn':
245                         unHideMe($('rdetail_cn_browse_div'));
246                         rdetailShowCNBrowse(defaultCN, null, true);
247                         break;
248         }
249 }
250
251 function rdetailBuildCNList() {
252         var select = $('cn_browse_selector');
253         var index = 0;
254         var arr = [];
255         for( var cn in callnumberCache ) arr.push( cn );
256         arr.sort();
257
258         for( var i in arr ) {
259                 var cn = arr[i];
260                 var opt = new Option(cn);
261                 select.options[index++] = opt;
262         }
263         select.onchange = rdetailGatherCN;
264 }
265
266 function rdetailGatherCN() {
267         var cn = getSelectorVal($('cn_browse_selector'));
268         rdetailShowCNBrowse( cn, getDepth(), true );
269         setSelector( $('cn_browse_selector'), cn );
270 }
271
272
273 function rdetailShowCNBrowse( cn, depth, fromOnclick ) {
274         if(!cn) return;
275         rdetailBuildCNList();
276         setSelector( $('cn_browse_selector'), cn );
277         hideMe($('rdetail_copy_info_div'));
278         hideMe($('rdetail_reviews_div'));
279         hideMe($('rdetail_toc_div'));
280         hideMe($('rdetail_marc_div'));
281         unHideMe($('rdetail_cn_browse_div'));
282         unHideMe($('cn_browse'));
283         if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
284         cnBrowseGo(cn, depth);
285 }
286
287 function rdetailHandleAddedContent(r) {
288         var resp = r.getResultObject();
289         if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
290         if( resp.TOC == 'true' ) unHideMe($('rdetail_toc_link'));
291 }
292
293
294 function rdetailShowReviews(r) {
295         hideMe($('rdetail_extras_loading'));
296         var res = r.getResultObject();
297         var par = $('rdetail_reviews_div');
298         var template = par.removeChild($('rdetail_review_template'));
299         if( res && res.length > 0 ) {
300                 unHideMe($('rdetail_reviews_link'));
301                 for( var i = 0; i != res.length; i++ ) {
302                         var rev = res[i];       
303                         if( rev.text && rev.info ) {
304                                 var node = template.cloneNode(true);
305                                 $n(node, 'review_header').appendChild(text(rev.info));
306                                 $n(node, 'review_text').appendChild(text(rev.text));
307                                 par.appendChild(node);
308                         }
309                 }
310         }
311 }
312
313 function rdetailShowTOC(r) {
314         hideMe($('rdetail_extras_loading'));
315         var resp = r.getResultObject();
316         if(resp) {
317                 unHideMe($('rdetail_toc_link'));
318                 $('rdetail_toc_div').innerHTML = resp;
319         }
320 }
321
322
323 function rdetailBuildInfoRows() {
324         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
325         req.callback(_rdetailBuildInfoRows);
326         req.send();
327 }
328
329 /* pre-allocate the copy info table with all org units in correct order */
330 function _rdetailRows(node) {
331
332         if(node) {
333
334                 var row = copyRow.cloneNode(true);
335                 row.id = "cp_info_" + node.id();
336
337                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
338                 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
339                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
340         
341                 libtd.appendChild(text(node.name()));
342                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
343         
344                 if(!findOrgType(node.ou_type()).can_have_vols()) {
345
346                         row.removeChild(cntd);
347                         row.removeChild(cpctd);
348
349                         libtd.setAttribute("colspan", numStatuses + 2 );
350                         libtd.colSpan = numStatuses + 2;
351                         addCSSClass(row, 'copy_info_region_row');
352                 } 
353         
354                 copyRowParent.appendChild(row);
355
356         } else { node = globalOrgTree; }
357
358         for( var c in node.children() ) 
359                 _rdetailRows(node.children()[c]);
360 }
361
362 /* walk through the copy info and build rows where necessary */
363 var localCNFound = false;
364 function _rdetailBuildInfoRows(r) {
365
366         _rdetailRows();
367
368         var summary = r.getResultObject();
369         if(!summary) return;
370
371         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
372                 G.ui.rdetail.cp_info_loading);
373
374         var found = false;
375         for( var i = 0; i < summary.length; i++ ) {
376
377                 var arr = summary[i];
378                 var thisOrg = findOrgUnit(arr[0]);
379                 var rowNode = $("cp_info_" + thisOrg.id());
380
381                 if(rowNode.getAttribute("used")) {
382
383                         if( rowNode.nextSibling )
384                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
385                         else
386                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
387                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
388                         n.appendChild(text(thisOrg.name()));
389                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
390
391                 } else rowNode.setAttribute("used", "1");
392
393                 var cpc_temp = rowNode.removeChild(
394                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
395
396                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
397
398                 var isLocal = false;
399                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { 
400                         found = true; 
401                         isLocal = true; 
402                         if(!localCNFound) {
403                                 localCNFound = true;
404                                 defaultCN = arr[1];
405                         }
406                 }
407                 rdetailSetPath( thisOrg, isLocal );
408                 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal );
409
410                 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
411         }
412
413         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
414
415 }
416
417 function rdetailBuildBrowseInfo(row, cn, local) {
418         /* used for building the shelf browser */
419         if(local) {
420                 var cache = callnumberCache[cn];
421                 if( cache ) cache.count++;
422                 else callnumberCache[cn] = { count : 1 };
423         }
424
425         var depth = getDepth();
426         if( !local ) depth = findOrgDepth(globalOrgTree);
427         var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + cn + '", "'+depth+'");' }, cn);
428         addCSSClass(a, 'classic_link');
429         findNodeByName( row, config.names.rdetail.cn_cell ).appendChild(a);
430 }
431
432 /* sets the path to org as 'active' and displays the 
433         path if it's local */
434 function rdetailSetPath(org, local) {
435         if( findOrgDepth(org) == 0 ) return;
436         var row = $("cp_info_" + org.id());
437         row.setAttribute("hasinfo", "1");
438         if(local) {
439                 unHideMe(row);
440                 row.setAttribute("local", "1");
441         }
442         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
443 }
444
445 function rdetailApplyStatuses( row, template, statuses ) {
446         for( var j in _statusPositions ) {
447                 var stat = _statusPositions[j];
448                 var val = statuses[stat.id()];
449                 var nn = template.cloneNode(true);
450                 if(val) nn.appendChild(text(val));
451                 else nn.appendChild(text(0));
452                 row.appendChild(nn);    
453         }
454 }
455
456
457 /* --------------------------------------------------------------------- */
458 var _statusPositions = {};
459
460 function rdetailBuildStatusColumns() {
461
462         rdetailGrabCopyStatuses();
463         var parent = statusRow;
464         var template = parent.removeChild(G.ui.rdetail.cp_status);
465
466         var i = 0;
467         for( i = 0; i < cp_statuses.length; i++ ) {
468
469                 var c = cp_statuses[i];
470
471                 if(c && c.holdable()) {
472
473                         var name = c.name();
474                         _statusPositions[i] = c;
475                         var node = template.cloneNode(true);
476                         var data = findNodeByName( node, config.names.rdetail.cp_status);
477
478                         data.appendChild(text(name));
479                         parent.appendChild(node);
480                 }       
481         }       
482
483         numStatuses = 0;
484         for(x in _statusPositions) numStatuses++; 
485 }
486
487 function rdetailGrabCopyStatuses() {
488         if(cp_statuses) return cp_statuses;
489    var req = new Request(FETCH_COPY_STATUSES);
490    req.send(true);
491         cp_statuses = req.result();
492         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
493 }
494
495 function _rdetailSortStatuses(a, b) {
496         return parseInt(a.id()) - parseInt(b.id());
497 }
498
499