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'));
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 mainTbody : mainTbody, /* holds the copy rows */
52 extrasRow : extrasRow, /* wrapper row for all extras */
56 if( contextRow.nextSibling )
57 contextTbody.insertBefore( templateRow, contextRow.nextSibling );
59 contextTbody.appendChild( templateRow );
62 _debug('creating new details row with id ' + templateRow.id);
63 cpdNodes[templateRow.id] = { templateRow : templateRow };
64 return templateRow.id;
68 function cpdBuildPrintWindow(record, orgid) {
69 var div = $('rdetail_print_details').cloneNode(true);
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()));
83 function cpdStylePopupWindow(div) {
84 var tds = div.getElementsByTagName('td');
85 for( var i = 0; i < tds.length ; i++ ) {
87 var sty = td.getAttribute('style');
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);
96 /* builds a friendly print window for this CNs data */
97 function cpdBuildPrintPane(contextRow, record, callnumber, orgid, depth) {
99 var div = cpdBuildPrintWindow( record, orgid);
101 $n(div, 'cn').appendChild(text(callnumber));
103 unHideMe($n(div, 'copy_header'));
105 var subtbody = $n(contextRow.nextSibling, 'copies_tbody');
106 var rows = subtbody.getElementsByTagName('tr');
108 for( var r = 0; r < rows.length; r++ ) {
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';
118 $n(div, 'tbody').appendChild(clone);
121 cpdStylePopupWindow(div);
122 openWindow( div.innerHTML);
127 /* hide any open tables and if we've already
128 fleshed this cn, just unhide it */
129 function cpdCheckExisting( contextRow ) {
132 var next = contextRow.nextSibling;
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;
142 if(existingid) _debug('row exists with id ' + existingid);
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');
151 addCSSClass(contextRow, 'rdetail_context_row');
152 if(existingid) return existingid;
157 function cpdFetchCopies(r) {
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);
167 function cpdDrawCopies(r) {
169 var copies = r.getResultObject();
171 var copytbody = $n(args.templateRow, 'copies_tbody');
172 var copyrow = copytbody.removeChild($n(copytbody, 'copies_row'));
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'));
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;
190 copytbody.appendChild(row);
194 function cpdDrawCopy(r) {
195 var copy = r.getResultObject();
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()));
203 /* show the hold link */
204 var l = $n(row, 'copy_hold_link');
206 l.onclick = function() {
211 onComplete : function(){}
216 if( copy.age_protect() )
217 appendClear($n(row, 'age_protect_value'), text(copy.age_protect().name()));
219 var cd = copy.create_date();
220 cd = cd.replace(/T.*/, '');
221 $n(row, 'create_date_value').appendChild(text(cd));
223 var yes = $('rdetail.yes').innerHTML;
224 var no = $('rdetail.no').innerHTML;
226 if( isTrue(copy.holdable()) &&
227 isTrue(copy.location().holdable()) &&
228 isTrue(copy.status().holdable()) ) {
229 $n(row, 'copy_is_holdable').appendChild(text(yes));
231 $n(row, 'copy_is_holdable').appendChild(text(no));
235 if( copy.circulations() ) {
236 circ = copy.circulations()[0];
238 $n(row, 'copy_due_date').appendChild(text(circ.due_date().replace(/[T ].*/,'')));
245 r.args.copyrow = row;
246 cpdShowNotes(copy, r.args)
247 cpdShowStats(copy, r.args);
251 function _cpdExtrasInit(args) {
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');
260 var cr = args.copyrow;
261 var nr = cr.nextSibling;
262 var np = args.mainTbody;
264 /* insert the extras row into the main table */
265 if(nr) np.insertBefore( newrow, nr );
266 else np.appendChild(newrow);
268 var link = $n(args.copyrow, 'details_link');
269 var link2 = $n(args.copyrow, 'less_details_link');
271 link.id = id + '_morelink';
272 link2.id = id + '_lesslink';
276 link.setAttribute('href',
277 'javascript:unHideMe($("'+link2.id+'")); hideMe($("'+link.id+'"));unHideMe($("'+newrow.id+'"));');
279 link2.setAttribute('href',
280 'javascript:unHideMe($("'+link.id+'")); hideMe($("'+link2.id+'"));hideMe($("'+newrow.id+'"));');
282 return [ tbody, rowt ];
285 function cpdShowNotes(copy, args) {
286 var notes = copy.notes();
287 if(!notes || notes.length == 0) return;
289 var a = _cpdExtrasInit(args);
293 for( var n in notes ) {
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'));
301 tbody.appendChild(row);
306 function cpdShowStats(copy, args) {
307 var entries = copy.stat_cat_entry_copy_maps();
308 if(!entries || entries.length == 0) return;
310 var a = _cpdExtrasInit(args);
314 for( var n in entries ) {
315 var entry = entries[n];
316 var row = rowt.cloneNode(true);
317 $n(row, 'key').appendChild(text(entry.stat_cat().name()));
318 $n(row, 'value').appendChild(text(entry.stat_cat_entry().value()));
319 unHideMe($n(row, 'cat'));
321 tbody.appendChild(row);