]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
numerous small style changes
[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         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.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
88
89         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
90         runEvt("rdetail", "recordDrawn");
91 }
92
93
94 function rdetailBuildInfoRows() {
95         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
96         req.callback(_rdetailBuildInfoRows);
97         req.send();
98 }
99
100 /* pre-allocate the copy info table with all org units in correct order */
101 function _rdetailRows(node) {
102
103         if(node) {
104
105                 var row = copyRow.cloneNode(true);
106                 row.id = "cp_info_" + node.id();
107
108                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
109                 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
110                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
111         
112                 libtd.appendChild(text(node.name()));
113                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
114         
115                 if(!findOrgType(node.ou_type()).can_have_vols()) {
116
117                         row.removeChild(cntd);
118                         row.removeChild(cpctd);
119
120                         libtd.setAttribute("colspan", numStatuses + 2 );
121                         libtd.colSpan = numStatuses + 2;
122                         addCSSClass(row, config.css.color_3);
123                 } 
124         
125                 copyRowParent.appendChild(row);
126
127         } else { node = globalOrgTree; }
128
129         for( var c in node.children() ) 
130                 _rdetailRows(node.children()[c]);
131 }
132
133 /* walk through the copy info and build rows where necessary */
134 function _rdetailBuildInfoRows(r) {
135
136         _rdetailRows();
137
138         var summary = r.getResultObject();
139
140         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
141                 G.ui.rdetail.cp_info_loading);
142
143         for( var i = 0; i < summary.length; i++ ) {
144
145                 var arr = summary[i];
146                 var thisOrg = findOrgUnit(arr[0]);
147                 var rowNode = getId("cp_info_" + thisOrg.id());
148
149                 if(rowNode.getAttribute("used")) {
150
151                         if( rowNode.nextSibling )
152                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
153                         else
154                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
155                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
156                         n.appendChild(text(thisOrg.name()));
157                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
158
159                 } else rowNode.setAttribute("used", "1");
160
161                 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
162
163                 var cpc_temp = rowNode.removeChild(
164                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
165
166                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
167
168                 var isLocal = false;
169                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) isLocal = true;
170                 rdetailSetPath( thisOrg, isLocal );
171
172         }
173
174 }
175
176 /* sets the path to org as 'active' and displays the 
177         path if it's local */
178 function rdetailSetPath(org, local) {
179         if( findOrgDepth(org) == 0 ) return;
180         var row = getId("cp_info_" + org.id());
181         row.setAttribute("hasinfo", "1");
182         if(local) {
183                 unHideMe(row);
184                 row.setAttribute("local", "1");
185         }
186         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
187 }
188
189 function rdetailApplyStatuses( row, template, statuses ) {
190         for( var j in _statusPositions ) {
191                 var stat = _statusPositions[j];
192                 var val = statuses[stat.id()];
193                 var nn = template.cloneNode(true);
194                 if(val) nn.appendChild(text(val));
195                 else nn.appendChild(text(0));
196                 row.appendChild(nn);    
197         }
198 }
199
200
201 /* --------------------------------------------------------------------- */
202 var _statusPositions = {};
203
204 function rdetailBuildStatusColumns() {
205
206         rdetailGrabCopyStatuses();
207         var parent = statusRow;
208         var template = parent.removeChild(G.ui.rdetail.cp_status);
209
210         var i = 0;
211         for( i = 0; i < cp_statuses.length; i++ ) {
212
213                 var c = cp_statuses[i];
214
215                 if(c && c.holdable()) {
216
217                         var name = c.name();
218                         _statusPositions[i] = c;
219                         var node = template.cloneNode(true);
220                         var data = findNodeByName( node, config.names.rdetail.cp_status);
221
222                         data.appendChild(text(name));
223                         parent.appendChild(node);
224                 }       
225         }       
226
227         numStatuses = 0;
228         for(x in _statusPositions) numStatuses++; 
229 }
230
231 function rdetailGrabCopyStatuses() {
232         if(cp_statuses) return cp_statuses;
233    var req = new Request(FETCH_COPY_STATUSES);
234    req.send(true);
235         cp_statuses = req.result();
236         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
237 }
238
239 function _rdetailSortStatuses(a, b) {
240         return parseInt(a.id()) - parseInt(b.id());
241 }
242
243