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 var req = new Request(FETCH_RMODS, getRid());
25 req.callback(_rdetailDraw);
29 function rdetailShowLocalCopies() {
32 var rows = copyRowParent.getElementsByTagName("tr");
33 for( var r in rows ) {
34 if(rows[r].id == "__rdsrow") continue;
36 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
42 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
43 hideMe(G.ui.rdetail.cp_info_local);
44 unHideMe(G.ui.rdetail.cp_info_all);
47 function rdetailShowAllCopies() {
48 var rows = copyRowParent.getElementsByTagName("tr");
50 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
53 hideMe(G.ui.rdetail.cp_info_all);
54 unHideMe(G.ui.rdetail.cp_info_local);
55 hideMe(G.ui.rdetail.cp_info_none);
59 function _rdetailDraw(r) {
60 record = r.getResultObject();
62 G.ui.rdetail.title.appendChild(text(record.title()));
63 G.ui.rdetail.author.appendChild(text(record.author()));
64 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
65 G.ui.rdetail.edition.appendChild(text(record.edition()));
66 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
67 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
68 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()));
69 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
71 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
72 runEvt("rdetail", "recordDrawn");
76 function rdetailBuildInfoRows() {
77 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
78 req.callback(_rdetailBuildInfoRows);
82 /* pre-allocate the copy info table with all org units in correct order */
83 function _rdetailRows(node) {
87 var row = copyRow.cloneNode(true);
88 row.id = "cp_info_" + node.id();
89 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
90 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
91 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
93 libtd.appendChild(text(node.name()));
94 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
96 if(!findOrgType(node.ou_type()).can_have_vols()) {
97 libtd.setAttribute("colspan", numStatuses + 2 );
98 libtd.colSpan = numStatuses + 2;
99 row.removeChild(cntd);
100 row.removeChild(cpctd);
101 addCSSClass(row, config.css.color_3);
104 copyRowParent.appendChild(row);
106 } else { node = globalOrgTree; }
108 for( var c in node.children() )
109 _rdetailRows(node.children()[c]);
112 /* walk through the copy info and build rows where necessary */
113 function _rdetailBuildInfoRows(r) {
117 var summary = r.getResultObject();
119 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
120 G.ui.rdetail.cp_info_loading);
122 for( var i = 0; i < summary.length; i++ ) {
124 var arr = summary[i];
125 var thisOrg = findOrgUnit(arr[0]);
126 var rowNode = getId("cp_info_" + thisOrg.id());
128 if(rowNode.getAttribute("used")) {
130 if( rowNode.nextSibling )
131 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
133 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
134 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
135 n.appendChild(text(thisOrg.name()));
136 n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1) * 9) + "px;");
138 } else rowNode.setAttribute("used", "1");
140 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
142 var cpc_temp = rowNode.removeChild(
143 findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
145 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
148 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) isLocal = true;
149 rdetailSetPath( thisOrg, isLocal );
155 /* sets the path to org as 'active' and displays the
156 path if it's local */
157 function rdetailSetPath(org, local) {
158 if( findOrgDepth(org) == 0 ) return;
159 var row = getId("cp_info_" + org.id());
160 row.setAttribute("hasinfo", "1");
163 row.setAttribute("local", "1");
165 rdetailSetPath(findOrgUnit(org.parent_ou()), local);
168 function rdetailApplyStatuses( row, template, statuses ) {
169 for( var j in _statusPositions ) {
170 var stat = _statusPositions[j];
171 var val = statuses[stat.id()];
172 var nn = template.cloneNode(true);
173 if(val) nn.appendChild(text(val));
174 else nn.appendChild(text(0));
180 /* --------------------------------------------------------------------- */
181 var _statusPositions = {};
183 function rdetailBuildStatusColumns() {
185 rdetailGrabCopyStatuses();
186 var parent = statusRow;
187 var template = parent.removeChild(G.ui.rdetail.cp_status);
190 for( i = 0; i < cp_statuses.length; i++ ) {
192 var c = cp_statuses[i];
194 if(c && c.holdable()) {
197 _statusPositions[i] = c;
198 var node = template.cloneNode(true);
199 var data = findNodeByName( node, config.names.rdetail.cp_status);
201 data.appendChild(text(name));
204 for( var x = 0; x < name.length; x++ ) {
205 var c = name.charAt(x);
206 data.appendChild(text(c));
207 data.appendChild(document.createElement("br"));
210 parent.appendChild(node);
215 for(x in _statusPositions) numStatuses++;
218 function rdetailGrabCopyStatuses() {
219 if(cp_statuses) return cp_statuses;
220 var req = new Request(FETCH_COPY_STATUSES);
222 cp_statuses = req.result();
223 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
226 function _rdetailSortStatuses(a, b) {
227 return parseInt(a.id()) - parseInt(b.id());