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 for( var i in arr ) {
264 var opt = new Option(cn);
265 select.options[index++] = opt;
267 select.onchange = rdetailGatherCN;
270 function rdetailGatherCN() {
271 var cn = getSelectorVal($('cn_browse_selector'));
272 rdetailShowCNBrowse( cn, getDepth(), true );
273 setSelector( $('cn_browse_selector'), cn );
277 function rdetailShowCNBrowse( cn, depth, fromOnclick ) {
279 rdetailBuildCNList();
280 setSelector( $('cn_browse_selector'), cn );
281 hideMe($('rdetail_copy_info_div'));
282 hideMe($('rdetail_reviews_div'));
283 hideMe($('rdetail_toc_div'));
284 hideMe($('rdetail_marc_div'));
285 unHideMe($('rdetail_cn_browse_div'));
286 unHideMe($('cn_browse'));
287 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
288 cnBrowseGo(cn, depth);
291 function rdetailHandleAddedContent(r) {
292 var resp = r.getResultObject();
293 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
294 if( resp.TOC == 'true' ) unHideMe($('rdetail_toc_link'));
298 function rdetailShowReviews(r) {
299 hideMe($('rdetail_extras_loading'));
300 var res = r.getResultObject();
301 var par = $('rdetail_reviews_div');
302 var template = par.removeChild($('rdetail_review_template'));
303 if( res && res.length > 0 ) {
304 unHideMe($('rdetail_reviews_link'));
305 for( var i = 0; i != res.length; i++ ) {
307 if( rev.text && rev.info ) {
308 var node = template.cloneNode(true);
309 $n(node, 'review_header').appendChild(text(rev.info));
310 $n(node, 'review_text').appendChild(text(rev.text));
311 par.appendChild(node);
317 function rdetailShowTOC(r) {
318 hideMe($('rdetail_extras_loading'));
319 var resp = r.getResultObject();
321 unHideMe($('rdetail_toc_link'));
322 $('rdetail_toc_div').innerHTML = resp;
327 function rdetailBuildInfoRows() {
328 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
329 req.callback(_rdetailBuildInfoRows);
333 /* pre-allocate the copy info table with all org units in correct order */
334 function _rdetailRows(node) {
338 var row = copyRow.cloneNode(true);
339 row.id = "cp_info_" + node.id();
341 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
342 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
343 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
345 libtd.appendChild(text(node.name()));
346 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
348 if(!findOrgType(node.ou_type()).can_have_vols()) {
350 row.removeChild(cntd);
351 row.removeChild(cpctd);
353 libtd.setAttribute("colspan", numStatuses + 2 );
354 libtd.colSpan = numStatuses + 2;
355 addCSSClass(row, 'copy_info_region_row');
358 copyRowParent.appendChild(row);
360 } else { node = globalOrgTree; }
362 for( var c in node.children() )
363 _rdetailRows(node.children()[c]);
366 /* walk through the copy info and build rows where necessary */
367 var localCNFound = false;
368 function _rdetailBuildInfoRows(r) {
372 var summary = r.getResultObject();
375 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
376 G.ui.rdetail.cp_info_loading);
379 for( var i = 0; i < summary.length; i++ ) {
381 var arr = summary[i];
382 globalCNCache[arr[1]] = 1;
383 var thisOrg = findOrgUnit(arr[0]);
384 var rowNode = $("cp_info_" + thisOrg.id());
385 if(!rowNode) continue;
387 if(rowNode.getAttribute("used")) {
389 if( rowNode.nextSibling )
390 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
392 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
393 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
394 n.appendChild(text(thisOrg.name()));
395 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
397 } else rowNode.setAttribute("used", "1");
399 var cpc_temp = rowNode.removeChild(
400 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
402 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
405 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
413 rdetailSetPath( thisOrg, isLocal );
414 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal );
416 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
419 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
421 /* now that we know what CN's we have, grab the associated notes */
425 function rdetailFetchNotes() {
426 var req = new Request(FETCH_BIBLIO_NOTES, record.doc_id());
427 req.callback(rdetailDrawNotes);
431 var rdetailNotesTemplate;
432 function rdetailDrawNotes(r) {
433 var notes = r.getResultObject();
435 var tbody = $('rdetail_notes_tbody');
436 if(!rdetailNotesTemplate)
437 rdetailNotesTemplate = tbody.removeChild($('rdetail_notes_row'));
440 for( var t in notes.titles ) {
441 var note = notes.copies[c];
442 /* these need to go into a title notes
443 section different from the copy/cn notes (on the title summary?) */
446 for( var v in notes.volumes ) {
447 var note = notes.copies[c];
448 var row = rdetailNotesTemplate.cloneNode(true);
452 for( var c in notes.copies ) {
454 var copynode = notes.copies[c];
455 var copy = copynode.id;
456 var nts = copynode.notes;
457 for( var n in nts ) {
459 var row = rdetailNotesTemplate.cloneNode(true);
460 $n(row, 'rdetail_notes_title').appendChild(text(note.title()));
461 $n(row, 'rdetail_notes_value').appendChild(text(note.value()));
462 tbody.appendChild(row);
466 if(found) unHideMe($('rdetail_viewnotes_link'));
469 function rdetailBuildBrowseInfo(row, cn, local) {
470 /* used for building the shelf browser */
472 var cache = callnumberCache[cn];
473 if( cache ) cache.count++;
474 else callnumberCache[cn] = { count : 1 };
477 var depth = getDepth();
478 if( !local ) depth = findOrgDepth(globalOrgTree);
479 var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + cn + '", "'+depth+'");' }, cn);
480 addCSSClass(a, 'classic_link');
481 findNodeByName( row, config.names.rdetail.cn_cell ).appendChild(a);
484 /* sets the path to org as 'active' and displays the
485 path if it's local */
486 function rdetailSetPath(org, local) {
487 if( findOrgDepth(org) == 0 ) return;
488 var row = $("cp_info_" + org.id());
489 row.setAttribute("hasinfo", "1");
492 row.setAttribute("local", "1");
494 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
497 function rdetailApplyStatuses( row, template, statuses ) {
498 for( var j in _statusPositions ) {
499 var stat = _statusPositions[j];
500 var val = statuses[stat.id()];
501 var nn = template.cloneNode(true);
502 if(val) nn.appendChild(text(val));
503 else nn.appendChild(text(0));
509 /* --------------------------------------------------------------------- */
510 var _statusPositions = {};
512 function rdetailBuildStatusColumns() {
514 rdetailGrabCopyStatuses();
515 var parent = statusRow;
516 var template = parent.removeChild(G.ui.rdetail.cp_status);
519 for( i = 0; i < cp_statuses.length; i++ ) {
521 var c = cp_statuses[i];
523 if(c && c.holdable()) {
526 _statusPositions[i] = c;
527 var node = template.cloneNode(true);
528 var data = findNodeByName( node, config.names.rdetail.cp_status);
530 data.appendChild(text(name));
531 parent.appendChild(node);
536 for(x in _statusPositions) numStatuses++;
539 function rdetailGrabCopyStatuses() {
540 if(cp_statuses) return cp_statuses;
541 var req = new Request(FETCH_COPY_STATUSES);
543 cp_statuses = req.result();
544 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
547 function _rdetailSortStatuses(a, b) {
548 return parseInt(a.id()) - parseInt(b.id());