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 var callnumberCache = {};
17 var rdetailLocalOnly = true;
18 var globalCNCache = {};
20 var nextContainerIndex;
22 function rdetailDraw() {
23 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
24 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
25 statusRow = G.ui.rdetail.cp_status.parentNode;
26 statusRow.id = '__rdsrow';
28 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
29 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
31 if(getLocation() == globalOrgTree.id())
32 hideMe(G.ui.rdetail.cp_info_all);
34 var req = new Request(FETCH_RMODS, getRid());
35 req.callback(_rdetailDraw);
39 function buildunAPISpan (span, type, id) {
43 addCSSClass(span,'unapi-uri');
45 span.appendChild(text('unAPI'));
48 'tag:' + cgi.server_name + ',' +
54 var rdeatilMarcFetched = false;
55 function rdetailViewMarc(r,id) {
56 hideMe($('rdetail_extras_loading'));
57 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
61 var div = elem('div', { "class" : 'hide_me' });
62 var span = div.appendChild( elem('span') );
64 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
66 /* add the unapi span inside a hidden div */
67 $('rdetail_view_marc_box').insertBefore(div, $('rdetail_view_marc_box').firstChild);
71 function rdetailShowLocalCopies() {
74 var rows = copyRowParent.getElementsByTagName("tr");
75 for( var r in rows ) {
76 if(rows[r].id == "__rdsrow") continue;
78 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
84 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
85 hideMe(G.ui.rdetail.cp_info_local);
86 unHideMe(G.ui.rdetail.cp_info_all);
87 rdetailLocalOnly = true;
90 function rdetailShowAllCopies() {
91 var rows = copyRowParent.getElementsByTagName("tr");
93 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
96 hideMe(G.ui.rdetail.cp_info_all);
97 unHideMe(G.ui.rdetail.cp_info_local);
98 hideMe(G.ui.rdetail.cp_info_none);
99 rdetailLocalOnly = false;
103 function _rdetailDraw(r) {
104 record = r.getResultObject();
106 runEvt('rdetail', 'recordRetrieved', record.doc_id());
108 G.ui.rdetail.title.appendChild(text(record.title()));
109 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
110 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
111 G.ui.rdetail.edition.appendChild(text(record.edition()));
112 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
113 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
114 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
115 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
116 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
119 $('rdetail_place_hold').setAttribute(
120 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
122 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
123 runEvt("rdetail", "recordDrawn");
124 recordsCache.push(record);
126 rdetailSetExtrasSelector();
128 var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
129 req.callback(rdetailHandleAddedContent);
132 resultBuildCaches( [ record ] );
133 resultDrawSubjects();
137 function rdetailSetExtrasSelector() {
138 if(!grabUser()) return;
139 unHideMe($('rdetail_more_actions'));
141 var req = new Request(
142 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
143 req.callback(rdetailAddBookbags);
147 function rdetailAddBookbags(r) {
149 var containers = r.getResultObject();
150 var selector = $('rdetail_more_actions_selector');
153 doSelectorActions(selector);
155 for( var i = 0; i != containers.length; i++ ) {
157 var container = containers[i];
158 insertSelectorVal( selector, index++, container.name(),
159 "container_" + container.id(), rdetailAddToBookbag, 1 );
162 nextContainerIndex = index;
163 if(!found) insertSelectorVal( selector, 3, "name", "value", 1 );
167 function rdetailNewBookbag() {
168 var name = prompt($('rdetail_bb_new').innerHTML,"");
172 if( id = containerCreate( name ) ) {
173 alert($('rdetail_bb_success').innerHTML);
174 var selector = $('rdetail_more_actions_selector');
175 insertSelectorVal( selector, nextContainerIndex++, name,
176 "container_" + id, rdetailAddToBookbag, 1 );
177 setSelector( selector, 'start' );
182 function rdetailAddToBookbag() {
183 var selector = $('rdetail_more_actions_selector');
184 var id = selector.options[selector.selectedIndex].value;
185 setSelector( selector, 'start' );
187 if( containerCreateItem( id.substring(10), record.doc_id() )) {
188 alert($('rdetail_bb_item_success').innerHTML);
194 var rdetailTocFetched = false;
195 var rdetailReviewFetched = false;
196 var rdetailMarcFetched = false;
198 function rdetailShowExtra(type) {
200 hideMe($('rdetail_copy_info_div'));
201 hideMe($('rdetail_reviews_div'));
202 hideMe($('rdetail_toc_div'));
203 hideMe($('rdetail_marc_div'));
204 hideMe($('cn_browse'));
205 hideMe($('rdetail_cn_browse_div'));
206 hideMe($('rdetail_notes_div'));
211 unHideMe($('rdetail_copy_info_div'));
215 unHideMe($('rdetail_reviews_div'));
216 if(rdetailReviewFetched) break;
217 unHideMe($('rdetail_extras_loading'));
218 rdetailReviewFetched = true;
219 req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
220 req.callback(rdetailShowReviews);
225 unHideMe($('rdetail_toc_div'));
226 if(rdetailTocFetched) break;
227 unHideMe($('rdetail_extras_loading'));
228 rdetailTocFetched = true;
229 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
230 req.callback(rdetailShowTOC);
235 unHideMe($('rdetail_marc_div'));
236 if(rdetailMarcFetched) return;
237 unHideMe($('rdetail_extras_loading'));
238 rdetailMarcFetched = true;
239 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
240 req.callback(rdetailViewMarc);
245 unHideMe($('rdetail_cn_browse_div'));
246 rdetailShowCNBrowse(defaultCN, null, true);
250 unHideMe($('rdetail_notes_div'));
255 function rdetailBuildCNList() {
256 var select = $('cn_browse_selector');
259 for( var cn in callnumberCache ) arr.push( cn );
262 if( arr.length == 0 ) {
263 hideMe($('rdetail_cn_browse_select_div'));
267 for( var i in arr ) {
269 var opt = new Option(cn);
270 select.options[index++] = opt;
272 select.onchange = rdetailGatherCN;
275 function rdetailGatherCN() {
276 var cn = getSelectorVal($('cn_browse_selector'));
277 rdetailShowCNBrowse( cn, getDepth(), true );
278 setSelector( $('cn_browse_selector'), cn );
282 function rdetailShowCNBrowse( cn, depth, fromOnclick ) {
284 rdetailBuildCNList();
285 setSelector( $('cn_browse_selector'), cn );
286 hideMe($('rdetail_copy_info_div'));
287 hideMe($('rdetail_reviews_div'));
288 hideMe($('rdetail_toc_div'));
289 hideMe($('rdetail_marc_div'));
290 unHideMe($('rdetail_cn_browse_div'));
291 unHideMe($('cn_browse'));
292 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
293 cnBrowseGo(cn, depth);
296 function rdetailHandleAddedContent(r) {
297 var resp = r.getResultObject();
298 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
299 if( resp.TOC == 'true' ) unHideMe($('rdetail_toc_link'));
303 function rdetailShowReviews(r) {
304 hideMe($('rdetail_extras_loading'));
305 var res = r.getResultObject();
306 var par = $('rdetail_reviews_div');
307 var template = par.removeChild($('rdetail_review_template'));
308 if( res && res.length > 0 ) {
309 unHideMe($('rdetail_reviews_link'));
310 for( var i = 0; i != res.length; i++ ) {
312 if( rev.text && rev.info ) {
313 var node = template.cloneNode(true);
314 $n(node, 'review_header').appendChild(text(rev.info));
315 $n(node, 'review_text').appendChild(text(rev.text));
316 par.appendChild(node);
322 function rdetailShowTOC(r) {
323 hideMe($('rdetail_extras_loading'));
324 var resp = r.getResultObject();
326 unHideMe($('rdetail_toc_link'));
327 $('rdetail_toc_div').innerHTML = resp;
332 function rdetailBuildInfoRows() {
333 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
334 req.callback(_rdetailBuildInfoRows);
338 /* pre-allocate the copy info table with all org units in correct order */
339 function _rdetailRows(node) {
343 var row = copyRow.cloneNode(true);
344 row.id = "cp_info_" + node.id();
346 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
347 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
348 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
350 libtd.appendChild(text(node.name()));
351 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
353 if(!findOrgType(node.ou_type()).can_have_vols()) {
355 row.removeChild(cntd);
356 row.removeChild(cpctd);
358 libtd.setAttribute("colspan", numStatuses + 2 );
359 libtd.colSpan = numStatuses + 2;
360 addCSSClass(row, 'copy_info_region_row');
363 copyRowParent.appendChild(row);
365 } else { node = globalOrgTree; }
367 for( var c in node.children() )
368 _rdetailRows(node.children()[c]);
371 /* walk through the copy info and build rows where necessary */
372 var localCNFound = false;
373 function _rdetailBuildInfoRows(r) {
377 var summary = r.getResultObject();
380 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
381 G.ui.rdetail.cp_info_loading);
384 for( var i = 0; i < summary.length; i++ ) {
386 var arr = summary[i];
387 globalCNCache[arr[1]] = 1;
388 var thisOrg = findOrgUnit(arr[0]);
389 var rowNode = $("cp_info_" + thisOrg.id());
390 if(!rowNode) continue;
392 if(rowNode.getAttribute("used")) {
394 if( rowNode.nextSibling )
395 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
397 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
398 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
399 n.appendChild(text(thisOrg.name()));
400 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
402 } else rowNode.setAttribute("used", "1");
404 var cpc_temp = rowNode.removeChild(
405 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
407 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
410 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
418 rdetailSetPath( thisOrg, isLocal );
419 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal );
421 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
424 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
426 /* now that we know what CN's we have, grab the associated notes */
430 function rdetailFetchNotes() {
431 var req = new Request(FETCH_BIBLIO_NOTES, record.doc_id());
432 req.callback(rdetailDrawNotes);
436 var rdetailNotesTemplate;
437 function rdetailDrawNotes(r) {
438 var notes = r.getResultObject();
440 var tbody = $('rdetail_notes_tbody');
441 if(!rdetailNotesTemplate)
442 rdetailNotesTemplate = tbody.removeChild($('rdetail_notes_row'));
445 for( var t in notes.titles ) {
446 var note = notes.copies[c];
447 /* these need to go into a title notes
448 section different from the copy/cn notes (on the title summary?) */
451 for( var v in notes.volumes ) {
452 var note = notes.copies[c];
453 var row = rdetailNotesTemplate.cloneNode(true);
457 for( var c in notes.copies ) {
459 var copynode = notes.copies[c];
460 var copy = copynode.id;
461 var nts = copynode.notes;
462 for( var n in nts ) {
464 var row = rdetailNotesTemplate.cloneNode(true);
465 $n(row, 'rdetail_notes_title').appendChild(text(note.title()));
466 $n(row, 'rdetail_notes_value').appendChild(text(note.value()));
467 tbody.appendChild(row);
471 if(found) unHideMe($('rdetail_viewnotes_link'));
474 function rdetailBuildBrowseInfo(row, cn, local) {
475 /* used for building the shelf browser */
477 var cache = callnumberCache[cn];
478 if( cache ) cache.count++;
479 else callnumberCache[cn] = { count : 1 };
482 var depth = getDepth();
483 if( !local ) depth = findOrgDepth(globalOrgTree);
484 var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + cn + '", "'+depth+'");' }, cn);
485 addCSSClass(a, 'classic_link');
486 findNodeByName( row, config.names.rdetail.cn_cell ).appendChild(a);
489 /* sets the path to org as 'active' and displays the
490 path if it's local */
491 function rdetailSetPath(org, local) {
492 if( findOrgDepth(org) == 0 ) return;
493 var row = $("cp_info_" + org.id());
494 row.setAttribute("hasinfo", "1");
497 row.setAttribute("local", "1");
499 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
502 function rdetailApplyStatuses( row, template, statuses ) {
503 for( var j in _statusPositions ) {
504 var stat = _statusPositions[j];
505 var val = statuses[stat.id()];
506 var nn = template.cloneNode(true);
507 if(val) nn.appendChild(text(val));
508 else nn.appendChild(text(0));
514 /* --------------------------------------------------------------------- */
515 var _statusPositions = {};
517 function rdetailBuildStatusColumns() {
519 rdetailGrabCopyStatuses();
520 var parent = statusRow;
521 var template = parent.removeChild(G.ui.rdetail.cp_status);
524 for( i = 0; i < cp_statuses.length; i++ ) {
526 var c = cp_statuses[i];
528 if(c && c.holdable()) {
531 _statusPositions[i] = c;
532 var node = template.cloneNode(true);
533 var data = findNodeByName( node, config.names.rdetail.cp_status);
535 data.appendChild(text(name));
536 parent.appendChild(node);
541 for(x in _statusPositions) numStatuses++;
544 function rdetailGrabCopyStatuses() {
545 if(cp_statuses) return cp_statuses;
546 var req = new Request(FETCH_COPY_STATUSES);
548 cp_statuses = req.result();
549 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
552 function _rdetailSortStatuses(a, b) {
553 return parseInt(a.id()) - parseInt(b.id());