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;
26 var req = new Request(FETCH_RMODS, getRid());
27 req.callback(_rdetailDraw);
31 function rdetailViewMarc() {
34 if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
35 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
37 var html = req.result();
38 G.ui.rdetail.view_marc_box.innerHTML = html;
40 swapCanvas(G.ui.rdetail.view_marc_div);
44 function rdetailShowLocalCopies() {
47 var rows = copyRowParent.getElementsByTagName("tr");
48 for( var r in rows ) {
49 if(rows[r].id == "__rdsrow") continue;
51 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
57 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
58 hideMe(G.ui.rdetail.cp_info_local);
59 unHideMe(G.ui.rdetail.cp_info_all);
62 function rdetailShowAllCopies() {
63 var rows = copyRowParent.getElementsByTagName("tr");
65 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
68 hideMe(G.ui.rdetail.cp_info_all);
69 unHideMe(G.ui.rdetail.cp_info_local);
70 hideMe(G.ui.rdetail.cp_info_none);
74 function _rdetailDraw(r) {
75 record = r.getResultObject();
77 G.ui.rdetail.title.appendChild(text(record.title()));
78 buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
79 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
80 G.ui.rdetail.edition.appendChild(text(record.edition()));
81 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
82 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
83 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
84 setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
85 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
89 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
90 runEvt("rdetail", "recordDrawn");
94 function rdetailBuildInfoRows() {
95 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
96 req.callback(_rdetailBuildInfoRows);
100 /* pre-allocate the copy info table with all org units in correct order */
101 function _rdetailRows(node) {
105 var row = copyRow.cloneNode(true);
106 row.id = "cp_info_" + node.id();
108 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
109 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
110 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
112 libtd.appendChild(text(node.name()));
113 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
115 if(!findOrgType(node.ou_type()).can_have_vols()) {
117 row.removeChild(cntd);
118 row.removeChild(cpctd);
120 libtd.setAttribute("colspan", numStatuses + 2 );
121 libtd.colSpan = numStatuses + 2;
122 addCSSClass(row, config.css.color_3);
125 copyRowParent.appendChild(row);
127 } else { node = globalOrgTree; }
129 for( var c in node.children() )
130 _rdetailRows(node.children()[c]);
133 /* walk through the copy info and build rows where necessary */
134 function _rdetailBuildInfoRows(r) {
138 var summary = r.getResultObject();
140 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
141 G.ui.rdetail.cp_info_loading);
143 for( var i = 0; i < summary.length; i++ ) {
145 var arr = summary[i];
146 var thisOrg = findOrgUnit(arr[0]);
147 var rowNode = getId("cp_info_" + thisOrg.id());
149 if(rowNode.getAttribute("used")) {
151 if( rowNode.nextSibling )
152 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
154 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
155 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
156 n.appendChild(text(thisOrg.name()));
157 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
159 } else rowNode.setAttribute("used", "1");
161 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
163 var cpc_temp = rowNode.removeChild(
164 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
166 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
169 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) isLocal = true;
170 rdetailSetPath( thisOrg, isLocal );
176 /* sets the path to org as 'active' and displays the
177 path if it's local */
178 function rdetailSetPath(org, local) {
179 if( findOrgDepth(org) == 0 ) return;
180 var row = getId("cp_info_" + org.id());
181 row.setAttribute("hasinfo", "1");
184 row.setAttribute("local", "1");
186 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
189 function rdetailApplyStatuses( row, template, statuses ) {
190 for( var j in _statusPositions ) {
191 var stat = _statusPositions[j];
192 var val = statuses[stat.id()];
193 var nn = template.cloneNode(true);
194 if(val) nn.appendChild(text(val));
195 else nn.appendChild(text(0));
201 /* --------------------------------------------------------------------- */
202 var _statusPositions = {};
204 function rdetailBuildStatusColumns() {
206 rdetailGrabCopyStatuses();
207 var parent = statusRow;
208 var template = parent.removeChild(G.ui.rdetail.cp_status);
211 for( i = 0; i < cp_statuses.length; i++ ) {
213 var c = cp_statuses[i];
215 if(c && c.holdable()) {
218 _statusPositions[i] = c;
219 var node = template.cloneNode(true);
220 var data = findNodeByName( node, config.names.rdetail.cp_status);
222 data.appendChild(text(name));
223 parent.appendChild(node);
228 for(x in _statusPositions) numStatuses++;
231 function rdetailGrabCopyStatuses() {
232 if(cp_statuses) return cp_statuses;
233 var req = new Request(FETCH_COPY_STATUSES);
235 cp_statuses = req.result();
236 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
239 function _rdetailSortStatuses(a, b) {
240 return parseInt(a.id()) - parseInt(b.id());