]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
97ab3aa15dc312f7c63d882f95c16eefb5afc688
[working/Evergreen.git] / Open-ILS / web / opac / skin / default / js / rdetail.js
1 /* */
2 attachEvt("common", "run", rdetailDraw);
3 attachEvt("rdetail", "recordDrawn", rdetailBuildStatusColumns);
4 attachEvt("rdetail", "recordDrawn", rdetailBuildInfoRows);
5
6 var record = null;
7 var cp_statuses = null;
8
9 var copyRowParent = null;
10 var copyRow = null;
11 var statusRow = null;
12
13 function rdetailDraw() {
14
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';
19
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);
24         req.send();
25 }
26
27 function rdetailShowLocalCopies() {
28
29         var found = false;
30         var rows = copyRowParent.getElementsByTagName("tr");
31         for( var r in rows ) {
32                 if(rows[r].id == "__rdsrow") continue;
33                 hideMe(rows[r]);
34                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
35                         unHideMe(rows[r]);
36                         found = true;
37                 }
38         }
39
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);
43 }
44
45 function rdetailShowAllCopies() {
46         var rows = copyRowParent.getElementsByTagName("tr");
47         for( var r in rows ) 
48                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
49                         unHideMe(rows[r]);
50
51         hideMe(G.ui.rdetail.cp_info_all);
52         unHideMe(G.ui.rdetail.cp_info_local);
53         hideMe(G.ui.rdetail.cp_info_none);
54 }
55
56
57 function _rdetailDraw(r) {
58         record = r.getResultObject();
59
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()));
68
69         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
70         runEvt("rdetail", "recordDrawn");
71 }
72
73
74
75 function rdetailBuildInfoRows() {
76         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
77         req.callback(_rdetailBuildInfoRows);
78         req.send();
79 }
80
81 /* pre-allocate the copy info table with all org units */
82 function _rdetailRows(node) {
83
84         if(node) {
85
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 );
91         
92                 libtd.appendChild(text(node.name()));
93                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
94         
95                 if(!findOrgType(node.ou_type()).can_have_vols()) {
96                         var c = 2;
97                         for(x in _statusPositions) c++;
98                         libtd.setAttribute("colspan", c );
99                         libtd.colSpan = c;
100                         row.removeChild(cntd);
101                         row.removeChild(cpctd);
102                         addCSSClass(row, config.css.color_3);
103                 } 
104         
105                 copyRowParent.appendChild(row);
106
107         } else { node = globalOrgTree; }
108
109         for( var c in node.children() ) 
110                 _rdetailRows(node.children()[c]);
111 }
112
113 /* walk through the copy info and build rows where necessary */
114 function _rdetailBuildInfoRows(r) {
115
116         _rdetailRows();
117
118         var summary = r.getResultObject();
119         var curLoc = getLocation();
120
121         /* remove the 'now loading' thingy */
122         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
123                 G.ui.rdetail.cp_info_loading);
124
125         var curLoc = getLocation();
126
127         for( var i = 0; i < summary.length; i++ ) {
128
129                 var arr = summary[i];
130                 var rowNode = copyRow.cloneNode(true);
131                 var rowNode = getId("cp_info_" + arr[0]);
132
133
134                 if(rowNode.getAttribute("used")) {
135
136                         if( rowNode.nextSibling )
137                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
138                         else
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;");
143
144                 } else {
145                         rowNode.setAttribute("used", "1");
146                 }
147
148                 rowNode.setAttribute("hasinfo", "1");
149                 var p = getId("cp_info_" + findOrgUnit(arr[0]).parent_ou());
150                 if(p) p.setAttribute("hasinfo", "1");
151
152                 if( orgIsMine( findOrgUnit(curLoc), findOrgUnit(arr[0]) ) ) {
153                         unHideMe(rowNode);
154                         unHideMe(getId("cp_info_" + findOrgUnit(arr[0]).parent_ou()));
155                         rowNode.setAttribute("local", "1");
156                 }
157
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));
161
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);        
169                 }
170
171         }
172
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());
177                 if(n) {
178                         unHideMe(n);
179                         n.setAttribute("local", "1");
180                 }
181         }
182 }
183
184
185
186 /* --------------------------------------------------------------------- */
187 var _statusPositions = {};
188
189 function rdetailBuildStatusColumns() {
190
191         rdetailGrabCopyStatuses();
192         var parent = statusRow;
193         var template = parent.removeChild(G.ui.rdetail.cp_status);
194
195         var i = 0;
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);
203                 }       
204         }       
205 }
206
207 function rdetailGrabCopyStatuses() {
208         if(cp_statuses) return cp_statuses;
209    var req = new Request(FETCH_COPY_STATUSES);
210    req.send(true);
211         cp_statuses = req.result();
212         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
213 }
214
215 function _rdetailSortStatuses(a, b) {
216         return parseInt(a.id()) - parseInt(b.id());
217 }
218
219