3 attachEvt("common", "run", rdetailDraw);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
5 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
8 var cp_statuses = null;
11 var copyRowParent = null;
14 var numStatuses = null;
16 function rdetailDraw() {
19 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
20 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
21 statusRow = G.ui.rdetail.cp_status.parentNode;
22 statusRow.id = '__rdsrow';
24 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
25 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
27 if(getLocation() == globalOrgTree.id())
28 hideMe(G.ui.rdetail.cp_info_all);
30 var req = new Request(FETCH_RMODS, getRid());
31 req.callback(_rdetailDraw);
35 var rdeatilMarcFetched = false;
36 function rdetailViewMarc(r) {
37 hideMe($('rdetail_extras_loading'));
38 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
42 function rdetailShowLocalCopies() {
45 var rows = copyRowParent.getElementsByTagName("tr");
46 for( var r in rows ) {
47 if(rows[r].id == "__rdsrow") continue;
49 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
55 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
56 hideMe(G.ui.rdetail.cp_info_local);
57 unHideMe(G.ui.rdetail.cp_info_all);
60 function rdetailShowAllCopies() {
61 var rows = copyRowParent.getElementsByTagName("tr");
63 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
66 hideMe(G.ui.rdetail.cp_info_all);
67 unHideMe(G.ui.rdetail.cp_info_local);
68 hideMe(G.ui.rdetail.cp_info_none);
72 function _rdetailDraw(r) {
73 record = r.getResultObject();
75 runEvt('rdetail', 'recordRetrieved', record.doc_id());
77 G.ui.rdetail.title.appendChild(text(record.title()));
78 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
79 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
80 G.ui.rdetail.edition.appendChild(text(record.edition()));
81 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
82 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
83 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
84 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
85 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
88 $('rdetail_place_hold').setAttribute(
89 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
91 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
92 runEvt("rdetail", "recordDrawn");
93 recordsCache.push(record);
95 var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
96 req.callback(rdetailHandleAddedContent);
101 var rdetailTocFetched = false;
102 var rdetailReviewFetched = false;
103 var rdetailMarcFetched = false;
105 function rdetailShowExtra(type) {
107 hideMe($('rdetail_copy_info_div'));
108 hideMe($('rdetail_reviews_div'));
109 hideMe($('rdetail_toc_div'));
110 hideMe($('rdetail_marc_div'));
115 unHideMe($('rdetail_copy_info_div'));
119 unHideMe($('rdetail_reviews_div'));
120 if(rdetailReviewFetched) break;
121 unHideMe($('rdetail_extras_loading'));
122 rdetailReviewFetched = true;
123 req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
124 req.callback(rdetailShowReviews);
129 unHideMe($('rdetail_toc_div'));
130 if(rdetailTocFetched) break;
131 unHideMe($('rdetail_extras_loading'));
132 rdetailTocFetched = true;
133 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
134 req.callback(rdetailShowTOC);
139 unHideMe($('rdetail_marc_div'));
140 if(rdetailMarcFetched) return;
141 unHideMe($('rdetail_extras_loading'));
142 rdetailMarcFetched = true;
143 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
144 req.callback(rdetailViewMarc);
150 function rdetailHandleAddedContent(r) {
151 var resp = r.getResultObject();
152 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
153 if( resp.TOC == 'true' ) unHideMe($('rdetail_toc_link'));
157 function rdetailShowReviews(r) {
158 hideMe($('rdetail_extras_loading'));
159 var res = r.getResultObject();
160 var par = $('rdetail_reviews_div');
161 var template = par.removeChild($('rdetail_review_template'));
162 if( res && res.length > 0 ) {
163 unHideMe($('rdetail_reviews_link'));
164 for( var i = 0; i != res.length; i++ ) {
166 if( rev.text && rev.info ) {
167 var node = template.cloneNode(true);
168 $n(node, 'review_header').appendChild(text(rev.info));
169 $n(node, 'review_text').appendChild(text(rev.text));
170 par.appendChild(node);
176 function rdetailShowTOC(r) {
177 hideMe($('rdetail_extras_loading'));
178 var resp = r.getResultObject();
180 unHideMe($('rdetail_toc_link'));
181 $('rdetail_toc_div').innerHTML = resp;
186 function rdetailBuildInfoRows() {
187 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
188 req.callback(_rdetailBuildInfoRows);
192 /* pre-allocate the copy info table with all org units in correct order */
193 function _rdetailRows(node) {
197 var row = copyRow.cloneNode(true);
198 row.id = "cp_info_" + node.id();
200 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
201 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
202 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
204 libtd.appendChild(text(node.name()));
205 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
207 if(!findOrgType(node.ou_type()).can_have_vols()) {
209 row.removeChild(cntd);
210 row.removeChild(cpctd);
212 libtd.setAttribute("colspan", numStatuses + 2 );
213 libtd.colSpan = numStatuses + 2;
214 addCSSClass(row, 'copy_info_region_row');
217 copyRowParent.appendChild(row);
219 } else { node = globalOrgTree; }
221 for( var c in node.children() )
222 _rdetailRows(node.children()[c]);
225 /* walk through the copy info and build rows where necessary */
226 function _rdetailBuildInfoRows(r) {
230 var summary = r.getResultObject();
232 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
233 G.ui.rdetail.cp_info_loading);
236 for( var i = 0; i < summary.length; i++ ) {
238 var arr = summary[i];
239 var thisOrg = findOrgUnit(arr[0]);
240 var rowNode = $("cp_info_" + thisOrg.id());
242 if(rowNode.getAttribute("used")) {
244 if( rowNode.nextSibling )
245 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
247 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
248 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
249 n.appendChild(text(thisOrg.name()));
250 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
252 } else rowNode.setAttribute("used", "1");
254 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
256 var cpc_temp = rowNode.removeChild(
257 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
259 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
262 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
263 rdetailSetPath( thisOrg, isLocal );
267 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
271 /* sets the path to org as 'active' and displays the
272 path if it's local */
273 function rdetailSetPath(org, local) {
274 if( findOrgDepth(org) == 0 ) return;
275 var row = $("cp_info_" + org.id());
276 row.setAttribute("hasinfo", "1");
279 row.setAttribute("local", "1");
281 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
284 function rdetailApplyStatuses( row, template, statuses ) {
285 for( var j in _statusPositions ) {
286 var stat = _statusPositions[j];
287 var val = statuses[stat.id()];
288 var nn = template.cloneNode(true);
289 if(val) nn.appendChild(text(val));
290 else nn.appendChild(text(0));
296 /* --------------------------------------------------------------------- */
297 var _statusPositions = {};
299 function rdetailBuildStatusColumns() {
301 rdetailGrabCopyStatuses();
302 var parent = statusRow;
303 var template = parent.removeChild(G.ui.rdetail.cp_status);
306 for( i = 0; i < cp_statuses.length; i++ ) {
308 var c = cp_statuses[i];
310 if(c && c.holdable()) {
313 _statusPositions[i] = c;
314 var node = template.cloneNode(true);
315 var data = findNodeByName( node, config.names.rdetail.cp_status);
317 data.appendChild(text(name));
318 parent.appendChild(node);
323 for(x in _statusPositions) numStatuses++;
326 function rdetailGrabCopyStatuses() {
327 if(cp_statuses) return cp_statuses;
328 var req = new Request(FETCH_COPY_STATUSES);
330 cp_statuses = req.result();
331 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
334 function _rdetailSortStatuses(a, b) {
335 return parseInt(a.id()) - parseInt(b.id());