5 /* showDueDate will show the due date in the OPAC */
6 var showDueDate = false;
7 /* showDueTime will show the due time (hours and minutes) in the OPAC;
8 if showDueDate is false, then showDueTime has no effect
10 var showDueTime = false;
12 function cpdBuild( contextTbody, contextRow, record, callnumber, orgid, depth, copy_location, already_fetched_copies, peer_types ) {
13 var i = cpdCheckExisting(contextRow);
16 var counter = cpdCounter++;
18 /* yank out all of the template rows */
19 if(!cpdTemplate) cpdTemplate = $('rdetail_volume_details_row');
20 var templateRow = cpdTemplate.cloneNode(true);
21 templateRow.id = 'cpd_row_' + counter;
23 /* shove a dummy a tag in before the context previous sibling */
25 contextTbody.insertBefore(
26 elem('a',{name:'slot_'+templateRow.id}), contextRow.previousSibling);
27 goTo('#slot_'+templateRow.id);
31 /* unhide before we unhide/clone the parent */
32 unHideMe($n(templateRow, 'age_protect_label'));
33 unHideMe($n(templateRow, 'create_date_label'));
34 unHideMe($n(templateRow, 'active_date_label'));
35 unHideMe($n(templateRow, 'holdable_label'));
38 if (isXUL() || showDueDate) {
39 unHideMe($n(templateRow, 'due_date_label'));
42 unHideMe(templateRow);
44 var print = $n(templateRow,'print');
45 print.onclick = function() { cpdBuildPrintPane(
46 contextRow, record, callnumber, orgid, depth) };
47 if (callnumber == null) {
48 addCSSClass(print,'hide_me');
51 var mainTbody = $n(templateRow, 'copies_tbody');
52 var extrasRow = mainTbody.removeChild($n(mainTbody, 'copy_extras_row'));
55 peer_types : peer_types, /* indexed the same as already_fetched_copies */
56 contextTbody : contextTbody, /* tbody that holds the contextrow */
57 contextRow : contextRow, /* the row our new row will be inserted after */
59 callnumber : callnumber,
62 templateRow : templateRow, /* contains everything */
63 copy_location : copy_location,
64 mainTbody : mainTbody, /* holds the copy rows */
65 extrasRow : extrasRow, /* wrapper row for all extras */
69 if (! already_fetched_copies) {
70 var req = new Request(FETCH_COPIES_FROM_VOLUME, record.doc_id(), callnumber, orgid);
71 req.callback(cpdDrawCopies);
73 req.request.args = request_args;
79 delete request_args['copy_location'];
81 'args' : request_args,
82 'getResultObject' : function() { return already_fetched_copies; }
88 if( contextRow.nextSibling )
89 contextTbody.insertBefore( templateRow, contextRow.nextSibling );
91 contextTbody.appendChild( templateRow );
92 _debug('creating new details row with id ' + templateRow.id);
93 cpdNodes[templateRow.id] = { templateRow : templateRow };
94 return templateRow.id;
98 function cpdBuildPrintWindow(record, orgid) {
99 var div = $('rdetail_print_details').cloneNode(true);
102 $n(div, 'lib').appendChild(text(findOrgUnit(orgid).name()));
103 $n(div, 'title').appendChild(text(record.title()));
104 $n(div, 'author').appendChild(text(record.author()));
105 $n(div, 'edition').appendChild(text(record.edition()));
106 $n(div, 'pubdate').appendChild(text(record.pubdate()));
107 $n(div, 'publisher').appendChild(text(record.publisher()));
108 $n(div, 'phys').appendChild(text(record.physical_description()));
113 function cpdStylePopupWindow(div) {
114 var tds = div.getElementsByTagName('td');
115 for( var i = 0; i < tds.length ; i++ ) {
117 var sty = td.getAttribute('style');
119 td.setAttribute('style', sty + 'padding: 2px; border: 1px solid #F0F0E0;');
120 if( td.className && td.className.match(/hide_me/) )
121 td.parentNode.removeChild(td);
126 /* builds a friendly print window for this CNs data */
127 function cpdBuildPrintPane(contextRow, record, cn, orgid, depth) {
129 var div = cpdBuildPrintWindow( record, orgid);
131 var whole_cn_text = (cn[0] ? cn[0] + ' ' : '') + cn[1] + (cn[2] ? ' ' + cn[2] : '');
132 $n(div, 'cn').appendChild(text(whole_cn_text));
134 unHideMe($n(div, 'copy_header'));
136 var subtbody = $n(contextRow.nextSibling, 'copies_tbody');
137 var rows = subtbody.getElementsByTagName('tr');
139 for( var r = 0; r < rows.length; r++ ) {
142 var name = row.getAttribute('name');
143 if( name.match(/extras_row/) ) continue; /* hide the copy notes, stat-cats */
144 var clone = row.cloneNode(true);
145 var links = clone.getElementsByTagName('a');
146 for( var i = 0; i < links.length; i++ )
147 links[i].style.display = 'none';
149 $n(div, 'tbody').appendChild(clone);
152 cpdStylePopupWindow(div);
153 openWindow( div.innerHTML);
158 /* hide any open tables and if we've already
159 fleshed this cn, just unhide it */
160 function cpdCheckExisting( contextRow ) {
163 var next = contextRow.nextSibling;
165 if( next && next.getAttribute('templateRow') ) {
166 var obj = cpdNodes[next.id];
167 if(obj.templateRow.className.match(/hide_me/))
168 unHideMe(obj.templateRow);
169 else hideMe(obj.templateRow);
170 existingid = next.id;
173 if(existingid) _debug('row exists with id ' + existingid);
175 for( var o in cpdNodes ) {
176 var node = cpdNodes[o];
177 if( existingid && o == existingid ) continue;
178 hideMe(node.templateRow);
179 removeCSSClass(node.templateRow.previousSibling, 'rdetail_context_row');
182 addCSSClass(contextRow, 'rdetail_context_row');
183 if(existingid) return existingid;
188 function cpdFetchCopies(r) {
190 args.cn = r.getResultObject();
191 var req = new Request(FETCH_COPIES_FROM_VOLUME, args.cn.id());
192 req.request.args = args;
193 req.callback(cpdDrawCopies);
198 function cpdDrawCopies(r) {
200 var copies = r.getResultObject();
202 var copytbody = $n(args.templateRow, 'copies_tbody');
203 var copyrow = copytbody.removeChild($n(copytbody, 'copies_row'));
206 /* unhide before we unhide/clone the parent */
207 unHideMe($n(copyrow, 'age_protect_value'));
208 unHideMe($n(copyrow, 'create_date_value'));
209 unHideMe($n(copyrow, 'active_date_value'));
210 unHideMe($n(copyrow, 'copy_holdable_td'));
213 if(isXUL() || showDueDate) {
214 unHideMe($n(copyrow, 'copy_due_date_td'));
217 for( var i = 0; i < copies.length; i++ ) {
218 var row = copyrow.cloneNode(true);
219 var copyid = copies[i];
220 var pt; if (args.peer_types) pt = args.peer_types[i];
221 if (typeof copyid != 'object') {
222 var req = new Request(FETCH_FLESHED_COPY, copyid);
223 req.callback(cpdDrawCopy);
224 req.request.args = r.args;
225 req.request.row = row;
229 function(copy,row,pt) {
232 'getResultObject' : function() { return copy; },
238 }(copies[i],row,pt), 0
241 copytbody.appendChild(row);
245 function cpdDrawCopy(r) {
246 var copy = r.getResultObject();
248 var pt = r.peer_type;
249 var trow = r.args.templateRow;
251 if (r.args.copy_location && copy.location().name() != r.args.copy_location) {
256 // Make barcode more useful for staff client usage
258 var my_a = document.createElement('a');
259 my_a.appendChild(text(copy.barcode()));
260 my_a.setAttribute("href","javascript:void(0);");
261 my_a.onclick = function() {
262 xulG.new_tab(xulG.urls.XUL_COPY_STATUS, {}, {'from_item_details_new': true, 'barcodes': [copy.barcode()]});
264 $n(row, 'barcode').appendChild(my_a);
267 $n(row, 'barcode').appendChild(text(copy.barcode()));
270 /* show the peer type*/
272 $n(row, 'barcode').appendChild(text(' :: ' + pt));
275 $n(row, 'location').appendChild(text(copy.location().name()));
276 $n(row, 'status').appendChild(text(copy.status().name()));
278 // append comma-separated list of part this copy is linked to
279 if(copy.parts() && copy.parts().length) {
280 unHideMe($n(trow, 'copy_part_label'));
281 unHideMe($n(row, 'copy_part'));
282 for(var i = 0; i < copy.parts().length; i++) {
283 var part = copy.parts()[i];
284 var node = $n(row, 'copy_part');
285 if(i > 0) node.appendChild(text(','));
286 node.appendChild(text(part.label()));
290 /* show the other bibs link */
291 if (copy.peer_record_maps().length > 0) {
292 var l = $n(row, 'copy_multi_home');
295 link_args.page = RRESULT;
296 link_args[PARAM_RTYPE] = RTYPE_LIST;
297 link_args[PARAM_RLIST] = new Array();
298 for (var i = 0; i < copy.peer_record_maps().length; i++) {
299 link_args[PARAM_RLIST].push( copy.peer_record_maps()[i].peer_record() );
301 l.setAttribute('href',buildOPACLink(link_args));
305 /* show the hold link */
306 var l = $n(row, 'copy_hold_link');
308 l.onclick = function() {
313 onComplete : function(){}
318 /* show the book now link */
319 l = $n(row, 'copy_reserve_link');
321 l.onclick = function() {
322 // XXX FIXME this duplicates things in cat/util.js
324 dojo.require("fieldmapper.Fieldmapper");
325 var r = fieldmapper.standardRequest(
327 "open-ils.booking.resources.create_from_copies"],
328 [G.user.session, [copy.id()]]
331 alert("No response from server!");
332 } else if (r.ilsevent != undefined) {
333 alert("Error from server:\n" + js2JSON(r));
335 xulG.auth = {"session": {"key": G.user.session}};
336 xulG.bresv_interface_opts = {"booking_results": r};
337 location.href = "/eg/booking/reservation";
341 if( copy.age_protect() )
342 appendClear($n(row, 'age_protect_value'), text(copy.age_protect().name()));
344 var cd = copy.create_date();
345 cd = cd.replace(/T.*/, '');
346 $n(row, 'create_date_value').appendChild(text(cd));
348 var ad = copy.active_date();
350 ad = ad.replace(/T.*/, '');
351 $n(row, 'active_date_value').appendChild(text(ad));
354 var yes = $('rdetail.yes').innerHTML;
355 var no = $('rdetail.no').innerHTML;
357 if( isTrue(copy.holdable()) &&
358 isTrue(copy.location().holdable()) &&
359 isTrue(copy.status().holdable()) ) {
360 $n(row, 'copy_is_holdable').appendChild(text(yes));
362 $n(row, 'copy_is_holdable').appendChild(text(no));
366 if (isXUL() || showDueDate) {
368 if( copy.circulations() ) {
369 circ = copy.circulations()[0];
371 var due_time = dojo.date.stamp.fromISOString(circ.due_date());
373 $n(row, 'copy_due_date').appendChild(text(dojo.date.locale.format(due_time, {"formatLength": "medium"})));
375 $n(row, 'copy_due_date').appendChild(text(dojo.date.locale.format(due_time, {"selector": "date", "formatLength": "medium"})));
382 r.args.copyrow = row;
383 cpdShowNotes(copy, r.args)
384 cpdShowStats(copy, r.args);
388 function _cpdExtrasInit(args) {
390 var newrid = 'extras_row_' + args.copy.barcode();
391 var newrow = $(newrid);
392 if(!newrow) newrow = args.extrasRow.cloneNode(true);
393 var tbody = $n(newrow, 'extras_tbody');
394 var rowt = $n(tbody, 'extras_row');
397 var cr = args.copyrow;
398 var nr = cr.nextSibling;
399 var np = args.mainTbody;
401 /* insert the extras row into the main table */
402 if(nr) np.insertBefore( newrow, nr );
403 else np.appendChild(newrow);
405 var link = $n(args.copyrow, 'details_link');
406 var link2 = $n(args.copyrow, 'less_details_link');
408 link.id = id + '_morelink';
409 link2.id = id + '_lesslink';
413 link.setAttribute('href',
414 'javascript:unHideMe($("'+link2.id+'")); hideMe($("'+link.id+'"));unHideMe($("'+newrow.id+'"));');
416 link2.setAttribute('href',
417 'javascript:unHideMe($("'+link.id+'")); hideMe($("'+link2.id+'"));hideMe($("'+newrow.id+'"));');
419 return [ tbody, rowt ];
422 function cpdShowNotes(copy, args) {
423 var notes = copy.notes();
424 if(!notes || notes.length == 0) return;
426 var a = _cpdExtrasInit(args);
430 for( var n in notes ) {
432 if(!isTrue(note.pub())) continue;
433 var row = rowt.cloneNode(true);
434 $n(row, 'key').appendChild(text(note.title()));
435 $n(row, 'value').appendChild(text(note.value()));
436 unHideMe($n(row, 'note'));
438 tbody.appendChild(row);
443 function cpdShowStats(copy, args) {
444 var entries = copy.stat_cat_entry_copy_maps();
445 if(!entries || entries.length == 0) return;
447 var visibleStatCat = false;
450 check all copy stat cats; if we find one that's OPAC visible,
451 set the flag and break the loop. If we've found one, or we're
452 in the staff client, build the table. if not, we return doing
453 nothing, as though the stat_cat_entry_copy_map was empty or null
456 for( var n in entries )
458 var entry = entries[n];
459 if(isTrue(entry.stat_cat().opac_visible()))
461 visibleStatCat = true;
466 if(!(isXUL() || visibleStatCat)) return;
468 var a = _cpdExtrasInit(args);
472 for( var n in entries ) {
473 var entry = entries[n];
474 if(!(isXUL() || isTrue(entry.stat_cat().opac_visible()))) continue;
475 var row = rowt.cloneNode(true);
476 $n(row, 'key').appendChild(text(entry.stat_cat().name()));
477 $n(row, 'value').appendChild(text(entry.stat_cat_entry().value()));
478 unHideMe($n(row, 'cat'));
480 tbody.appendChild(row);