]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/rdetail.js
basic record level holds working on record result and record detail pages
[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 var recordsCache = [];
10
11 var copyRowParent = null;
12 var copyRow = null;
13 var statusRow = null;
14 var numStatuses = null;
15
16 function rdetailDraw() {
17
18         copyRowParent = G.ui.rdetail.cp_info_row.parentNode;
19         copyRow = copyRowParent.removeChild(G.ui.rdetail.cp_info_row);
20         statusRow = G.ui.rdetail.cp_status.parentNode;
21         statusRow.id = '__rdsrow';
22
23         G.ui.rdetail.cp_info_local.onclick = rdetailShowLocalCopies;
24         G.ui.rdetail.cp_info_all.onclick = rdetailShowAllCopies;
25         G.ui.rdetail.view_marc.onclick = rdetailViewMarc;
26         G.ui.rdetail.hide_marc.onclick = showCanvas;
27
28
29         if(getLocation() == globalOrgTree.id())
30                 hideMe(G.ui.rdetail.cp_info_all);
31
32
33
34         var req = new Request(FETCH_RMODS, getRid());
35         req.callback(_rdetailDraw);
36         req.send();
37 }
38
39 function rdetailViewMarc() {
40         if(!record) return;
41
42         if( G.ui.rdetail.view_marc_box.innerHTML.indexOf("style") == -1 ) {
43                 var req = new Request( FETCH_MARC_HTML, record.doc_id() );
44                 req.send(true);
45                 var html = req.result();
46                 G.ui.rdetail.view_marc_box.innerHTML = html;
47         }
48         swapCanvas(G.ui.rdetail.view_marc_div);
49 }
50
51
52 function rdetailShowLocalCopies() {
53
54         var found = false;
55         var rows = copyRowParent.getElementsByTagName("tr");
56         for( var r in rows ) {
57                 if(rows[r].id == "__rdsrow") continue;
58                 hideMe(rows[r]);
59                 if(rows[r].getAttribute && rows[r].getAttribute("local")) {
60                         unHideMe(rows[r]);
61                         found = true;
62                 }
63         }
64
65         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
66         hideMe(G.ui.rdetail.cp_info_local);
67         unHideMe(G.ui.rdetail.cp_info_all);
68 }
69
70 function rdetailShowAllCopies() {
71         var rows = copyRowParent.getElementsByTagName("tr");
72         for( var r in rows ) 
73                 if(rows[r].getAttribute && rows[r].getAttribute("hasinfo"))
74                         unHideMe(rows[r]);
75
76         hideMe(G.ui.rdetail.cp_info_all);
77         unHideMe(G.ui.rdetail.cp_info_local);
78         hideMe(G.ui.rdetail.cp_info_none);
79 }
80
81
82 function _rdetailDraw(r) {
83         record = r.getResultObject();
84
85         G.ui.rdetail.title.appendChild(text(record.title()));
86         buildSearchLink(STYPE_AUTHOR, record.author(), G.ui.rdetail.author);
87         G.ui.rdetail.isbn.appendChild(text(cleanISBN(record.isbn())));
88         G.ui.rdetail.edition.appendChild(text(record.edition()));
89         G.ui.rdetail.pubdate.appendChild(text(record.pubdate()));
90         G.ui.rdetail.publisher.appendChild(text(record.publisher()));
91         G.ui.rdetail.tor.appendChild(text(record.types_of_resource()[0]));
92         setResourcePic( G.ui.rdetail.tor_pic, record.types_of_resource()[0]);
93         G.ui.rdetail.abstr.appendChild(text(record.synopsis()));
94
95
96         $('rdetail_place_hold').setAttribute(
97                 'href','javascript:holdsDrawWindow("'+record.doc_id()+'");');
98
99         G.ui.rdetail.image.setAttribute("src", buildISBNSrc(cleanISBN(record.isbn())));
100         runEvt("rdetail", "recordDrawn");
101         recordsCache.push(record);
102 }
103
104
105 function rdetailBuildInfoRows() {
106         var req = new Request(FETCH_COPY_COUNTS_SUMMARY, record.doc_id())
107         req.callback(_rdetailBuildInfoRows);
108         req.send();
109 }
110
111 /* pre-allocate the copy info table with all org units in correct order */
112 function _rdetailRows(node) {
113
114         if(node) {
115
116                 var row = copyRow.cloneNode(true);
117                 row.id = "cp_info_" + node.id();
118
119                 var libtd = findNodeByName( row, config.names.rdetail.lib_cell );
120                 var cntd = findNodeByName( row, config.names.rdetail.cn_cell );
121                 var cpctd = findNodeByName( row, config.names.rdetail.cp_count_cell );
122         
123                 libtd.appendChild(text(node.name()));
124                 libtd.setAttribute("style", "padding-left: " + ((findOrgDepth(node) - 1)  * 9) + "px;");
125         
126                 if(!findOrgType(node.ou_type()).can_have_vols()) {
127
128                         row.removeChild(cntd);
129                         row.removeChild(cpctd);
130
131                         libtd.setAttribute("colspan", numStatuses + 2 );
132                         libtd.colSpan = numStatuses + 2;
133                         addCSSClass(row, config.css.color_3);
134                 } 
135         
136                 copyRowParent.appendChild(row);
137
138         } else { node = globalOrgTree; }
139
140         for( var c in node.children() ) 
141                 _rdetailRows(node.children()[c]);
142 }
143
144 /* walk through the copy info and build rows where necessary */
145 function _rdetailBuildInfoRows(r) {
146
147         _rdetailRows();
148
149         var summary = r.getResultObject();
150
151         G.ui.rdetail.cp_info_loading.parentNode.removeChild(
152                 G.ui.rdetail.cp_info_loading);
153
154         var found = false;
155         for( var i = 0; i < summary.length; i++ ) {
156
157                 var arr = summary[i];
158                 var thisOrg = findOrgUnit(arr[0]);
159                 var rowNode = $("cp_info_" + thisOrg.id());
160
161                 if(rowNode.getAttribute("used")) {
162
163                         if( rowNode.nextSibling )
164                                 rowNode = copyRowParent.insertBefore(copyRow.cloneNode(true), rowNode.nextSibling);
165                         else
166                                 rowNode = copyRowParent.appendChild(copyRow.cloneNode(true));
167                         var n = findNodeByName( rowNode, config.names.rdetail.lib_cell );
168                         n.appendChild(text(thisOrg.name()));
169                         n.setAttribute("style", "padding-left: " + ((findOrgDepth(thisOrg) - 1)  * 9) + "px;");
170
171                 } else rowNode.setAttribute("used", "1");
172
173                 findNodeByName( rowNode, config.names.rdetail.cn_cell ).appendChild(text(arr[1]));
174
175                 var cpc_temp = rowNode.removeChild(
176                         findNodeByName(rowNode, config.names.rdetail.cp_count_cell));
177
178                 rdetailApplyStatuses(rowNode, cpc_temp, arr[2]);
179
180                 var isLocal = false;
181                 if( orgIsMine( findOrgUnit(getLocation()), thisOrg ) ) { found = true; isLocal = true; }
182                 rdetailSetPath( thisOrg, isLocal );
183
184         }
185
186         if(!found) unHideMe(G.ui.rdetail.cp_info_none);
187
188 }
189
190 /* sets the path to org as 'active' and displays the 
191         path if it's local */
192 function rdetailSetPath(org, local) {
193         if( findOrgDepth(org) == 0 ) return;
194         var row = $("cp_info_" + org.id());
195         row.setAttribute("hasinfo", "1");
196         if(local) {
197                 unHideMe(row);
198                 row.setAttribute("local", "1");
199         }
200         rdetailSetPath(findOrgUnit(org.parent_ou()), local);
201 }
202
203 function rdetailApplyStatuses( row, template, statuses ) {
204         for( var j in _statusPositions ) {
205                 var stat = _statusPositions[j];
206                 var val = statuses[stat.id()];
207                 var nn = template.cloneNode(true);
208                 if(val) nn.appendChild(text(val));
209                 else nn.appendChild(text(0));
210                 row.appendChild(nn);    
211         }
212 }
213
214
215 /* --------------------------------------------------------------------- */
216 var _statusPositions = {};
217
218 function rdetailBuildStatusColumns() {
219
220         rdetailGrabCopyStatuses();
221         var parent = statusRow;
222         var template = parent.removeChild(G.ui.rdetail.cp_status);
223
224         var i = 0;
225         for( i = 0; i < cp_statuses.length; i++ ) {
226
227                 var c = cp_statuses[i];
228
229                 if(c && c.holdable()) {
230
231                         var name = c.name();
232                         _statusPositions[i] = c;
233                         var node = template.cloneNode(true);
234                         var data = findNodeByName( node, config.names.rdetail.cp_status);
235
236                         data.appendChild(text(name));
237                         parent.appendChild(node);
238                 }       
239         }       
240
241         numStatuses = 0;
242         for(x in _statusPositions) numStatuses++; 
243 }
244
245 function rdetailGrabCopyStatuses() {
246         if(cp_statuses) return cp_statuses;
247    var req = new Request(FETCH_COPY_STATUSES);
248    req.send(true);
249         cp_statuses = req.result();
250         cp_statuses = cp_statuses.sort(_rdetailSortStatuses);
251 }
252
253 function _rdetailSortStatuses(a, b) {
254         return parseInt(a.id()) - parseInt(b.id());
255 }
256
257