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 G.ui.rdetail.author.appendChild(text(record.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()));
87 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
88 runEvt("rdetail", "recordDrawn");
92 function rdetailBuildInfoRows() {
93 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
94 req.callback(_rdetailBuildInfoRows);
98 /* pre-allocate the copy info table with all org units in correct order */
99 function _rdetailRows(node) {
103 var row = copyRow.cloneNode(true);
104 row.id = "cp_info_" + node.id();
106 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
107 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
108 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
110 libtd.appendChild(text(node.name()));
111 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
113 if(!findOrgType(node.ou_type()).can_have_vols()) {
115 row.removeChild(cntd);
116 row.removeChild(cpctd);
118 libtd.setAttribute("colspan", numStatuses + 2 );
119 libtd.colSpan = numStatuses + 2;
120 addCSSClass(row, config.css.color_3);
123 copyRowParent.appendChild(row);
125 } else { node = globalOrgTree; }
127 for( var c in node.children() )
128 _rdetailRows(node.children()[c]);
131 /* walk through the copy info and build rows where necessary */
132 function _rdetailBuildInfoRows(r) {
136 var summary = r.getResultObject();
138 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
139 G.ui.rdetail.cp_info_loading);
141 for( var i = 0; i < summary.length; i++ ) {
143 var arr = summary[i];
144 var thisOrg = findOrgUnit(arr[0]);
145 var rowNode = getId("cp_info_" + thisOrg.id());
147 if(rowNode.getAttribute("used")) {
149 if( rowNode.nextSibling )
150 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
152 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
153 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
154 n.appendChild(text(thisOrg.name()));
155 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
157 } else rowNode.setAttribute("used", "1");
159 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
161 var cpc_temp = rowNode.removeChild(
162 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
164 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
167 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) isLocal = true;
168 rdetailSetPath( thisOrg, isLocal );
174 /* sets the path to org as 'active' and displays the
175 path if it's local */
176 function rdetailSetPath(org, local) {
177 if( findOrgDepth(org) == 0 ) return;
178 var row = getId("cp_info_" + org.id());
179 row.setAttribute("hasinfo", "1");
182 row.setAttribute("local", "1");
184 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
187 function rdetailApplyStatuses( row, template, statuses ) {
188 for( var j in _statusPositions ) {
189 var stat = _statusPositions[j];
190 var val = statuses[stat.id()];
191 var nn = template.cloneNode(true);
192 if(val) nn.appendChild(text(val));
193 else nn.appendChild(text(0));
199 /* --------------------------------------------------------------------- */
200 var _statusPositions = {};
202 function rdetailBuildStatusColumns() {
204 rdetailGrabCopyStatuses();
205 var parent = statusRow;
206 var template = parent.removeChild(G.ui.rdetail.cp_status);
209 for( i = 0; i < cp_statuses.length; i++ ) {
211 var c = cp_statuses[i];
213 if(c && c.holdable()) {
216 _statusPositions[i] = c;
217 var node = template.cloneNode(true);
218 var data = findNodeByName( node, config.names.rdetail.cp_status);
220 data.appendChild(text(name));
223 for( var x = 0; x < name.length; x++ ) {
224 var c = name.charAt(x);
225 data.appendChild(text(c));
226 data.appendChild(document.createElement("br"));
229 parent.appendChild(node);
234 for(x in _statusPositions) numStatuses++;
237 function rdetailGrabCopyStatuses() {
238 if(cp_statuses) return cp_statuses;
239 var req = new Request(FETCH_COPY_STATUSES);
241 cp_statuses = req.result();
242 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
245 function _rdetailSortStatuses(a, b) {
246 return parseInt(a.id()) - parseInt(b.id());