2 attachEvt("common", "run", rdetailDraw);
3 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
7 var cp_statuses = null;
9 var copyRowParent = null;
13 function rdetailDraw() {
15 copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
16 copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
17 statusRow = G.ui.rdetail.cp_status.parentNode;
18 statusRow.id = '__rdsrow';
20 G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
21 G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
22 var req = new Request(FETCH_RMODS, getRid());
23 req.callback(_rdetailDraw);
27 function rdetailShowLocalCopies() {
30 var rows = copyRowParent.getElementsByTagName("tr");
31 for( var r in rows ) {
32 if(rows[r].id == "__rdsrow") continue;
34 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
40 if(!found) unHideMe(G.ui.rdetail.cp_info_none);
41 hideMe(G.ui.rdetail.cp_info_local);
42 unHideMe(G.ui.rdetail.cp_info_all);
45 function rdetailShowAllCopies() {
46 var rows = copyRowParent.getElementsByTagName("tr");
48 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
51 hideMe(G.ui.rdetail.cp_info_all);
52 unHideMe(G.ui.rdetail.cp_info_local);
53 hideMe(G.ui.rdetail.cp_info_none);
57 function _rdetailDraw(r) {
58 record = r.getResultObject();
60 G.ui.rdetail.title.appendChild(text(record.title()));
61 G.ui.rdetail.author.appendChild(text(record.author()));
62 G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
63 G.ui.rdetail.edition.appendChild(text(record.edition()));
64 G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
65 G.ui.rdetail.publisher.appendChild(text(record.publisher()));
66 G.ui.rdetail.tor.appendChild(text(record.types_of_resource()));
67 G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
69 G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
70 runEvt("rdetail", "recordDrawn");
75 function rdetailBuildInfoRows() {
76 var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
77 req.callback(_rdetailBuildInfoRows);
81 /* pre-allocate the copy info table with all org units */
82 function _rdetailRows(node) {
86 var row = copyRow.cloneNode(true);
87 row.id = "cp_info_" + node.id();
88 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
89 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
90 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
92 libtd.appendChild(text(node.name()));
93 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1) * 9) + "px;");
95 if(!findOrgType(node.ou_type()).can_have_vols()) {
97 for(x in _statusPositions) c++;
98 libtd.setAttribute("colspan", c );
100 row.removeChild(cntd);
101 row.removeChild(cpctd);
102 addCSSClass(row, config.css.color_3);
105 copyRowParent.appendChild(row);
107 } else { node = globalOrgTree; }
109 for( var c in node.children() )
110 _rdetailRows(node.children()[c]);
113 /* walk through the copy info and build rows where necessary */
114 function _rdetailBuildInfoRows(r) {
118 var summary = r.getResultObject();
119 var curLoc = getLocation();
121 /* remove the 'now loading' thingy */
122 G.ui.rdetail.cp_info_loading.parentNode.removeChild(
123 G.ui.rdetail.cp_info_loading);
125 var curLoc = getLocation();
127 for( var i = 0; i < summary.length; i++ ) {
129 var arr = summary[i];
130 var rowNode = copyRow.cloneNode(true);
131 var rowNode = getId("cp_info_" + arr[0]);
134 if(rowNode.getAttribute("used")) {
136 if( rowNode.nextSibling )
137 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
139 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
140 var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
141 n.appendChild(text(findOrgUnit(arr[0]).name()));
142 n.setAttribute("style", "padding-left: " + ((findOrgDepth(arr[0]) - 1) * 9) + "px;");
145 rowNode.setAttribute("used", "1");
148 rowNode.setAttribute("hasinfo", "1");
149 var p = getId("cp_info_" + findOrgUnit(arr[0]).parent_ou());
150 if(p) p.setAttribute("hasinfo", "1");
152 if( orgIsMine( findOrgUnit(curLoc), findOrgUnit(arr[0]) ) ) {
154 unHideMe(getId("cp_info_" + findOrgUnit(arr[0]).parent_ou()));
155 rowNode.setAttribute("local", "1");
158 var cntd = findNodeByName( rowNode, config.names.rdetail.cn_cell );
159 cntd.appendChild(text(arr[1]));
160 var cpc_temp = rowNode.removeChild(findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
162 for( var j in _statusPositions ) {
163 var stat = _statusPositions[j];
164 var val = arr[2][stat.id()];
165 var nn = cpc_temp.cloneNode(true);
166 if(val) nn.appendChild(text(val));
167 else nn.appendChild(text(0));
168 rowNode.appendChild(nn);
173 /* unhide the path to me */
174 var nodeTrail = orgNodeTrail(findOrgUnit(curLoc));
175 for( var i = 0; i != nodeTrail.length; i++ ) {
176 var n = getId("cp_info_" + nodeTrail[i].id());
179 n.setAttribute("local", "1");
186 /* --------------------------------------------------------------------- */
187 var _statusPositions = {};
189 function rdetailBuildStatusColumns() {
191 rdetailGrabCopyStatuses();
192 var parent = statusRow;
193 var template = parent.removeChild(G.ui.rdetail.cp_status);
196 for( i = 0; i < cp_statuses.length; i++ ) {
197 var c = cp_statuses[i];
198 if(c && c.holdable()) {
199 _statusPositions[i] = c;
200 var node = template.cloneNode(true);
201 node.appendChild(text("#" + c.name()));
202 parent.appendChild(node);
207 function rdetailGrabCopyStatuses() {
208 if(cp_statuses) return cp_statuses;
209 var req = new Request(FETCH_COPY_STATUSES);
211 cp_statuses = req.result();
212 cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
215 function _rdetailSortStatuses(a, b) {
216 return parseInt(a.id()) - parseInt(b.id());