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 = {};
21 var nextContainerIndex;
23 function rdetailDraw() {
24 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
25 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
26 statusRow = G.ui.rdetail.cp_status.parentNode;
27 statusRow.id = '__rdsrow';
29 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
30 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
32 if(getLocation() == globalOrgTree.id())
33 hideMe(G.ui.rdetail.cp_info_all);
35 var req = new Request(FETCH_RMODS, getRid());
36 req.callback(_rdetailDraw);
40 function buildunAPISpan (span, type, id) {
44 addCSSClass(span,'unapi-uri');
46 span.appendChild(text('unAPI'));
49 'tag:' + cgi.server_name + ',' +
55 var rdeatilMarcFetched = false;
56 function rdetailViewMarc(r,id) {
57 hideMe($('rdetail_extras_loading'));
58 $('rdetail_view_marc_box').innerHTML = r.getResultObject();
62 var div = elem('div', { "class" : 'hide_me' });
63 var span = div.appendChild( elem('span') );
65 buildunAPISpan( span, 'biblio-record_entry', record.doc_id() );
67 /* add the unapi span inside a hidden div */
68 $('rdetail_view_marc_box').insertBefore(div, $('rdetail_view_marc_box').firstChild);
72 function rdetailShowLocalCopies() {
75 var rows = copyRowParent.getElementsByTagName("tr");
76 for( var r in rows ) {
77 if(rows[r].id == "__rdsrow") continue;
79 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
85 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
86 hideMe(G.ui.rdetail.cp_info_local);
87 unHideMe(G.ui.rdetail.cp_info_all);
88 rdetailLocalOnly = true;
91 function rdetailShowAllCopies() {
92 var rows = copyRowParent.getElementsByTagName("tr");
94 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
97 hideMe(G.ui.rdetail.cp_info_all);
98 unHideMe(G.ui.rdetail.cp_info_local);
99 hideMe(G.ui.rdetail.cp_info_none);
100 rdetailLocalOnly = false;
104 function _rdetailDraw(r) {
105 record = r.getResultObject();
107 runEvt('rdetail', 'recordRetrieved', record.doc_id());
109 G.ui.rdetail.title.appendChild(text(record.title()));
110 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
111 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
112 G.ui.rdetail.edition.appendChild(text(record.edition()));
113 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
114 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
115 $('rdetail_physical_desc').appendChild(text(record.physical_description()));
116 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
117 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
118 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
120 $('rdetail_place_hold').setAttribute(
121 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
123 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
124 runEvt("rdetail", "recordDrawn");
125 recordsCache.push(record);
127 rdetailSetExtrasSelector();
129 var req = new Request(FETCH_ACONT_SUMMARY, cleanISBN(record.isbn()));
130 req.callback(rdetailHandleAddedContent);
133 resultBuildCaches( [ record ] );
134 resultDrawSubjects();
138 function rdetailSetExtrasSelector() {
139 if(!grabUser()) return;
140 unHideMe($('rdetail_more_actions'));
142 var req = new Request(
143 FETCH_CONTAINERS, G.user.session, G.user.id(), 'biblio', 'bookbag' );
144 req.callback(rdetailAddBookbags);
148 function rdetailAddBookbags(r) {
150 var containers = r.getResultObject();
151 var selector = $('rdetail_more_actions_selector');
154 doSelectorActions(selector);
156 for( var i = 0; i != containers.length; i++ ) {
158 var container = containers[i];
159 insertSelectorVal( selector, index++, container.name(),
160 "container_" + container.id(), rdetailAddToBookbag, 1 );
163 nextContainerIndex = index;
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;
230 hideMe($('rdetail_extras_loading'));
231 $('rdetail_toc_div').innerHTML = record.toc().replace(/--/g, "<br/>");
233 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
234 req.callback(rdetailShowTOC);
240 unHideMe($('rdetail_marc_div'));
241 if(rdetailMarcFetched) return;
242 unHideMe($('rdetail_extras_loading'));
243 rdetailMarcFetched = true;
244 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
245 req.callback(rdetailViewMarc);
250 unHideMe($('rdetail_cn_browse_div'));
251 rdetailShowCNBrowse(defaultCN, null, true);
255 unHideMe($('rdetail_notes_div'));
260 function rdetailBuildCNList() {
261 var select = $('cn_browse_selector');
264 for( var cn in callnumberCache ) arr.push( cn );
267 if( arr.length == 0 ) {
268 hideMe($('rdetail_cn_browse_select_div'));
272 for( var i in arr ) {
274 var opt = new Option(cn);
275 select.options[index++] = opt;
277 select.onchange = rdetailGatherCN;
280 function rdetailGatherCN() {
281 var cn = getSelectorVal($('cn_browse_selector'));
282 rdetailShowCNBrowse( cn, getDepth(), true );
283 setSelector( $('cn_browse_selector'), cn );
287 function rdetailShowCNBrowse( cn, depth, fromOnclick ) {
289 rdetailBuildCNList();
290 setSelector( $('cn_browse_selector'), cn );
291 hideMe($('rdetail_copy_info_div'));
292 hideMe($('rdetail_reviews_div'));
293 hideMe($('rdetail_toc_div'));
294 hideMe($('rdetail_marc_div'));
295 unHideMe($('rdetail_cn_browse_div'));
296 unHideMe($('cn_browse'));
297 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
298 cnBrowseGo(cn, depth);
301 function rdetailHandleAddedContent(r) {
302 var resp = r.getResultObject();
303 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
304 if( resp.TOC == 'true' ) {
305 unHideMe($('rdetail_toc_link'));
309 unHideMe($('rdetail_toc_link'));
315 function rdetailShowReviews(r) {
316 hideMe($('rdetail_extras_loading'));
317 var res = r.getResultObject();
318 var par = $('rdetail_reviews_div');
319 var template = par.removeChild($('rdetail_review_template'));
320 if( res && res.length > 0 ) {
321 unHideMe($('rdetail_reviews_link'));
322 for( var i = 0; i != res.length; i++ ) {
324 if( rev.text && rev.info ) {
325 var node = template.cloneNode(true);
326 $n(node, 'review_header').appendChild(text(rev.info));
327 $n(node, 'review_text').appendChild(text(rev.text));
328 par.appendChild(node);
334 function rdetailShowTOC(r) {
335 hideMe($('rdetail_extras_loading'));
336 var resp = r.getResultObject();
338 unHideMe($('rdetail_toc_link'));
339 $('rdetail_toc_div').innerHTML = resp;
344 function rdetailBuildInfoRows() {
345 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
346 req.callback(_rdetailBuildInfoRows);
350 /* pre-allocate the copy info table with all org units in correct order */
351 function _rdetailRows(node) {
355 var row = copyRow.cloneNode(true);
356 row.id = "cp_info_" + node.id();
358 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
359 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
360 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
362 libtd.appendChild(text(node.name()));
363 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
365 if(!findOrgType(node.ou_type()).can_have_vols()) {
367 row.removeChild(cntd);
368 row.removeChild(cpctd);
370 libtd.setAttribute("colspan", numStatuses + 2 );
371 libtd.colSpan = numStatuses + 2;
372 addCSSClass(row, 'copy_info_region_row');
375 copyRowParent.appendChild(row);
377 } else { node = globalOrgTree; }
379 for( var c in node.children() )
380 _rdetailRows(node.children()[c]);
383 /* walk through the copy info and build rows where necessary */
384 var localCNFound = false;
385 function _rdetailBuildInfoRows(r) {
389 var summary = r.getResultObject();
392 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
393 G.ui.rdetail.cp_info_loading);
396 for( var i = 0; i < summary.length; i++ ) {
398 var arr = summary[i];
399 globalCNCache[arr[1]] = 1;
400 var thisOrg = findOrgUnit(arr[0]);
401 var rowNode = $("cp_info_" + thisOrg.id());
402 if(!rowNode) continue;
404 if(rowNode.getAttribute("used")) {
406 if( rowNode.nextSibling )
407 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
409 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
410 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
411 n.appendChild(text(thisOrg.name()));
412 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
414 } else rowNode.setAttribute("used", "1");
416 var cpc_temp = rowNode.removeChild(
417 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
419 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
422 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
430 rdetailSetPath( thisOrg, isLocal );
431 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal );
433 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
436 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
438 /* now that we know what CN's we have, grab the associated notes */
442 function rdetailFetchNotes() {
443 var req = new Request(FETCH_BIBLIO_NOTES, record.doc_id());
444 req.callback(rdetailDrawNotes);
448 var rdetailNotesTemplate;
449 function rdetailDrawNotes(r) {
450 var notes = r.getResultObject();
453 var tbody = $('rdetail_notes_tbody');
454 if(!rdetailNotesTemplate)
455 rdetailNotesTemplate = tbody.removeChild($('rdetail_notes_row'));
458 for( var t in notes.titles ) {
459 var note = notes.copies[c];
460 /* these need to go into a title notes
461 section different from the copy/cn notes (on the title summary?) */
464 for( var v in notes.volumes ) {
465 var note = notes.copies[c];
466 var row = rdetailNotesTemplate.cloneNode(true);
470 for( var c in notes.copies ) {
472 var copynode = notes.copies[c];
473 var copy = copynode.id;
474 var nts = copynode.notes;
475 for( var n in nts ) {
477 var row = rdetailNotesTemplate.cloneNode(true);
478 $n(row, 'rdetail_notes_title').appendChild(text(note.title()));
479 $n(row, 'rdetail_notes_value').appendChild(text(note.value()));
480 tbody.appendChild(row);
484 if(found) unHideMe($('rdetail_viewnotes_link'));
487 function rdetailBuildBrowseInfo(row, cn, local) {
488 /* used for building the shelf browser */
490 var cache = callnumberCache[cn];
491 if( cache ) cache.count++;
492 else callnumberCache[cn] = { count : 1 };
495 var depth = getDepth();
496 if( !local ) depth = findOrgDepth(globalOrgTree);
497 var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + cn + '", "'+depth+'");' }, cn);
498 addCSSClass(a, 'classic_link');
499 findNodeByName( row, config.names.rdetail.cn_cell ).appendChild(a);
502 /* sets the path to org as 'active' and displays the
503 path if it's local */
504 function rdetailSetPath(org, local) {
505 if( findOrgDepth(org) == 0 ) return;
506 var row = $("cp_info_" + org.id());
507 row.setAttribute("hasinfo", "1");
510 row.setAttribute("local", "1");
512 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
515 function rdetailApplyStatuses( row, template, statuses ) {
516 for( var j in _statusPositions ) {
517 var stat = _statusPositions[j];
518 var val = statuses[stat.id()];
519 var nn = template.cloneNode(true);
520 if(val) nn.appendChild(text(val));
521 else nn.appendChild(text(0));
527 /* --------------------------------------------------------------------- */
528 var _statusPositions = {};
530 function rdetailBuildStatusColumns() {
532 rdetailGrabCopyStatuses();
533 var parent = statusRow;
534 var template = parent.removeChild(G.ui.rdetail.cp_status);
537 for( i = 0; i < cp_statuses.length; i++ ) {
539 var c = cp_statuses[i];
541 if(c && c.holdable()) {
544 _statusPositions[i] = c;
545 var node = template.cloneNode(true);
546 var data = findNodeByName( node, config.names.rdetail.cp_status);
548 data.appendChild(text(name));
549 parent.appendChild(node);
554 for(x in _statusPositions) numStatuses++;
557 function rdetailGrabCopyStatuses() {
558 if(cp_statuses) return cp_statuses;
559 var req = new Request(FETCH_COPY_STATUSES);
561 cp_statuses = req.result();
562 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
565 function _rdetailSortStatuses(a, b) {
566 return parseInt(a.id()) - parseInt(b.id());