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);
99 resultBuildCaches( [ record ] );
100 resultDrawSubjects();
101 //resultDrawAuthors();
106 var rdetailTocFetched = false;
107 var rdetailReviewFetched = false;
108 var rdetailMarcFetched = false;
110 function rdetailShowExtra(type) {
112 hideMe($('rdetail_copy_info_div'));
113 hideMe($('rdetail_reviews_div'));
114 hideMe($('rdetail_toc_div'));
115 hideMe($('rdetail_marc_div'));
116 hideMe($('cn_browse'));
117 hideMe($('rdetail_viewcn_link'));
122 unHideMe($('rdetail_copy_info_div'));
126 unHideMe($('rdetail_reviews_div'));
127 if(rdetailReviewFetched) break;
128 unHideMe($('rdetail_extras_loading'));
129 rdetailReviewFetched = true;
130 req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
131 req.callback(rdetailShowReviews);
136 unHideMe($('rdetail_toc_div'));
137 if(rdetailTocFetched) break;
138 unHideMe($('rdetail_extras_loading'));
139 rdetailTocFetched = true;
140 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
141 req.callback(rdetailShowTOC);
146 unHideMe($('rdetail_marc_div'));
147 if(rdetailMarcFetched) return;
148 unHideMe($('rdetail_extras_loading'));
149 rdetailMarcFetched = true;
150 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
151 req.callback(rdetailViewMarc);
157 function rdetailShowCNBrowse( cn ) {
158 hideMe($('rdetail_copy_info_div'));
159 hideMe($('rdetail_reviews_div'));
160 hideMe($('rdetail_toc_div'));
161 hideMe($('rdetail_marc_div'));
162 unHideMe($('rdetail_viewcn_link'));
163 unHideMe($('cn_browse'));
167 function rdetailHandleAddedContent(r) {
168 var resp = r.getResultObject();
169 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
170 if( resp.TOC == 'true' ) unHideMe($('rdetail_toc_link'));
174 function rdetailShowReviews(r) {
175 hideMe($('rdetail_extras_loading'));
176 var res = r.getResultObject();
177 var par = $('rdetail_reviews_div');
178 var template = par.removeChild($('rdetail_review_template'));
179 if( res && res.length > 0 ) {
180 unHideMe($('rdetail_reviews_link'));
181 for( var i = 0; i != res.length; i++ ) {
183 if( rev.text && rev.info ) {
184 var node = template.cloneNode(true);
185 $n(node, 'review_header').appendChild(text(rev.info));
186 $n(node, 'review_text').appendChild(text(rev.text));
187 par.appendChild(node);
193 function rdetailShowTOC(r) {
194 hideMe($('rdetail_extras_loading'));
195 var resp = r.getResultObject();
197 unHideMe($('rdetail_toc_link'));
198 $('rdetail_toc_div').innerHTML = resp;
203 function rdetailBuildInfoRows() {
204 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
205 req.callback(_rdetailBuildInfoRows);
209 /* pre-allocate the copy info table with all org units in correct order */
210 function _rdetailRows(node) {
214 var row = copyRow.cloneNode(true);
215 row.id = "cp_info_" + node.id();
217 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
218 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
219 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
221 libtd.appendChild(text(node.name()));
222 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
224 if(!findOrgType(node.ou_type()).can_have_vols()) {
226 row.removeChild(cntd);
227 row.removeChild(cpctd);
229 libtd.setAttribute("colspan", numStatuses + 2 );
230 libtd.colSpan = numStatuses + 2;
231 addCSSClass(row, 'copy_info_region_row');
234 copyRowParent.appendChild(row);
236 } else { node = globalOrgTree; }
238 for( var c in node.children() )
239 _rdetailRows(node.children()[c]);
242 /* walk through the copy info and build rows where necessary */
243 function _rdetailBuildInfoRows(r) {
247 var summary = r.getResultObject();
250 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
251 G.ui.rdetail.cp_info_loading);
254 for( var i = 0; i < summary.length; i++ ) {
256 var arr = summary[i];
257 var thisOrg = findOrgUnit(arr[0]);
258 var rowNode = $("cp_info_" + thisOrg.id());
260 if(rowNode.getAttribute("used")) {
262 if( rowNode.nextSibling )
263 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
265 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
266 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
267 n.appendChild(text(thisOrg.name()));
268 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
270 } else rowNode.setAttribute("used", "1");
272 //var a = elem("a", {href:'javascript:cnBrowseGo("' + arr[1] + '");' }, arr[1]);
273 var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + arr[1] + '");' }, arr[1]);
274 addCSSClass(a, 'classic_link');
275 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(a);
277 //findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
279 var cpc_temp = rowNode.removeChild(
280 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
282 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
285 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
286 rdetailSetPath( thisOrg, isLocal );
290 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
294 /* sets the path to org as 'active' and displays the
295 path if it's local */
296 function rdetailSetPath(org, local) {
297 if( findOrgDepth(org) == 0 ) return;
298 var row = $("cp_info_" + org.id());
299 row.setAttribute("hasinfo", "1");
302 row.setAttribute("local", "1");
304 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
307 function rdetailApplyStatuses( row, template, statuses ) {
308 for( var j in _statusPositions ) {
309 var stat = _statusPositions[j];
310 var val = statuses[stat.id()];
311 var nn = template.cloneNode(true);
312 if(val) nn.appendChild(text(val));
313 else nn.appendChild(text(0));
319 /* --------------------------------------------------------------------- */
320 var _statusPositions = {};
322 function rdetailBuildStatusColumns() {
324 rdetailGrabCopyStatuses();
325 var parent = statusRow;
326 var template = parent.removeChild(G.ui.rdetail.cp_status);
329 for( i = 0; i < cp_statuses.length; i++ ) {
331 var c = cp_statuses[i];
333 if(c && c.holdable()) {
336 _statusPositions[i] = c;
337 var node = template.cloneNode(true);
338 var data = findNodeByName( node, config.names.rdetail.cp_status);
340 data.appendChild(text(name));
341 parent.appendChild(node);
346 for(x in _statusPositions) numStatuses++;
349 function rdetailGrabCopyStatuses() {
350 if(cp_statuses) return cp_statuses;
351 var req = new Request(FETCH_COPY_STATUSES);
353 cp_statuses = req.result();
354 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
357 function _rdetailSortStatuses(a, b) {
358 return parseInt(a.id()) - parseInt(b.id());