5 function cpdBuild( contextTbody, contextRow, record, callnumber, orgid, depth, copy_location ) {
6 var i = cpdCheckExisting(contextRow);
9 var counter = cpdCounter++;
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;
16 /* shove a dummy a tag in before the context previous sibling */
18 contextTbody.insertBefore(
19 elem('a',{name:'slot_'+templateRow.id}), contextRow.previousSibling);
20 goTo('#slot_'+templateRow.id);
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'));
31 unHideMe(templateRow);
33 var print = $n(templateRow,'print');
34 print.onclick = function() { cpdBuildPrintPane(
35 contextRow, record, callnumber, orgid, depth) };
37 var mainTbody = $n(templateRow, 'copies_tbody');
38 var extrasRow = mainTbody.removeChild($n(mainTbody, 'copy_extras_row'));
40 var req = new Request(FETCH_COPIES_FROM_VOLUME, record.doc_id(), callnumber, orgid);
41 req.callback(cpdDrawCopies);
44 contextTbody : contextTbody, /* tbody that holds the contextrow */
45 contextRow : contextRow, /* the row our new row will be inserted after */
47 callnumber : callnumber,
50 templateRow : templateRow, /* contains everything */
51 copy_location : copy_location,
52 mainTbody : mainTbody, /* holds the copy rows */
53 extrasRow : extrasRow, /* wrapper row for all extras */
57 if( contextRow.nextSibling )
58 contextTbody.insertBefore( templateRow, contextRow.nextSibling );
60 contextTbody.appendChild( templateRow );
63 _debug('creating new details row with id ' + templateRow.id);
64 cpdNodes[templateRow.id] = { templateRow : templateRow };
65 return templateRow.id;
69 function cpdBuildPrintWindow(record, orgid) {
70 var div = $('rdetail_print_details').cloneNode(true);
73 $n(div, 'lib').appendChild(text(findOrgUnit(orgid).name()));
74 $n(div, 'title').appendChild(text(record.title()));
75 $n(div, 'author').appendChild(text(record.author()));
76 $n(div, 'edition').appendChild(text(record.edition()));
77 $n(div, 'pubdate').appendChild(text(record.pubdate()));
78 $n(div, 'publisher').appendChild(text(record.publisher()));
79 $n(div, 'phys').appendChild(text(record.physical_description()));
84 function cpdStylePopupWindow(div) {
85 var tds = div.getElementsByTagName('td');
86 for( var i = 0; i < tds.length ; i++ ) {
88 var sty = td.getAttribute('style');
90 td.setAttribute('style', sty + 'padding: 2px; border: 1px solid #F0F0E0;');
91 if( td.className && td.className.match(/hide_me/) )
92 td.parentNode.removeChild(td);
97 /* builds a friendly print window for this CNs data */
98 function cpdBuildPrintPane(contextRow, record, callnumber, orgid, depth) {
100 var div = cpdBuildPrintWindow( record, orgid);
102 $n(div, 'cn').appendChild(text(callnumber));
104 unHideMe($n(div, 'copy_header'));
106 var subtbody = $n(contextRow.nextSibling, 'copies_tbody');
107 var rows = subtbody.getElementsByTagName('tr');
109 for( var r = 0; r < rows.length; r++ ) {
112 var name = row.getAttribute('name');
113 if( name.match(/extras_row/) ) continue; /* hide the copy notes, stat-cats */
114 var clone = row.cloneNode(true);
115 var links = clone.getElementsByTagName('a');
116 for( var i = 0; i < links.length; i++ )
117 links[i].style.display = 'none';
119 $n(div, 'tbody').appendChild(clone);
122 cpdStylePopupWindow(div);
123 openWindow( div.innerHTML);
128 /* hide any open tables and if we've already
129 fleshed this cn, just unhide it */
130 function cpdCheckExisting( contextRow ) {
133 var next = contextRow.nextSibling;
135 if( next && next.getAttribute('templateRow') ) {
136 var obj = cpdNodes[next.id];
137 if(obj.templateRow.className.match(/hide_me/))
138 unHideMe(obj.templateRow);
139 else hideMe(obj.templateRow);
140 existingid = next.id;
143 if(existingid) _debug('row exists with id ' + existingid);
145 for( var o in cpdNodes ) {
146 var node = cpdNodes[o];
147 if( existingid && o == existingid ) continue;
148 hideMe(node.templateRow);
149 removeCSSClass(node.templateRow.previousSibling, 'rdetail_context_row');
152 addCSSClass(contextRow, 'rdetail_context_row');
153 if(existingid) return existingid;
158 function cpdFetchCopies(r) {
160 args.cn = r.getResultObject();
161 var req = new Request(FETCH_COPIES_FROM_VOLUME, args.cn.id());
162 req.request.args = args;
163 req.callback(cpdDrawCopies);
168 function cpdDrawCopies(r) {
170 var copies = r.getResultObject();
172 var copytbody = $n(args.templateRow, 'copies_tbody');
173 var copyrow = copytbody.removeChild($n(copytbody, 'copies_row'));
176 /* unhide before we unhide/clone the parent */
177 unHideMe($n(copyrow, 'age_protect_value'));
178 unHideMe($n(copyrow, 'create_date_value'));
179 unHideMe($n(copyrow, 'copy_holdable_td'));
180 unHideMe($n(copyrow, 'copy_due_date_td'));
183 for( var i = 0; i < copies.length; i++ ) {
184 var row = copyrow.cloneNode(true);
185 var copyid = copies[i];
186 var req = new Request(FETCH_FLESHED_COPY, copies[i]);
187 req.callback(cpdDrawCopy);
188 req.request.args = r.args;
189 req.request.row = row;
191 copytbody.appendChild(row);
195 function cpdDrawCopy(r) {
196 var copy = r.getResultObject();
199 if (r.args.copy_location && copy.location().name() != r.args.copy_location) {
204 $n(row, 'barcode').appendChild(text(copy.barcode()));
205 $n(row, 'location').appendChild(text(copy.location().name()));
206 $n(row, 'status').appendChild(text(copy.status().name()));
209 /* show the hold link */
210 var l = $n(row, 'copy_hold_link');
212 l.onclick = function() {
217 onComplete : function(){}
222 if( copy.age_protect() )
223 appendClear($n(row, 'age_protect_value'), text(copy.age_protect().name()));
225 var cd = copy.create_date();
226 cd = cd.replace(/T.*/, '');
227 $n(row, 'create_date_value').appendChild(text(cd));
229 var yes = $('rdetail.yes').innerHTML;
230 var no = $('rdetail.no').innerHTML;
232 if( isTrue(copy.holdable()) &&
233 isTrue(copy.location().holdable()) &&
234 isTrue(copy.status().holdable()) ) {
235 $n(row, 'copy_is_holdable').appendChild(text(yes));
237 $n(row, 'copy_is_holdable').appendChild(text(no));
241 if( copy.circulations() ) {
242 circ = copy.circulations()[0];
244 $n(row, 'copy_due_date').appendChild(text(circ.due_date().replace(/[T ].*/,'')));
251 r.args.copyrow = row;
252 cpdShowNotes(copy, r.args)
253 cpdShowStats(copy, r.args);
257 function _cpdExtrasInit(args) {
259 var newrid = 'extras_row_' + args.copy.barcode();
260 var newrow = $(newrid);
261 if(!newrow) newrow = args.extrasRow.cloneNode(true);
262 var tbody = $n(newrow, 'extras_tbody');
263 var rowt = $n(tbody, 'extras_row');
266 var cr = args.copyrow;
267 var nr = cr.nextSibling;
268 var np = args.mainTbody;
270 /* insert the extras row into the main table */
271 if(nr) np.insertBefore( newrow, nr );
272 else np.appendChild(newrow);
274 var link = $n(args.copyrow, 'details_link');
275 var link2 = $n(args.copyrow, 'less_details_link');
277 link.id = id + '_morelink';
278 link2.id = id + '_lesslink';
282 link.setAttribute('href',
283 'javascript:unHideMe($("'+link2.id+'")); hideMe($("'+link.id+'"));unHideMe($("'+newrow.id+'"));');
285 link2.setAttribute('href',
286 'javascript:unHideMe($("'+link.id+'")); hideMe($("'+link2.id+'"));hideMe($("'+newrow.id+'"));');
288 return [ tbody, rowt ];
291 function cpdShowNotes(copy, args) {
292 var notes = copy.notes();
293 if(!notes || notes.length == 0) return;
295 var a = _cpdExtrasInit(args);
299 for( var n in notes ) {
301 if(!isTrue(note.pub())) continue;
302 var row = rowt.cloneNode(true);
303 $n(row, 'key').appendChild(text(note.title()));
304 $n(row, 'value').appendChild(text(note.value()));
305 unHideMe($n(row, 'note'));
307 tbody.appendChild(row);
312 function cpdShowStats(copy, args) {
313 var entries = copy.stat_cat_entry_copy_maps();
314 if(!entries || entries.length == 0) return;
316 var visibleStatCat = false;
319 check all copy stat cats; if we find one that's OPAC visible,
320 set the flag and break the loop. If we've found one, or we're
321 in the staff client, build the table. if not, we return doing
322 nothing, as though the stat_cat_entry_copy_map was empty or null
325 for( var n in entries )
327 var entry = entries[n];
328 if(isTrue(entry.stat_cat().opac_visible()))
330 visibleStatCat = true;
335 if(!(isXUL() || visibleStatCat)) return;
337 var a = _cpdExtrasInit(args);
341 for( var n in entries ) {
342 var entry = entries[n];
343 if(!(isXUL() || isTrue(entry.stat_cat().opac_visible()))) continue;
344 var row = rowt.cloneNode(true);
345 $n(row, 'key').appendChild(text(entry.stat_cat().name()));
346 $n(row, 'value').appendChild(text(entry.stat_cat_entry().value()));
347 unHideMe($n(row, 'cat'));
349 tbody.appendChild(row);