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() {
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';
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;
29 if(getLocation() == globalOrgTree.id())
30 hideMe(G.ui.rdetail.cp_info_all);
34 var req = new Request(FETCH_RMODS, getRid());
35 req.callback(_rdetailDraw);
39 function rdetailViewMarc() {
42 if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
43 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
45 var html = req.result();
46 G.ui.rdetail.view_marc_box.innerHTML = html;
48 swapCanvas(G.ui.rdetail.view_marc_div);
52 function rdetailShowLocalCopies() {
55 var rows = copyRowParent.getElementsByTagName("tr");
56 for( var r in rows ) {
57 if(rows[r].id == "__rdsrow") continue;
59 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
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);
70 function rdetailShowAllCopies() {
71 var rows = copyRowParent.getElementsByTagName("tr");
73 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
76 hideMe(G.ui.rdetail.cp_info_all);
77 unHideMe(G.ui.rdetail.cp_info_local);
78 hideMe(G.ui.rdetail.cp_info_none);
82 function _rdetailDraw(r) {
83 record = r.getResultObject();
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()));
96 $('rdetail_place_hold').setAttribute(
97 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
99 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
100 runEvt("rdetail", "recordDrawn");
101 recordsCache.push(record);
103 var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
104 req.callback(rdetailHandleAddedContent);
109 function rdetailShowExtra(type) {
111 hideMe($('rdetail_copy_info_div'));
112 hideMe($('rdetail_reviews_div'));
113 hideMe($('rdetail_toc_div'));
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;
122 function rdetailHandleAddedContent(r) {
123 var resp = r.getResultObject();
125 if( resp.Review == 'true' ) {
126 var req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
127 req.callback(rdetailShowReviews);
131 if( resp.TOC == 'true' ) {
132 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
133 req.callback(rdetailShowTOC);
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++ ) {
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);
158 function rdetailShowTOC(r) {
159 var resp = r.getResultObject();
161 unHideMe($('rdetail_toc_link'));
162 $('rdetail_toc_div').innerHTML = resp;
167 function rdetailBuildInfoRows() {
168 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
169 req.callback(_rdetailBuildInfoRows);
173 /* pre-allocate the copy info table with all org units in correct order */
174 function _rdetailRows(node) {
178 var row = copyRow.cloneNode(true);
179 row.id = "cp_info_" + node.id();
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 );
185 libtd.appendChild(text(node.name()));
186 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
188 if(!findOrgType(node.ou_type()).can_have_vols()) {
190 row.removeChild(cntd);
191 row.removeChild(cpctd);
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');
199 copyRowParent.appendChild(row);
201 } else { node = globalOrgTree; }
203 for( var c in node.children() )
204 _rdetailRows(node.children()[c]);
207 /* walk through the copy info and build rows where necessary */
208 function _rdetailBuildInfoRows(r) {
212 var summary = r.getResultObject();
214 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
215 G.ui.rdetail.cp_info_loading);
218 for( var i = 0; i < summary.length; i++ ) {
220 var arr = summary[i];
221 var thisOrg = findOrgUnit(arr[0]);
222 var rowNode = $("cp_info_" + thisOrg.id());
224 if(rowNode.getAttribute("used")) {
226 if( rowNode.nextSibling )
227 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
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;");
234 } else rowNode.setAttribute("used", "1");
236 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
238 var cpc_temp = rowNode.removeChild(
239 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
241 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
244 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
245 rdetailSetPath( thisOrg, isLocal );
249 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
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");
261 row.setAttribute("local", "1");
263 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
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));
278 /* --------------------------------------------------------------------- */
279 var _statusPositions = {};
281 function rdetailBuildStatusColumns() {
283 rdetailGrabCopyStatuses();
284 var parent = statusRow;
285 var template = parent.removeChild(G.ui.rdetail.cp_status);
288 for( i = 0; i < cp_statuses.length; i++ ) {
290 var c = cp_statuses[i];
292 if(c && c.holdable()) {
295 _statusPositions[i] = c;
296 var node = template.cloneNode(true);
297 var data = findNodeByName( node, config.names.rdetail.cp_status);
299 data.appendChild(text(name));
300 parent.appendChild(node);
305 for(x in _statusPositions) numStatuses++;
308 function rdetailGrabCopyStatuses() {
309 if(cp_statuses) return cp_statuses;
310 var req = new Request(FETCH_COPY_STATUSES);
312 cp_statuses = req.result();
313 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
316 function _rdetailSortStatuses(a, b) {
317 return parseInt(a.id()) - parseInt(b.id());