]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
e80b179112e091c4c2172bea03a63517b4396ed9
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1 /* */
2
3 attachEvt("common", "run", rdetailDraw);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
5 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
6
7 var record = null;
8 var cp_statuses = null;
9
10 var copyRowParent = null;
11 var copyRow = null;
12 var statusRow = null;
13 var numStatuses = null;
14
15 function rdetailDraw() {
16
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';
21
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);
26         req.send();
27 }
28
29 function rdetailShowLocalCopies() {
30
31         var found = false;
32         var rows = copyRowParent.getElementsByTagName("tr");
33         for( var r in rows ) {
34                 if(rows[r].id == "__rdsrow") continue;
35                 hideMe(rows[r]);
36                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
37                         unHideMe(rows[r]);
38                         found = true;
39                 }
40         }
41
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);
45 }
46
47 function rdetailShowAllCopies() {
48         var rows = copyRowParent.getElementsByTagName("tr");
49         for( var r in rows ) 
50                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
51                         unHideMe(rows[r]);
52
53         hideMe(G.ui.rdetail.cp_info_all);
54         unHideMe(G.ui.rdetail.cp_info_local);
55         hideMe(G.ui.rdetail.cp_info_none);
56 }
57
58
59 function _rdetailDraw(r) {
60         record = r.getResultObject();
61
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()));
70
71         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
72         runEvt("rdetail", "recordDrawn");
73 }
74
75
76 function rdetailBuildInfoRows() {
77         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
78         req.callback(_rdetailBuildInfoRows);
79         req.send();
80 }
81
82 /* pre-allocate the copy info table with all org units in correct order */
83 function _rdetailRows(node) {
84
85         if(node) {
86
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 );
92         
93                 libtd.appendChild(text(node.name()));
94                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
95         
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);
102                 } 
103         
104                 copyRowParent.appendChild(row);
105
106         } else { node = globalOrgTree; }
107
108         for( var c in node.children() ) 
109                 _rdetailRows(node.children()[c]);
110 }
111
112 /* walk through the copy info and build rows where necessary */
113 function _rdetailBuildInfoRows(r) {
114
115         _rdetailRows();
116
117         var summary = r.getResultObject();
118
119         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
120                 G.ui.rdetail.cp_info_loading);
121
122         for( var i = 0; i < summary.length; i++ ) {
123
124                 var arr = summary[i];
125                 var thisOrg = findOrgUnit(arr[0]);
126                 var rowNode = getId("cp_info_" + thisOrg.id());
127
128                 if(rowNode.getAttribute("used")) {
129
130                         if( rowNode.nextSibling )
131                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
132                         else
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;");
137
138                 } else rowNode.setAttribute("used", "1");
139
140                 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
141
142                 var cpc_temp = rowNode.removeChild(
143                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
144
145                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
146
147                 var isLocal = false;
148                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) isLocal = true;
149                 rdetailSetPath( thisOrg, isLocal );
150
151         }
152
153 }
154
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");
161         if(local) {
162                 unHideMe(row);
163                 row.setAttribute("local", "1");
164         }
165         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
166 }
167
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));
175                 row.appendChild(nn);    
176         }
177 }
178
179
180 /* --------------------------------------------------------------------- */
181 var _statusPositions = {};
182
183 function rdetailBuildStatusColumns() {
184
185         rdetailGrabCopyStatuses();
186         var parent = statusRow;
187         var template = parent.removeChild(G.ui.rdetail.cp_status);
188
189         var i = 0;
190         for( i = 0; i < cp_statuses.length; i++ ) {
191
192                 var c = cp_statuses[i];
193
194                 if(c && c.holdable()) {
195
196                         var name = c.name();
197                         _statusPositions[i] = c;
198                         var node = template.cloneNode(true);
199                         var data = findNodeByName( node, config.names.rdetail.cp_status);
200
201                         data.appendChild(text(name));
202                         
203 /*
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"));
208                         }       
209 */
210                         parent.appendChild(node);
211                 }       
212         }       
213
214         numStatuses = 0;
215         for(x in _statusPositions) numStatuses++; 
216 }
217
218 function rdetailGrabCopyStatuses() {
219         if(cp_statuses) return cp_statuses;
220    var req = new Request(FETCH_COPY_STATUSES);
221    req.send(true);
222         cp_statuses = req.result();
223         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
224 }
225
226 function _rdetailSortStatuses(a, b) {
227         return parseInt(a.id()) - parseInt(b.id());
228 }
229
230