]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
d9f19cc2b1c184fdb837e6ebe9a7702e6cc5272b
[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         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);
28         req.send();
29 }
30
31 function rdetailViewMarc() {
32         if(!record) return;
33
34         if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
35                 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
36                 req.send(true);
37                 var html = req.result();
38                 G.ui.rdetail.view_marc_box.innerHTML = html;
39         }
40         swapCanvas(G.ui.rdetail.view_marc_div);
41 }
42
43
44 function rdetailShowLocalCopies() {
45
46         var found = false;
47         var rows = copyRowParent.getElementsByTagName("tr");
48         for( var r in rows ) {
49                 if(rows[r].id == "__rdsrow") continue;
50                 hideMe(rows[r]);
51                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
52                         unHideMe(rows[r]);
53                         found = true;
54                 }
55         }
56
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);
60 }
61
62 function rdetailShowAllCopies() {
63         var rows = copyRowParent.getElementsByTagName("tr");
64         for( var r in rows ) 
65                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
66                         unHideMe(rows[r]);
67
68         hideMe(G.ui.rdetail.cp_info_all);
69         unHideMe(G.ui.rdetail.cp_info_local);
70         hideMe(G.ui.rdetail.cp_info_none);
71 }
72
73
74 function _rdetailDraw(r) {
75         record = r.getResultObject();
76
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()));
86
87         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
88         runEvt("rdetail", "recordDrawn");
89 }
90
91
92 function rdetailBuildInfoRows() {
93         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
94         req.callback(_rdetailBuildInfoRows);
95         req.send();
96 }
97
98 /* pre-allocate the copy info table with all org units in correct order */
99 function _rdetailRows(node) {
100
101         if(node) {
102
103                 var row = copyRow.cloneNode(true);
104                 row.id = "cp_info_" + node.id();
105
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 );
109         
110                 libtd.appendChild(text(node.name()));
111                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
112         
113                 if(!findOrgType(node.ou_type()).can_have_vols()) {
114
115                         row.removeChild(cntd);
116                         row.removeChild(cpctd);
117
118                         libtd.setAttribute("colspan", numStatuses + 2 );
119                         libtd.colSpan = numStatuses + 2;
120                         addCSSClass(row, config.css.color_3);
121                 } 
122         
123                 copyRowParent.appendChild(row);
124
125         } else { node = globalOrgTree; }
126
127         for( var c in node.children() ) 
128                 _rdetailRows(node.children()[c]);
129 }
130
131 /* walk through the copy info and build rows where necessary */
132 function _rdetailBuildInfoRows(r) {
133
134         _rdetailRows();
135
136         var summary = r.getResultObject();
137
138         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
139                 G.ui.rdetail.cp_info_loading);
140
141         for( var i = 0; i < summary.length; i++ ) {
142
143                 var arr = summary[i];
144                 var thisOrg = findOrgUnit(arr[0]);
145                 var rowNode = getId("cp_info_" + thisOrg.id());
146
147                 if(rowNode.getAttribute("used")) {
148
149                         if( rowNode.nextSibling )
150                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
151                         else
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;");
156
157                 } else rowNode.setAttribute("used", "1");
158
159                 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
160
161                 var cpc_temp = rowNode.removeChild(
162                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
163
164                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
165
166                 var isLocal = false;
167                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) isLocal = true;
168                 rdetailSetPath( thisOrg, isLocal );
169
170         }
171
172 }
173
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");
180         if(local) {
181                 unHideMe(row);
182                 row.setAttribute("local", "1");
183         }
184         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
185 }
186
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));
194                 row.appendChild(nn);    
195         }
196 }
197
198
199 /* --------------------------------------------------------------------- */
200 var _statusPositions = {};
201
202 function rdetailBuildStatusColumns() {
203
204         rdetailGrabCopyStatuses();
205         var parent = statusRow;
206         var template = parent.removeChild(G.ui.rdetail.cp_status);
207
208         var i = 0;
209         for( i = 0; i < cp_statuses.length; i++ ) {
210
211                 var c = cp_statuses[i];
212
213                 if(c && c.holdable()) {
214
215                         var name = c.name();
216                         _statusPositions[i] = c;
217                         var node = template.cloneNode(true);
218                         var data = findNodeByName( node, config.names.rdetail.cp_status);
219
220                         data.appendChild(text(name));
221                         
222 /*
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"));
227                         }       
228 */
229                         parent.appendChild(node);
230                 }       
231         }       
232
233         numStatuses = 0;
234         for(x in _statusPositions) numStatuses++; 
235 }
236
237 function rdetailGrabCopyStatuses() {
238         if(cp_statuses) return cp_statuses;
239    var req = new Request(FETCH_COPY_STATUSES);
240    req.send(true);
241         cp_statuses = req.result();
242         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
243 }
244
245 function _rdetailSortStatuses(a, b) {
246         return parseInt(a.id()) - parseInt(b.id());
247 }
248
249