5 function cpdBuild( contextTbody, contextRow, record, callnumber, orgid, depth ) {
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'));
30 unHideMe(templateRow);
32 var print = $n(templateRow,'print');
33 print.onclick = function() { cpdBuildPrintPane(
34 contextRow, record, callnumber, orgid, depth) };
36 var mainTbody = $n(templateRow, 'copies_tbody');
37 var extrasRow = mainTbody.removeChild($n(mainTbody, 'copy_extras_row'));
39 var req = new Request(FETCH_COPIES_FROM_VOLUME, record.doc_id(), callnumber, orgid);
40 req.callback(cpdDrawCopies);
43 contextTbody : contextTbody, /* tbody that holds the contextrow */
44 contextRow : contextRow, /* the row our new row will be inserted after */
46 callnumber : callnumber,
49 templateRow : templateRow, /* contains everything */
50 mainTbody : mainTbody, /* holds the copy rows */
51 extrasRow : extrasRow, /* wrapper row for all extras */
55 if( contextRow.nextSibling )
56 contextTbody.insertBefore( templateRow, contextRow.nextSibling );
58 contextTbody.appendChild( templateRow );
61 _debug('creating new details row with id ' + templateRow.id);
62 cpdNodes[templateRow.id] = { templateRow : templateRow };
63 return templateRow.id;
67 function cpdBuildPrintWindow(record, orgid) {
68 var div = $('rdetail_print_details').cloneNode(true);
71 $n(div, 'lib').appendChild(text(findOrgUnit(orgid).name()));
72 $n(div, 'title').appendChild(text(record.title()));
73 $n(div, 'author').appendChild(text(record.author()));
74 $n(div, 'edition').appendChild(text(record.edition()));
75 $n(div, 'pubdate').appendChild(text(record.pubdate()));
76 $n(div, 'publisher').appendChild(text(record.publisher()));
77 $n(div, 'phys').appendChild(text(record.physical_description()));
82 function cpdStylePopupWindow(div) {
83 var tds = div.getElementsByTagName('td');
84 for( var i = 0; i < tds.length ; i++ ) {
86 var sty = td.getAttribute('style');
88 td.setAttribute('style', sty + 'padding: 2px; border: 1px solid #F0F0E0;');
89 if( td.className && td.className.match(/hide_me/) )
90 td.parentNode.removeChild(td);
95 /* builds a friendly print window for this CNs data */
96 function cpdBuildPrintPane(contextRow, record, callnumber, orgid, depth) {
98 var div = cpdBuildPrintWindow( record, orgid);
100 $n(div, 'cn').appendChild(text(callnumber));
102 unHideMe($n(div, 'copy_header'));
104 var subtbody = $n(contextRow.nextSibling, 'copies_tbody');
105 var rows = subtbody.getElementsByTagName('tr');
107 for( var r = 0; r < rows.length; r++ ) {
110 var name = row.getAttribute('name');
111 if( name.match(/extras_row/) ) continue; /* hide the copy notes, stat-cats */
112 var clone = row.cloneNode(true);
113 var links = clone.getElementsByTagName('a');
114 for( var i = 0; i < links.length; i++ )
115 links[i].style.display = 'none';
117 $n(div, 'tbody').appendChild(clone);
120 cpdStylePopupWindow(div);
121 openWindow( div.innerHTML);
126 /* hide any open tables and if we've already
127 fleshed this cn, just unhide it */
128 function cpdCheckExisting( contextRow ) {
131 var next = contextRow.nextSibling;
133 if( next && next.getAttribute('templateRow') ) {
134 var obj = cpdNodes[next.id];
135 if(obj.templateRow.className.match(/hide_me/))
136 unHideMe(obj.templateRow);
137 else hideMe(obj.templateRow);
138 existingid = next.id;
141 if(existingid) _debug('row exists with id ' + existingid);
143 for( var o in cpdNodes ) {
144 var node = cpdNodes[o];
145 if( existingid && o == existingid ) continue;
146 hideMe(node.templateRow);
147 removeCSSClass(node.templateRow.previousSibling, 'rdetail_context_row');
150 addCSSClass(contextRow, 'rdetail_context_row');
151 if(existingid) return existingid;
156 function cpdFetchCopies(r) {
158 args.cn = r.getResultObject();
159 var req = new Request(FETCH_COPIES_FROM_VOLUME, args.cn.id());
160 req.request.args = args;
161 req.callback(cpdDrawCopies);
166 function cpdDrawCopies(r) {
168 var copies = r.getResultObject();
170 var copytbody = $n(args.templateRow, 'copies_tbody');
171 var copyrow = copytbody.removeChild($n(copytbody, 'copies_row'));
174 /* unhide before we unhide/clone the parent */
175 unHideMe($n(copyrow, 'age_protect_value'));
176 unHideMe($n(copyrow, 'create_date_value'));
177 unHideMe($n(copyrow, 'copy_holdable_td'));
180 for( var i = 0; i < copies.length; i++ ) {
181 var row = copyrow.cloneNode(true);
182 var copyid = copies[i];
183 var req = new Request(FETCH_FLESHED_COPY, copies[i]);
184 req.callback(cpdDrawCopy);
185 req.request.args = r.args;
186 req.request.row = row;
188 copytbody.appendChild(row);
192 function cpdDrawCopy(r) {
193 var copy = r.getResultObject();
196 $n(row, 'barcode').appendChild(text(copy.barcode()));
197 $n(row, 'location').appendChild(text(copy.location().name()));
198 $n(row, 'status').appendChild(text(copy.status().name()));
202 /* show the hold link */
203 var l = $n(row, 'copy_hold_link');
205 l.onclick = function() {
210 onComplete : function(){}
215 if( copy.age_protect() )
216 appendClear($n(row, 'age_protect_value'), text(copy.age_protect().name()));
218 var cd = copy.create_date();
219 cd = cd.replace(/T.*/, '');
220 $n(row, 'create_date_value').appendChild(text(cd));
222 var yes = $('rdetail.yes').innerHTML;
223 var no = $('rdetail.no').innerHTML;
225 if( isTrue(copy.holdable()) &&
226 isTrue(copy.location().holdable()) &&
227 isTrue(copy.status().holdable()) ) {
228 $n(row, 'copy_is_holdable').appendChild(text(yes));
230 $n(row, 'copy_is_holdable').appendChild(text(no));
236 r.args.copyrow = row;
237 cpdShowNotes(copy, r.args)
238 cpdShowStats(copy, r.args);
242 function _cpdExtrasInit(args) {
244 var newrid = 'extras_row_' + args.copy.barcode();
245 var newrow = $(newrid);
246 if(!newrow) newrow = args.extrasRow.cloneNode(true);
247 var tbody = $n(newrow, 'extras_tbody');
248 var rowt = $n(tbody, 'extras_row');
251 var cr = args.copyrow;
252 var nr = cr.nextSibling;
253 var np = args.mainTbody;
255 /* insert the extras row into the main table */
256 if(nr) np.insertBefore( newrow, nr );
257 else np.appendChild(newrow);
259 var link = $n(args.copyrow, 'details_link');
260 var link2 = $n(args.copyrow, 'less_details_link');
262 link.id = id + '_morelink';
263 link2.id = id + '_lesslink';
267 link.setAttribute('href',
268 'javascript:unHideMe($("'+link2.id+'")); hideMe($("'+link.id+'"));unHideMe($("'+newrow.id+'"));');
270 link2.setAttribute('href',
271 'javascript:unHideMe($("'+link.id+'")); hideMe($("'+link2.id+'"));hideMe($("'+newrow.id+'"));');
273 return [ tbody, rowt ];
276 function cpdShowNotes(copy, args) {
277 var notes = copy.notes();
278 if(!notes || notes.length == 0) return;
280 var a = _cpdExtrasInit(args);
284 for( var n in notes ) {
286 if(!isTrue(note.pub())) continue;
287 var row = rowt.cloneNode(true);
288 $n(row, 'key').appendChild(text(note.title()));
289 $n(row, 'value').appendChild(text(note.value()));
290 unHideMe($n(row, 'note'));
292 tbody.appendChild(row);
297 function cpdShowStats(copy, args) {
298 var entries = copy.stat_cat_entry_copy_maps();
299 if(!entries || entries.length == 0) return;
301 var a = _cpdExtrasInit(args);
305 for( var n in entries ) {
306 var entry = entries[n];
307 var row = rowt.cloneNode(true);
308 $n(row, 'key').appendChild(text(entry.stat_cat().name()));
309 $n(row, 'value').appendChild(text(entry.stat_cat_entry().value()));
310 unHideMe($n(row, 'cat'));
312 tbody.appendChild(row);