]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/opac/skin/default/js/copy_details.js
added params for filtering pubdate before/after/between/during. added functional...
[Evergreen.git] / Open-ILS / web / opac / skin / default / js / copy_details.js
1 var cpdTemplate;
2 var cpdCounter = 0;
3 var cpdNodes = {};
4
5 function cpdBuild( contextTbody, contextRow, record, callnumber, orgid, depth ) {
6 var i = cpdCheckExisting(contextRow);
7         if(i) return i;
8
9         var counter = cpdCounter++;
10
11         /* yank out all of the template rows */
12         if(!cpdTemplate) cpdTemplate = $('rdetail_volume_details_row');
13         var templateRow = cpdTemplate.cloneNode(true);
14         templateRow.id = 'cpd_row_' + counter;
15
16         /* shove a dummy a tag in before the context previous sibling */
17         /*
18         contextTbody.insertBefore( 
19                 elem('a',{name:'slot_'+templateRow.id}), contextRow.previousSibling);
20         goTo('#slot_'+templateRow.id);
21         */
22
23         if(isXUL()) {
24                 /* unhide before we unhide/clone the parent */
25                 unHideMe($n(templateRow, 'age_protect_label'));
26                 unHideMe($n(templateRow, 'create_date_label'));
27                 unHideMe($n(templateRow, 'holdable_label'));
28                 unHideMe($n(templateRow, 'due_date_label'));
29         }
30
31         unHideMe(templateRow);
32
33         var print = $n(templateRow,'print');
34         print.onclick = function() { cpdBuildPrintPane(
35                 contextRow, record, callnumber, orgid, depth) };
36
37         var mainTbody = $n(templateRow, 'copies_tbody');
38         var extrasRow = mainTbody.removeChild($n(mainTbody, 'copy_extras_row'));
39
40         var req = new Request(FETCH_COPIES_FROM_VOLUME, record.doc_id(), callnumber, orgid);
41         req.callback(cpdDrawCopies);
42
43         req.request.args = { 
44                 contextTbody    : contextTbody, /* tbody that holds the contextrow */
45                 contextRow              : contextRow, /* the row our new row will be inserted after */
46                 record                  : record,
47                 callnumber              : callnumber, 
48                 orgid                           : orgid,
49                 depth                           : depth,
50                 templateRow             : templateRow, /* contains everything */
51                 mainTbody               : mainTbody, /* holds the copy rows */
52                 extrasRow               : extrasRow, /* wrapper row for all extras */
53                 counter                 : counter
54         };
55
56         if( contextRow.nextSibling ) 
57                 contextTbody.insertBefore( templateRow, contextRow.nextSibling );
58         else
59                 contextTbody.appendChild( templateRow );
60
61         req.send();
62         _debug('creating new details row with id ' + templateRow.id);
63         cpdNodes[templateRow.id] = { templateRow : templateRow };
64         return templateRow.id;
65 }
66
67
68 function cpdBuildPrintWindow(record, orgid) {
69         var div = $('rdetail_print_details').cloneNode(true);
70         div.id = "";
71
72         $n(div, 'lib').appendChild(text(findOrgUnit(orgid).name()));
73         $n(div, 'title').appendChild(text(record.title()));
74         $n(div, 'author').appendChild(text(record.author()));
75         $n(div, 'edition').appendChild(text(record.edition()));
76         $n(div, 'pubdate').appendChild(text(record.pubdate()));
77         $n(div, 'publisher').appendChild(text(record.publisher()));
78         $n(div, 'phys').appendChild(text(record.physical_description()));
79
80         return div;
81 }
82
83 function cpdStylePopupWindow(div) {
84         var tds = div.getElementsByTagName('td');
85         for( var i = 0; i < tds.length ; i++ ) {
86                 var td = tds[i];
87                 var sty = td.getAttribute('style');
88                 if(!sty) sty = "";
89                 td.setAttribute('style', sty + 'padding: 2px; border: 1px solid #F0F0E0;');
90                 if( td.className && td.className.match(/hide_me/) ) 
91                         td.parentNode.removeChild(td);
92         }
93 }
94
95
96 /* builds a friendly print window for this CNs data */
97 function cpdBuildPrintPane(contextRow, record, callnumber, orgid, depth) {
98
99         var div = cpdBuildPrintWindow( record, orgid);
100
101         $n(div, 'cn').appendChild(text(callnumber));
102
103         unHideMe($n(div, 'copy_header'));
104
105         var subtbody = $n(contextRow.nextSibling, 'copies_tbody');
106         var rows = subtbody.getElementsByTagName('tr');
107
108         for( var r = 0; r < rows.length; r++ ) {
109                 var row = rows[r];
110                 if(!row) continue;
111                 var name = row.getAttribute('name');
112                 if( name.match(/extras_row/) ) continue; /* hide the copy notes, stat-cats */
113                 var clone = row.cloneNode(true);
114                 var links = clone.getElementsByTagName('a');
115                 for( var i = 0; i < links.length; i++ ) 
116                         links[i].style.display = 'none';
117
118                 $n(div, 'tbody').appendChild(clone);
119         }
120
121         cpdStylePopupWindow(div);
122         openWindow( div.innerHTML);
123 }
124
125
126
127 /* hide any open tables and if we've already 
128         fleshed this cn, just unhide it */
129 function cpdCheckExisting( contextRow ) {
130
131         var existingid;
132         var next = contextRow.nextSibling;
133
134         if( next && next.getAttribute('templateRow') ) {
135                 var obj = cpdNodes[next.id];
136                 if(obj.templateRow.className.match(/hide_me/)) 
137                         unHideMe(obj.templateRow);
138                 else hideMe(obj.templateRow);
139                 existingid = next.id;
140         }
141
142         if(existingid) _debug('row exists with id ' + existingid);
143
144         for( var o in cpdNodes ) {
145                 var node = cpdNodes[o];
146                 if( existingid && o == existingid ) continue;
147                 hideMe(node.templateRow);
148                 removeCSSClass(node.templateRow.previousSibling, 'rdetail_context_row');
149         }
150
151         addCSSClass(contextRow, 'rdetail_context_row');
152         if(existingid) return existingid;
153         return null;
154 }
155
156 /*
157 function cpdFetchCopies(r) {
158         var args = r.args;
159         args.cn = r.getResultObject();
160         var req = new Request(FETCH_COPIES_FROM_VOLUME, args.cn.id());
161         req.request.args = args;
162         req.callback(cpdDrawCopies);
163         req.send();
164 }
165 */
166
167 function cpdDrawCopies(r) {
168
169         var copies              = r.getResultObject();
170         var args                        = r.args;
171         var copytbody   = $n(args.templateRow, 'copies_tbody');
172         var copyrow             = copytbody.removeChild($n(copytbody, 'copies_row'));
173
174         if(isXUL()) {
175                 /* unhide before we unhide/clone the parent */
176                 unHideMe($n(copyrow, 'age_protect_value'));
177                 unHideMe($n(copyrow, 'create_date_value'));
178                 unHideMe($n(copyrow, 'copy_holdable_td'));
179                 unHideMe($n(copyrow, 'copy_due_date_td'));
180         }
181
182         for( var i = 0; i < copies.length; i++ ) {
183                 var row = copyrow.cloneNode(true);
184                 var copyid = copies[i];
185                 var req = new Request(FETCH_FLESHED_COPY, copies[i]);
186                 req.callback(cpdDrawCopy);
187                 req.request.args = r.args;
188                 req.request.row = row;
189                 req.send();
190                 copytbody.appendChild(row);
191         }
192 }
193
194 function cpdDrawCopy(r) {
195         var copy = r.getResultObject();
196         var row  = r.row;
197
198         $n(row, 'barcode').appendChild(text(copy.barcode()));
199         $n(row, 'location').appendChild(text(copy.location().name()));
200         $n(row, 'status').appendChild(text(copy.status().name()));
201
202         if(isXUL()) {
203                 /* show the hold link */
204                 var l = $n(row, 'copy_hold_link');
205                 unHideMe(l);
206                 l.onclick = function() {
207                         holdsDrawEditor( 
208                                 { 
209                                         type                    : 'C',
210                                         copyObject      : copy,
211                                         onComplete      : function(){}
212                                 }
213                         );
214                 }
215
216                 if( copy.age_protect() ) 
217                         appendClear($n(row, 'age_protect_value'), text(copy.age_protect().name()));
218
219                 var cd = copy.create_date();
220                 cd = cd.replace(/T.*/, '');
221                 $n(row, 'create_date_value').appendChild(text(cd));
222
223                 var yes = $('rdetail.yes').innerHTML;
224                 var no = $('rdetail.no').innerHTML;
225
226                 if( isTrue(copy.holdable()) &&
227                                 isTrue(copy.location().holdable()) &&
228                                 isTrue(copy.status().holdable()) ) {
229                         $n(row, 'copy_is_holdable').appendChild(text(yes));     
230                 } else {
231                         $n(row, 'copy_is_holdable').appendChild(text(no));      
232                 }
233
234                 var circ;
235                 if( copy.circulations() ) {
236                         circ = copy.circulations()[0];
237                         if( circ ) {
238                                 $n(row, 'copy_due_date').appendChild(text(circ.due_date().replace(/[T ].*/,'')));
239                         }
240                 }
241
242         }
243
244         r.args.copy = copy;
245         r.args.copyrow = row;
246         cpdShowNotes(copy, r.args)
247         cpdShowStats(copy, r.args);
248
249 }
250
251 function _cpdExtrasInit(args) {
252
253         var newrid      = 'extras_row_' + args.copy.barcode();
254         var newrow      = $(newrid);
255         if(!newrow) newrow = args.extrasRow.cloneNode(true);
256         var tbody       = $n(newrow, 'extras_tbody');
257         var rowt                = $n(tbody, 'extras_row');
258         newrow.id       = newrid;
259
260         var cr = args.copyrow;
261         var nr = cr.nextSibling;
262         var np = args.mainTbody;
263
264         /* insert the extras row into the main table */
265         if(nr) np.insertBefore( newrow, nr );
266         else np.appendChild(newrow);
267
268         var link = $n(args.copyrow, 'details_link');
269         var link2 = $n(args.copyrow, 'less_details_link');
270         var id = newrow.id;
271         link.id = id + '_morelink';
272         link2.id = id + '_lesslink';
273         unHideMe(link);
274         hideMe(link2);
275
276         link.setAttribute('href', 
277                         'javascript:unHideMe($("'+link2.id+'")); hideMe($("'+link.id+'"));unHideMe($("'+newrow.id+'"));');
278
279         link2.setAttribute('href', 
280                         'javascript:unHideMe($("'+link.id+'")); hideMe($("'+link2.id+'"));hideMe($("'+newrow.id+'"));');
281
282         return [ tbody, rowt ];
283 }
284
285 function cpdShowNotes(copy, args) {
286         var notes = copy.notes();
287         if(!notes || notes.length == 0) return;
288
289         var a = _cpdExtrasInit(args);
290         var tbody = a[0];
291         var rowt = a[1];
292
293         for( var n in notes ) {
294                 var note = notes[n];
295                 if(!isTrue(note.pub())) continue;
296                 var row = rowt.cloneNode(true);
297                 $n(row, 'key').appendChild(text(note.title()));
298                 $n(row, 'value').appendChild(text(note.value()));
299                 unHideMe($n(row, 'note'));
300                 unHideMe(row);
301                 tbody.appendChild(row);
302         }
303 }
304
305
306 function cpdShowStats(copy, args) {
307         var entries = copy.stat_cat_entry_copy_maps();
308         if(!entries || entries.length == 0) return;
309
310         var visibleStatCat = false;
311
312         /*
313                 check all copy stat cats; if we find one that's OPAC visible,
314                 set the flag and break the loop. If we've found one, or we're
315                 in the staff client, build the table. if not, we return doing
316                 nothing, as though the stat_cat_entry_copy_map was empty or null
317         */
318
319         for( var n in entries )
320         {
321                         var entry = entries[n];
322                         if(isTrue(entry.stat_cat().opac_visible()))
323                         {
324                                 visibleStatCat = true;
325                                 break;
326                         }
327         }
328
329         if(!(isXUL() || visibleStatCat)) return;
330
331         var a = _cpdExtrasInit(args);
332         var tbody = a[0];
333         var rowt = a[1];
334
335         for( var n in entries ) {
336                 var entry = entries[n];
337                 if(!(isXUL() || isTrue(entry.stat_cat().opac_visible()))) continue;
338                 var row = rowt.cloneNode(true);
339                 $n(row, 'key').appendChild(text(entry.stat_cat().name()));
340                 $n(row, 'value').appendChild(text(entry.stat_cat_entry().value()));
341                 unHideMe($n(row, 'cat'));
342                 unHideMe(row);
343                 tbody.appendChild(row);
344         }
345 }
346