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() {
18 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
19 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
20 statusRow = G.ui.rdetail.cp_status.parentNode;
21 statusRow.id = '__rdsrow';
23 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
24 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
25 G.ui.rdetail.view_marc.onclick = rdetailViewMarc;
26 G.ui.rdetail.hide_marc.onclick = showCanvas;
29 if(getLocation() == globalOrgTree.id())
30 hideMe(G.ui.rdetail.cp_info_all);
34 var req = new Request(FETCH_RMODS, getRid());
35 req.callback(_rdetailDraw);
39 function rdetailViewMarc() {
42 if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
43 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
45 var html = req.result();
46 G.ui.rdetail.view_marc_box.innerHTML = html;
48 swapCanvas(G.ui.rdetail.view_marc_div);
52 function rdetailShowLocalCopies() {
55 var rows = copyRowParent.getElementsByTagName("tr");
56 for( var r in rows ) {
57 if(rows[r].id == "__rdsrow") continue;
59 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
65 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
66 hideMe(G.ui.rdetail.cp_info_local);
67 unHideMe(G.ui.rdetail.cp_info_all);
70 function rdetailShowAllCopies() {
71 var rows = copyRowParent.getElementsByTagName("tr");
73 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
76 hideMe(G.ui.rdetail.cp_info_all);
77 unHideMe(G.ui.rdetail.cp_info_local);
78 hideMe(G.ui.rdetail.cp_info_none);
82 function _rdetailDraw(r) {
83 record = r.getResultObject();
85 G.ui.rdetail.title.appendChild(text(record.title()));
86 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
87 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
88 G.ui.rdetail.edition.appendChild(text(record.edition()));
89 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
90 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
91 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
92 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
93 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
96 $('rdetail_place_hold').setAttribute(
97 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
99 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
100 runEvt("rdetail", "recordDrawn");
101 recordsCache.push(record);
105 function rdetailBuildInfoRows() {
106 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
107 req.callback(_rdetailBuildInfoRows);
111 /* pre-allocate the copy info table with all org units in correct order */
112 function _rdetailRows(node) {
116 var row = copyRow.cloneNode(true);
117 row.id = "cp_info_" + node.id();
119 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
120 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
121 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
123 libtd.appendChild(text(node.name()));
124 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
126 if(!findOrgType(node.ou_type()).can_have_vols()) {
128 row.removeChild(cntd);
129 row.removeChild(cpctd);
131 libtd.setAttribute("colspan", numStatuses + 2 );
132 libtd.colSpan = numStatuses + 2;
133 addCSSClass(row, config.css.color_3);
136 copyRowParent.appendChild(row);
138 } else { node = globalOrgTree; }
140 for( var c in node.children() )
141 _rdetailRows(node.children()[c]);
144 /* walk through the copy info and build rows where necessary */
145 function _rdetailBuildInfoRows(r) {
149 var summary = r.getResultObject();
151 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
152 G.ui.rdetail.cp_info_loading);
155 for( var i = 0; i < summary.length; i++ ) {
157 var arr = summary[i];
158 var thisOrg = findOrgUnit(arr[0]);
159 var rowNode = $("cp_info_" + thisOrg.id());
161 if(rowNode.getAttribute("used")) {
163 if( rowNode.nextSibling )
164 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
166 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
167 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
168 n.appendChild(text(thisOrg.name()));
169 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
171 } else rowNode.setAttribute("used", "1");
173 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
175 var cpc_temp = rowNode.removeChild(
176 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
178 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
181 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
182 rdetailSetPath( thisOrg, isLocal );
186 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
190 /* sets the path to org as 'active' and displays the
191 path if it's local */
192 function rdetailSetPath(org, local) {
193 if( findOrgDepth(org) == 0 ) return;
194 var row = $("cp_info_" + org.id());
195 row.setAttribute("hasinfo", "1");
198 row.setAttribute("local", "1");
200 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
203 function rdetailApplyStatuses( row, template, statuses ) {
204 for( var j in _statusPositions ) {
205 var stat = _statusPositions[j];
206 var val = statuses[stat.id()];
207 var nn = template.cloneNode(true);
208 if(val) nn.appendChild(text(val));
209 else nn.appendChild(text(0));
215 /* --------------------------------------------------------------------- */
216 var _statusPositions = {};
218 function rdetailBuildStatusColumns() {
220 rdetailGrabCopyStatuses();
221 var parent = statusRow;
222 var template = parent.removeChild(G.ui.rdetail.cp_status);
225 for( i = 0; i < cp_statuses.length; i++ ) {
227 var c = cp_statuses[i];
229 if(c && c.holdable()) {
232 _statusPositions[i] = c;
233 var node = template.cloneNode(true);
234 var data = findNodeByName( node, config.names.rdetail.cp_status);
236 data.appendChild(text(name));
237 parent.appendChild(node);
242 for(x in _statusPositions) numStatuses++;
245 function rdetailGrabCopyStatuses() {
246 if(cp_statuses) return cp_statuses;
247 var req = new Request(FETCH_COPY_STATUSES);
249 cp_statuses = req.result();
250 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
253 function _rdetailSortStatuses(a, b) {
254 return parseInt(a.id()) - parseInt(b.id());