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;
26 G.ui.rdetail.view_marc.onclick = rdetailViewMarc;
27 G.ui.rdetail.hide_marc.onclick = showCanvas;
30 if(getLocation() == globalOrgTree.id())
31 hideMe(G.ui.rdetail.cp_info_all);
33 var req = new Request(FETCH_RMODS, getRid());
34 req.callback(_rdetailDraw);
38 function rdetailViewMarc() {
41 if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
42 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
44 var html = req.result();
45 G.ui.rdetail.view_marc_box.innerHTML = html;
47 swapCanvas(G.ui.rdetail.view_marc_div);
51 function rdetailShowLocalCopies() {
54 var rows = copyRowParent.getElementsByTagName("tr");
55 for( var r in rows ) {
56 if(rows[r].id == "__rdsrow") continue;
58 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
64 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
65 hideMe(G.ui.rdetail.cp_info_local);
66 unHideMe(G.ui.rdetail.cp_info_all);
69 function rdetailShowAllCopies() {
70 var rows = copyRowParent.getElementsByTagName("tr");
72 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
75 hideMe(G.ui.rdetail.cp_info_all);
76 unHideMe(G.ui.rdetail.cp_info_local);
77 hideMe(G.ui.rdetail.cp_info_none);
81 function _rdetailDraw(r) {
82 record = r.getResultObject();
84 runEvt('rdetail', 'recordRetrieved', record.doc_id());
86 G.ui.rdetail.title.appendChild(text(record.title()));
87 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
88 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
89 G.ui.rdetail.edition.appendChild(text(record.edition()));
90 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
91 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
92 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
93 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
94 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
97 $('rdetail_place_hold').setAttribute(
98 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
100 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
101 runEvt("rdetail", "recordDrawn");
102 recordsCache.push(record);
104 var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
105 req.callback(rdetailHandleAddedContent);
110 function rdetailShowExtra(type) {
112 hideMe($('rdetail_copy_info_div'));
113 hideMe($('rdetail_reviews_div'));
114 hideMe($('rdetail_toc_div'));
117 case "copyinfo": unHideMe($('rdetail_copy_info_div')); break;
118 case "reviews": unHideMe($('rdetail_reviews_div')); break;
119 case "toc": unHideMe($('rdetail_toc_div')); break;
123 function rdetailHandleAddedContent(r) {
124 var resp = r.getResultObject();
126 if( resp.Review == 'true' ) {
127 var req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
128 req.callback(rdetailShowReviews);
132 if( resp.TOC == 'true' ) {
133 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
134 req.callback(rdetailShowTOC);
141 function rdetailShowReviews(r) {
142 var res = r.getResultObject();
143 var par = $('rdetail_reviews_div');
144 var template = par.removeChild($('rdetail_review_template'));
145 if( res && res.length > 0 ) {
146 unHideMe($('rdetail_reviews_link'));
147 for( var i = 0; i != res.length; i++ ) {
149 if( rev.text && rev.info ) {
150 var node = template.cloneNode(true);
151 $n(node, 'review_header').appendChild(text(rev.info));
152 $n(node, 'review_text').appendChild(text(rev.text));
153 par.appendChild(node);
159 function rdetailShowTOC(r) {
160 var resp = r.getResultObject();
162 unHideMe($('rdetail_toc_link'));
163 $('rdetail_toc_div').innerHTML = resp;
168 function rdetailBuildInfoRows() {
169 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
170 req.callback(_rdetailBuildInfoRows);
174 /* pre-allocate the copy info table with all org units in correct order */
175 function _rdetailRows(node) {
179 var row = copyRow.cloneNode(true);
180 row.id = "cp_info_" + node.id();
182 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
183 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
184 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
186 libtd.appendChild(text(node.name()));
187 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
189 if(!findOrgType(node.ou_type()).can_have_vols()) {
191 row.removeChild(cntd);
192 row.removeChild(cpctd);
194 libtd.setAttribute("colspan", numStatuses + 2 );
195 libtd.colSpan = numStatuses + 2;
196 //addCSSClass(row, config.css.color_3);
197 addCSSClass(row, 'copy_info_region_row');
200 copyRowParent.appendChild(row);
202 } else { node = globalOrgTree; }
204 for( var c in node.children() )
205 _rdetailRows(node.children()[c]);
208 /* walk through the copy info and build rows where necessary */
209 function _rdetailBuildInfoRows(r) {
213 var summary = r.getResultObject();
215 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
216 G.ui.rdetail.cp_info_loading);
219 for( var i = 0; i < summary.length; i++ ) {
221 var arr = summary[i];
222 var thisOrg = findOrgUnit(arr[0]);
223 var rowNode = $("cp_info_" + thisOrg.id());
225 if(rowNode.getAttribute("used")) {
227 if( rowNode.nextSibling )
228 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
230 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
231 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
232 n.appendChild(text(thisOrg.name()));
233 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
235 } else rowNode.setAttribute("used", "1");
237 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
239 var cpc_temp = rowNode.removeChild(
240 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
242 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
245 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
246 rdetailSetPath( thisOrg, isLocal );
250 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
254 /* sets the path to org as 'active' and displays the
255 path if it's local */
256 function rdetailSetPath(org, local) {
257 if( findOrgDepth(org) == 0 ) return;
258 var row = $("cp_info_" + org.id());
259 row.setAttribute("hasinfo", "1");
262 row.setAttribute("local", "1");
264 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
267 function rdetailApplyStatuses( row, template, statuses ) {
268 for( var j in _statusPositions ) {
269 var stat = _statusPositions[j];
270 var val = statuses[stat.id()];
271 var nn = template.cloneNode(true);
272 if(val) nn.appendChild(text(val));
273 else nn.appendChild(text(0));
279 /* --------------------------------------------------------------------- */
280 var _statusPositions = {};
282 function rdetailBuildStatusColumns() {
284 rdetailGrabCopyStatuses();
285 var parent = statusRow;
286 var template = parent.removeChild(G.ui.rdetail.cp_status);
289 for( i = 0; i < cp_statuses.length; i++ ) {
291 var c = cp_statuses[i];
293 if(c && c.holdable()) {
296 _statusPositions[i] = c;
297 var node = template.cloneNode(true);
298 var data = findNodeByName( node, config.names.rdetail.cp_status);
300 data.appendChild(text(name));
301 parent.appendChild(node);
306 for(x in _statusPositions) numStatuses++;
309 function rdetailGrabCopyStatuses() {
310 if(cp_statuses) return cp_statuses;
311 var req = new Request(FETCH_COPY_STATUSES);
313 cp_statuses = req.result();
314 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
317 function _rdetailSortStatuses(a, b) {
318 return parseInt(a.id()) - parseInt(b.id());