]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
preliminary TOC working
[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
16 function rdetailDraw() {
17
18         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
19         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
20         statusRow = G.ui.rdetail.cp_status.parentNode;
21         statusRow.id = '__rdsrow';
22
23         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
24         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
25         G.ui.rdetail.view_marc.onclick = rdetailViewMarc;
26         G.ui.rdetail.hide_marc.onclick = showCanvas;
27
28
29         if(getLocation() == globalOrgTree.id())
30                 hideMe(G.ui.rdetail.cp_info_all);
31
32
33
34         var req = new Request(FETCH_RMODS, getRid());
35         req.callback(_rdetailDraw);
36         req.send();
37 }
38
39 function rdetailViewMarc() {
40         if(!record) return;
41
42         if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
43                 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
44                 req.send(true);
45                 var html = req.result();
46                 G.ui.rdetail.view_marc_box.innerHTML = html;
47         }
48         swapCanvas(G.ui.rdetail.view_marc_div);
49 }
50
51
52 function rdetailShowLocalCopies() {
53
54         var found = false;
55         var rows = copyRowParent.getElementsByTagName("tr");
56         for( var r in rows ) {
57                 if(rows[r].id == "__rdsrow") continue;
58                 hideMe(rows[r]);
59                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
60                         unHideMe(rows[r]);
61                         found = true;
62                 }
63         }
64
65         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
66         hideMe(G.ui.rdetail.cp_info_local);
67         unHideMe(G.ui.rdetail.cp_info_all);
68 }
69
70 function rdetailShowAllCopies() {
71         var rows = copyRowParent.getElementsByTagName("tr");
72         for( var r in rows ) 
73                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
74                         unHideMe(rows[r]);
75
76         hideMe(G.ui.rdetail.cp_info_all);
77         unHideMe(G.ui.rdetail.cp_info_local);
78         hideMe(G.ui.rdetail.cp_info_none);
79 }
80
81
82 function _rdetailDraw(r) {
83         record = r.getResultObject();
84
85         G.ui.rdetail.title.appendChild(text(record.title()));
86         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
87         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
88         G.ui.rdetail.edition.appendChild(text(record.edition()));
89         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
90         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
91         G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
92         setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
93         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
94
95
96         $('rdetail_place_hold').setAttribute(
97                 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
98
99         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
100         runEvt("rdetail", "recordDrawn");
101         recordsCache.push(record);
102
103         var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
104         req.callback(rdetailHandleAddedContent);
105         req.send();
106
107 }
108
109 function rdetailShowExtra(type) {
110
111         hideMe($('rdetail_copy_info_div'));
112         hideMe($('rdetail_reviews_div'));
113         hideMe($('rdetail_toc_div'));
114
115         switch(type) {
116                 case "copyinfo": unHideMe($('rdetail_copy_info_div')); break;
117                 case "reviews": unHideMe($('rdetail_reviews_div')); break;
118                 case "toc": unHideMe($('rdetail_toc_div')); break;
119         }
120 }
121
122 function rdetailHandleAddedContent(r) {
123         var resp = r.getResultObject();
124
125         if( resp.Review == 'true' ) { 
126                 var req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
127                 req.callback(rdetailShowReviews);
128                 req.send();
129         }
130
131         if( resp.TOC == 'true' ) { 
132                 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
133                 req.callback(rdetailShowTOC);
134                 req.send();
135         }
136
137 }
138
139
140 function rdetailShowReviews(r) {
141         var res = r.getResultObject();
142         var par = $('rdetail_reviews_div');
143         var template = par.removeChild($('rdetail_review_template'));
144         if( res && res.length > 0 ) {
145                 unHideMe($('rdetail_reviews_link'));
146                 for( var i = 0; i != res.length; i++ ) {
147                         var rev = res[i];       
148                         if( rev.text && rev.info ) {
149                                 var node = template.cloneNode(true);
150                                 $n(node, 'review_header').appendChild(text(rev.info));
151                                 $n(node, 'review_text').appendChild(text(rev.text));
152                                 par.appendChild(node);
153                         }
154                 }
155         }
156 }
157
158 function rdetailShowTOC(r) {
159         var resp = r.getResultObject();
160         if(resp) {
161                 unHideMe($('rdetail_toc_link'));
162                 $('rdetail_toc_div').innerHTML = resp;
163         }
164 }
165
166
167 function rdetailBuildInfoRows() {
168         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
169         req.callback(_rdetailBuildInfoRows);
170         req.send();
171 }
172
173 /* pre-allocate the copy info table with all org units in correct order */
174 function _rdetailRows(node) {
175
176         if(node) {
177
178                 var row = copyRow.cloneNode(true);
179                 row.id = "cp_info_" + node.id();
180
181                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
182                 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
183                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
184         
185                 libtd.appendChild(text(node.name()));
186                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
187         
188                 if(!findOrgType(node.ou_type()).can_have_vols()) {
189
190                         row.removeChild(cntd);
191                         row.removeChild(cpctd);
192
193                         libtd.setAttribute("colspan", numStatuses + 2 );
194                         libtd.colSpan = numStatuses + 2;
195                         //addCSSClass(row, config.css.color_3);
196                         addCSSClass(row, 'copy_info_region_row');
197                 } 
198         
199                 copyRowParent.appendChild(row);
200
201         } else { node = globalOrgTree; }
202
203         for( var c in node.children() ) 
204                 _rdetailRows(node.children()[c]);
205 }
206
207 /* walk through the copy info and build rows where necessary */
208 function _rdetailBuildInfoRows(r) {
209
210         _rdetailRows();
211
212         var summary = r.getResultObject();
213
214         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
215                 G.ui.rdetail.cp_info_loading);
216
217         var found = false;
218         for( var i = 0; i < summary.length; i++ ) {
219
220                 var arr = summary[i];
221                 var thisOrg = findOrgUnit(arr[0]);
222                 var rowNode = $("cp_info_" + thisOrg.id());
223
224                 if(rowNode.getAttribute("used")) {
225
226                         if( rowNode.nextSibling )
227                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
228                         else
229                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
230                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
231                         n.appendChild(text(thisOrg.name()));
232                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
233
234                 } else rowNode.setAttribute("used", "1");
235
236                 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
237
238                 var cpc_temp = rowNode.removeChild(
239                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
240
241                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
242
243                 var isLocal = false;
244                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
245                 rdetailSetPath( thisOrg, isLocal );
246
247         }
248
249         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
250
251 }
252
253 /* sets the path to org as 'active' and displays the 
254         path if it's local */
255 function rdetailSetPath(org, local) {
256         if( findOrgDepth(org) == 0 ) return;
257         var row = $("cp_info_" + org.id());
258         row.setAttribute("hasinfo", "1");
259         if(local) {
260                 unHideMe(row);
261                 row.setAttribute("local", "1");
262         }
263         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
264 }
265
266 function rdetailApplyStatuses( row, template, statuses ) {
267         for( var j in _statusPositions ) {
268                 var stat = _statusPositions[j];
269                 var val = statuses[stat.id()];
270                 var nn = template.cloneNode(true);
271                 if(val) nn.appendChild(text(val));
272                 else nn.appendChild(text(0));
273                 row.appendChild(nn);    
274         }
275 }
276
277
278 /* --------------------------------------------------------------------- */
279 var _statusPositions = {};
280
281 function rdetailBuildStatusColumns() {
282
283         rdetailGrabCopyStatuses();
284         var parent = statusRow;
285         var template = parent.removeChild(G.ui.rdetail.cp_status);
286
287         var i = 0;
288         for( i = 0; i < cp_statuses.length; i++ ) {
289
290                 var c = cp_statuses[i];
291
292                 if(c && c.holdable()) {
293
294                         var name = c.name();
295                         _statusPositions[i] = c;
296                         var node = template.cloneNode(true);
297                         var data = findNodeByName( node, config.names.rdetail.cp_status);
298
299                         data.appendChild(text(name));
300                         parent.appendChild(node);
301                 }       
302         }       
303
304         numStatuses = 0;
305         for(x in _statusPositions) numStatuses++; 
306 }
307
308 function rdetailGrabCopyStatuses() {
309         if(cp_statuses) return cp_statuses;
310    var req = new Request(FETCH_COPY_STATUSES);
311    req.send(true);
312         cp_statuses = req.result();
313         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
314 }
315
316 function _rdetailSortStatuses(a, b) {
317         return parseInt(a.id()) - parseInt(b.id());
318 }
319
320