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;
164 if(!found) insertSelectorVal( selector, index, "name", "value", 1 );
168 function rdetailNewBookbag() {
169 var name = prompt($('rdetail_bb_new').innerHTML,"");
173 if( id = containerCreate( name ) ) {
174 alert($('rdetail_bb_success').innerHTML);
175 var selector = $('rdetail_more_actions_selector');
176 insertSelectorVal( selector, nextContainerIndex++, name,
177 "container_" + id, rdetailAddToBookbag, 1 );
178 setSelector( selector, 'start' );
183 function rdetailAddToBookbag() {
184 var selector = $('rdetail_more_actions_selector');
185 var id = selector.options[selector.selectedIndex].value;
186 setSelector( selector, 'start' );
188 if( containerCreateItem( id.substring(10), record.doc_id() )) {
189 alert($('rdetail_bb_item_success').innerHTML);
195 var rdetailTocFetched = false;
196 var rdetailReviewFetched = false;
197 var rdetailMarcFetched = false;
199 function rdetailShowExtra(type) {
201 hideMe($('rdetail_copy_info_div'));
202 hideMe($('rdetail_reviews_div'));
203 hideMe($('rdetail_toc_div'));
204 hideMe($('rdetail_marc_div'));
205 hideMe($('cn_browse'));
206 hideMe($('rdetail_cn_browse_div'));
207 hideMe($('rdetail_notes_div'));
212 unHideMe($('rdetail_copy_info_div'));
216 unHideMe($('rdetail_reviews_div'));
217 if(rdetailReviewFetched) break;
218 unHideMe($('rdetail_extras_loading'));
219 rdetailReviewFetched = true;
220 req = new Request(FETCH_REVIEWS, cleanISBN(record.isbn()));
221 req.callback(rdetailShowReviews);
226 unHideMe($('rdetail_toc_div'));
227 if(rdetailTocFetched) break;
228 unHideMe($('rdetail_extras_loading'));
229 rdetailTocFetched = true;
231 hideMe($('rdetail_extras_loading'));
232 $('rdetail_toc_div').innerHTML = record.toc().replace(/--/g, "<br/>");
234 var req = new Request(FETCH_TOC, cleanISBN(record.isbn()));
235 req.callback(rdetailShowTOC);
241 unHideMe($('rdetail_marc_div'));
242 if(rdetailMarcFetched) return;
243 unHideMe($('rdetail_extras_loading'));
244 rdetailMarcFetched = true;
245 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
246 req.callback(rdetailViewMarc);
251 unHideMe($('rdetail_cn_browse_div'));
252 rdetailShowCNBrowse(defaultCN, null, true);
256 unHideMe($('rdetail_notes_div'));
261 function rdetailBuildCNList() {
262 var select = $('cn_browse_selector');
265 for( var cn in callnumberCache ) arr.push( cn );
268 if( arr.length == 0 ) {
269 hideMe($('rdetail_cn_browse_select_div'));
273 for( var i in arr ) {
275 var opt = new Option(cn);
276 select.options[index++] = opt;
278 select.onchange = rdetailGatherCN;
281 function rdetailGatherCN() {
282 var cn = getSelectorVal($('cn_browse_selector'));
283 rdetailShowCNBrowse( cn, getDepth(), true );
284 setSelector( $('cn_browse_selector'), cn );
288 function rdetailShowCNBrowse( cn, depth, fromOnclick ) {
290 rdetailBuildCNList();
291 setSelector( $('cn_browse_selector'), cn );
292 hideMe($('rdetail_copy_info_div'));
293 hideMe($('rdetail_reviews_div'));
294 hideMe($('rdetail_toc_div'));
295 hideMe($('rdetail_marc_div'));
296 unHideMe($('rdetail_cn_browse_div'));
297 unHideMe($('cn_browse'));
298 if( !rdetailLocalOnly && ! fromOnclick ) depth = findOrgDepth(globalOrgTree);
299 cnBrowseGo(cn, depth);
302 function rdetailHandleAddedContent(r) {
303 var resp = r.getResultObject();
304 if( resp.Review == 'true' ) unHideMe($('rdetail_reviews_link'));
305 if( resp.TOC == 'true' ) {
306 unHideMe($('rdetail_toc_link'));
310 unHideMe($('rdetail_toc_link'));
316 function rdetailShowReviews(r) {
317 hideMe($('rdetail_extras_loading'));
318 var res = r.getResultObject();
319 var par = $('rdetail_reviews_div');
320 var template = par.removeChild($('rdetail_review_template'));
321 if( res && res.length > 0 ) {
322 unHideMe($('rdetail_reviews_link'));
323 for( var i = 0; i != res.length; i++ ) {
325 if( rev.text && rev.info ) {
326 var node = template.cloneNode(true);
327 $n(node, 'review_header').appendChild(text(rev.info));
328 $n(node, 'review_text').appendChild(text(rev.text));
329 par.appendChild(node);
335 function rdetailShowTOC(r) {
336 hideMe($('rdetail_extras_loading'));
337 var resp = r.getResultObject();
339 unHideMe($('rdetail_toc_link'));
340 $('rdetail_toc_div').innerHTML = resp;
345 function rdetailBuildInfoRows() {
346 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
347 req.callback(_rdetailBuildInfoRows);
351 /* pre-allocate the copy info table with all org units in correct order */
352 function _rdetailRows(node) {
356 var row = copyRow.cloneNode(true);
357 row.id = "cp_info_" + node.id();
359 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
360 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
361 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
363 libtd.appendChild(text(node.name()));
364 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
366 if(!findOrgType(node.ou_type()).can_have_vols()) {
368 row.removeChild(cntd);
369 row.removeChild(cpctd);
371 libtd.setAttribute("colspan", numStatuses + 2 );
372 libtd.colSpan = numStatuses + 2;
373 addCSSClass(row, 'copy_info_region_row');
376 copyRowParent.appendChild(row);
378 } else { node = globalOrgTree; }
380 for( var c in node.children() )
381 _rdetailRows(node.children()[c]);
384 /* walk through the copy info and build rows where necessary */
385 var localCNFound = false;
386 function _rdetailBuildInfoRows(r) {
390 var summary = r.getResultObject();
393 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
394 G.ui.rdetail.cp_info_loading);
397 for( var i = 0; i < summary.length; i++ ) {
399 var arr = summary[i];
400 globalCNCache[arr[1]] = 1;
401 var thisOrg = findOrgUnit(arr[0]);
402 var rowNode = $("cp_info_" + thisOrg.id());
403 if(!rowNode) continue;
405 if(rowNode.getAttribute("used")) {
407 if( rowNode.nextSibling )
408 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
410 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
411 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
412 n.appendChild(text(thisOrg.name()));
413 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
415 } else rowNode.setAttribute("used", "1");
417 var cpc_temp = rowNode.removeChild(
418 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
420 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
423 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) {
431 rdetailSetPath( thisOrg, isLocal );
432 rdetailBuildBrowseInfo( rowNode, arr[1], isLocal );
434 if( i == summary.length - 1 && !defaultCN) defaultCN = arr[1];
437 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
439 /* now that we know what CN's we have, grab the associated notes */
443 function rdetailFetchNotes() {
444 var req = new Request(FETCH_BIBLIO_NOTES, record.doc_id());
445 req.callback(rdetailDrawNotes);
449 var rdetailNotesTemplate;
450 function rdetailDrawNotes(r) {
451 var notes = r.getResultObject();
454 var tbody = $('rdetail_notes_tbody');
455 if(!rdetailNotesTemplate)
456 rdetailNotesTemplate = tbody.removeChild($('rdetail_notes_row'));
459 for( var t in notes.titles ) {
460 var note = notes.copies[c];
461 /* these need to go into a title notes
462 section different from the copy/cn notes (on the title summary?) */
465 for( var v in notes.volumes ) {
466 var note = notes.copies[c];
467 var row = rdetailNotesTemplate.cloneNode(true);
471 for( var c in notes.copies ) {
473 var copynode = notes.copies[c];
474 var copy = copynode.id;
475 var nts = copynode.notes;
476 for( var n in nts ) {
478 var row = rdetailNotesTemplate.cloneNode(true);
479 $n(row, 'rdetail_notes_title').appendChild(text(note.title()));
480 $n(row, 'rdetail_notes_value').appendChild(text(note.value()));
481 tbody.appendChild(row);
485 if(found) unHideMe($('rdetail_viewnotes_link'));
488 function rdetailBuildBrowseInfo(row, cn, local) {
489 /* used for building the shelf browser */
491 var cache = callnumberCache[cn];
492 if( cache ) cache.count++;
493 else callnumberCache[cn] = { count : 1 };
496 var depth = getDepth();
497 if( !local ) depth = findOrgDepth(globalOrgTree);
498 var a = elem("a", {href:'javascript:rdetailShowCNBrowse("' + cn + '", "'+depth+'");' }, cn);
499 addCSSClass(a, 'classic_link');
500 findNodeByName( row, config.names.rdetail.cn_cell ).appendChild(a);
503 /* sets the path to org as 'active' and displays the
504 path if it's local */
505 function rdetailSetPath(org, local) {
506 if( findOrgDepth(org) == 0 ) return;
507 var row = $("cp_info_" + org.id());
508 row.setAttribute("hasinfo", "1");
511 row.setAttribute("local", "1");
513 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
516 function rdetailApplyStatuses( row, template, statuses ) {
517 for( var j in _statusPositions ) {
518 var stat = _statusPositions[j];
519 var val = statuses[stat.id()];
520 var nn = template.cloneNode(true);
521 if(val) nn.appendChild(text(val));
522 else nn.appendChild(text(0));
528 /* --------------------------------------------------------------------- */
529 var _statusPositions = {};
531 function rdetailBuildStatusColumns() {
533 rdetailGrabCopyStatuses();
534 var parent = statusRow;
535 var template = parent.removeChild(G.ui.rdetail.cp_status);
538 for( i = 0; i < cp_statuses.length; i++ ) {
540 var c = cp_statuses[i];
542 if(c && c.holdable()) {
545 _statusPositions[i] = c;
546 var node = template.cloneNode(true);
547 var data = findNodeByName( node, config.names.rdetail.cp_status);
549 data.appendChild(text(name));
550 parent.appendChild(node);
555 for(x in _statusPositions) numStatuses++;
558 function rdetailGrabCopyStatuses() {
559 if(cp_statuses) return cp_statuses;
560 var req = new Request(FETCH_COPY_STATUSES);
562 cp_statuses = req.result();
563 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
566 function _rdetailSortStatuses(a, b) {
567 return parseInt(a.id()) - parseInt(b.id());