3 attachEvt("common", "run", rdetailDraw);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
5 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
8 var cp_statuses = null;
10 var copyRowParent = null;
13 var numStatuses = null;
15 function rdetailDraw() {
17 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
18 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
19 statusRow = G.ui.rdetail.cp_status.parentNode;
20 statusRow.id = '__rdsrow';
22 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
23 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
24 G.ui.rdetail.view_marc.onclick = rdetailViewMarc;
25 G.ui.rdetail.hide_marc.onclick = showCanvas;
28 if(getLocation() == globalOrgTree.id())
29 hideMe(G.ui.rdetail.cp_info_all);
31 var req = new Request(FETCH_RMODS, getRid());
32 req.callback(_rdetailDraw);
36 function rdetailViewMarc() {
39 if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
40 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
42 var html = req.result();
43 G.ui.rdetail.view_marc_box.innerHTML = html;
45 swapCanvas(G.ui.rdetail.view_marc_div);
49 function rdetailShowLocalCopies() {
52 var rows = copyRowParent.getElementsByTagName("tr");
53 for( var r in rows ) {
54 if(rows[r].id == "__rdsrow") continue;
56 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
62 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
63 hideMe(G.ui.rdetail.cp_info_local);
64 unHideMe(G.ui.rdetail.cp_info_all);
67 function rdetailShowAllCopies() {
68 var rows = copyRowParent.getElementsByTagName("tr");
70 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
73 hideMe(G.ui.rdetail.cp_info_all);
74 unHideMe(G.ui.rdetail.cp_info_local);
75 hideMe(G.ui.rdetail.cp_info_none);
79 function _rdetailDraw(r) {
80 record = r.getResultObject();
82 G.ui.rdetail.title.appendChild(text(record.title()));
83 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
84 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
85 G.ui.rdetail.edition.appendChild(text(record.edition()));
86 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
87 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
88 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
89 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
90 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
94 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
95 runEvt("rdetail", "recordDrawn");
99 function rdetailBuildInfoRows() {
100 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
101 req.callback(_rdetailBuildInfoRows);
105 /* pre-allocate the copy info table with all org units in correct order */
106 function _rdetailRows(node) {
110 var row = copyRow.cloneNode(true);
111 row.id = "cp_info_" + node.id();
113 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
114 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
115 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
117 libtd.appendChild(text(node.name()));
118 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
120 if(!findOrgType(node.ou_type()).can_have_vols()) {
122 row.removeChild(cntd);
123 row.removeChild(cpctd);
125 libtd.setAttribute("colspan", numStatuses + 2 );
126 libtd.colSpan = numStatuses + 2;
127 addCSSClass(row, config.css.color_3);
130 copyRowParent.appendChild(row);
132 } else { node = globalOrgTree; }
134 for( var c in node.children() )
135 _rdetailRows(node.children()[c]);
138 /* walk through the copy info and build rows where necessary */
139 function _rdetailBuildInfoRows(r) {
143 var summary = r.getResultObject();
145 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
146 G.ui.rdetail.cp_info_loading);
149 for( var i = 0; i < summary.length; i++ ) {
151 var arr = summary[i];
152 var thisOrg = findOrgUnit(arr[0]);
153 var rowNode = $("cp_info_" + thisOrg.id());
155 if(rowNode.getAttribute("used")) {
157 if( rowNode.nextSibling )
158 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
160 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
161 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
162 n.appendChild(text(thisOrg.name()));
163 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
165 } else rowNode.setAttribute("used", "1");
167 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
169 var cpc_temp = rowNode.removeChild(
170 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
172 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
175 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
176 rdetailSetPath( thisOrg, isLocal );
180 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
184 /* sets the path to org as 'active' and displays the
185 path if it's local */
186 function rdetailSetPath(org, local) {
187 if( findOrgDepth(org) == 0 ) return;
188 var row = $("cp_info_" + org.id());
189 row.setAttribute("hasinfo", "1");
192 row.setAttribute("local", "1");
194 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
197 function rdetailApplyStatuses( row, template, statuses ) {
198 for( var j in _statusPositions ) {
199 var stat = _statusPositions[j];
200 var val = statuses[stat.id()];
201 var nn = template.cloneNode(true);
202 if(val) nn.appendChild(text(val));
203 else nn.appendChild(text(0));
209 /* --------------------------------------------------------------------- */
210 var _statusPositions = {};
212 function rdetailBuildStatusColumns() {
214 rdetailGrabCopyStatuses();
215 var parent = statusRow;
216 var template = parent.removeChild(G.ui.rdetail.cp_status);
219 for( i = 0; i < cp_statuses.length; i++ ) {
221 var c = cp_statuses[i];
223 if(c && c.holdable()) {
226 _statusPositions[i] = c;
227 var node = template.cloneNode(true);
228 var data = findNodeByName( node, config.names.rdetail.cp_status);
230 data.appendChild(text(name));
231 parent.appendChild(node);
236 for(x in _statusPositions) numStatuses++;
239 function rdetailGrabCopyStatuses() {
240 if(cp_statuses) return cp_statuses;
241 var req = new Request(FETCH_COPY_STATUSES);
243 cp_statuses = req.result();
244 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
247 function _rdetailSortStatuses(a, b) {
248 return parseInt(a.id()) - parseInt(b.id());