1 var globalRecordDetailPage = null;
2 RecordDetailPage.prototype = new Page();
3 RecordDetailPage.prototype.constructor = RecordDetailPage;
4 RecordDetailPage.baseClass = Page.constructor;
6 var globalDetailRecord;
8 function RecordDetailPage() {
9 if( globalRecordDetailPage != null )
10 return globalRecordDetailPage;
11 this.searchBar = new SearchBarChunk();
14 RecordDetailPage.prototype.setPageTrail = function() {
15 var box = getById("page_trail");
18 var d = this.buildTrailLink("start",true);
22 d = this.buildTrailLink("advanced_search",true);
27 var b = this.buildTrailLink("mr_result", true);
30 box.appendChild(this.buildDivider());
34 box.appendChild(this.buildDivider());
36 box.appendChild(this.buildTrailLink("record_result", true));
37 } catch(E) {} /* doesn't work when deep linking */
39 box.appendChild(this.buildDivider());
41 this.buildTrailLink("record_detail",false));
45 RecordDetailPage.instance = function() {
46 if( globalRecordDetailPage != null )
47 return globalRecordDetailPage;
48 return new RecordDetailPage();
51 RecordDetailPage.prototype.init = function() {
52 debug("Initing RecordDetailPage");
56 RecordDetailPage.prototype.draw = function() {
57 this.mainBox = getById("record_detail_copy_info");
59 var linksDiv = elem("div");
60 var leftLink = elem("div", { style: "width: 50%;text-align: left" });
61 var rightLink = elem("div", { style: "width: 50%;text-align: right"});
62 linksDiv.appendChild(leftLink);
63 linksDiv.appendChild(rightLink);
64 this.mainBox.appendChild(linksDiv);
66 this.mainBox.appendChild(elem("br"));
67 this.parentLink = elem("a",
68 { href : "javascript:void(0)",
70 style : "text-decoration:underline" } );
73 { href : "javascript:void(0)",
74 style : "text-decoration:underline" }, null,
75 "Select a location whose Volumes/Copies you wish to see");
78 a.onclick = function(evt) {
79 obj.copyLocationTree.toggle(null, 100, 100);
82 leftLink.appendChild(a);
83 rightLink.appendChild(this.parentLink);
85 /* --------------------------------------------- */
88 this.copyLocationTree = new LocationTree(
89 globalOrgTree, "record_detail_tree", "record_detail_tree_container" );
90 td = this.copyLocationTree.newSpot();
91 this.copyLocationTree.treeBuilder = buildCustomOrgTree;
92 this.mainBox.appendChild(td);
94 this.copyLocationTree.setObjects();
98 this.treeDiv = elem("div");
99 this.mainBox.appendChild(this.treeDiv);
101 this.fetchRecord(paramObj.__record); /* sets this.record */
102 this.viewMarc = getById("record_detail_view_marc");
108 function buildCustomOrgTree(org_node, root) {
110 debug("performing custom org tree build");
114 item = new WebFXTree(org_node.name());
115 item.setBehavior('classic');
117 item = new WebFXTreeItem(org_node.name());
121 "javascript:globalPage.drawCopyTrees(" +
122 org_node.id() + ", logicNode.globalDetailRecord );" +
123 "globalPage.copyLocationTree.hide();";
126 for( var index in org_node.children()) {
127 var childorg = org_node.children()[index];
128 if( childorg != null ) {
129 debug("Adding " + childorg.name() + " to org tree");
130 var tree_node = buildCustomOrgTree(childorg);
131 if(tree_node != null)
140 RecordDetailPage.prototype.setViewMarc = function(record) {
141 var marcb = elem( "a",
143 href:"javascript:void(0)",
144 style: "text-decoration:underline"
148 debug(".ou_type()Setting up view marc callback with record " + record.doc_id());
149 var func = buildViewMARCWindow(record);
150 marcb.onclick = func;
151 this.viewMarc.appendChild(marcb);
155 RecordDetailPage.prototype.fetchRecord = function(id) {
157 debug("No ID in fetchRecord");
161 var req = new RemoteRequest(
163 "open-ils.search.biblio.record.mods_slim.retrieve",
167 req.setCompleteCallback(
169 obj.record = req.getResultObject();
170 globalDetailRecord = obj.record;
171 obj.copyLocationTree.widget =
172 buildCustomOrgTree(globalOrgTree, obj.record, true);
173 obj.drawRecord(obj.record);
174 obj.setViewMarc(obj.record);
182 RecordDetailPage.prototype.drawRecord = function(record) {
184 var title_cell = getById("record_detail_title_cell");
185 var author_cell = getById("record_detail_author_cell");
186 var isbn_cell = getById("record_detail_isbn_cell");
188 var edition_cell = getById("record_detail_edition_cell");
189 var pubdate_cell = getById("record_detail_pubdate_cell");
190 var publisher_cell = getById("record_detail_publisher_cell");
192 var subject_cell = getById("record_detail_subject_cell");
193 var tcn_cell = getById("record_detail_tcn_cell");
194 var resource_cell = getById("record_detail_resource_cell");
195 var pic_cell = getById("record_detail_pic_cell");
197 add_css_class(title_cell, "detail_item_cell");
198 add_css_class(author_cell, "detail_item_cell");
199 add_css_class(isbn_cell, "detail_item_cell");
200 add_css_class(edition_cell, "detail_item_cell");
201 add_css_class(pubdate_cell, "detail_item_cell");
202 add_css_class(publisher_cell, "detail_item_cell");
203 add_css_class(subject_cell, "detail_item_cell");
204 add_css_class(tcn_cell, "detail_item_cell");
205 add_css_class(resource_cell, "detail_item_cell");
207 title_cell.appendChild(
208 createAppTextNode(normalize(record.title())));
209 author_cell.appendChild(
210 createAppTextNode(normalize(record.author())));
211 isbn_cell.appendChild(
212 createAppTextNode(record.isbn()));
214 edition_cell.appendChild(
215 createAppTextNode(record.edition()));
216 pubdate_cell.appendChild(
217 createAppTextNode(record.pubdate()));
218 publisher_cell.appendChild(
219 createAppTextNode(record.publisher()));
221 subject_cell.appendChild(
222 createAppTextNode(record.subject()));
223 tcn_cell.appendChild(
224 createAppTextNode(record.tcn()));
229 var resource = record.types_of_resource()[0];
230 var r_pic = elem("img",
231 { src: "/images/" + resource + ".jpg" } );
232 resource_cell.appendChild(r_pic);
233 resource_cell.appendChild(createAppTextNode(" "));
235 resource_cell.appendChild(
236 createAppTextNode(record.types_of_resource()));
239 pic_cell.appendChild(this.mkImage(record));
241 var orgUnit = globalSelectedLocation;
242 if(!orgUnit) orgUnit = globalLocation;
244 this.drawCopyTrees(orgUnit, record);
247 /* sets up the cover art image */
248 RecordDetailPage.prototype.mkImage = function(record) {
250 var isbn = record.isbn();
251 if(isbn) isbn = isbn.replace(/\s+/,"");
254 var big_pic = elem("a", {
255 href : "http://images.amazon.com/images/P/" +isbn + ".01.LZZZZZZZ.jpg",
256 title : "Click for larger image" } );
258 var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg";
259 var pic = elem ( "img", { src : img_src }, { border : "0px none" });
260 big_pic.appendChild(pic);
266 /* if sync, it is a synchronous call */
267 RecordDetailPage.prototype.grabCopyTree = function(record, orgUnit, callback, sync) {
269 var orgIds = new Array();
270 if(orgUnit.constructor == Array) {
271 for(var x = 0; x < orgUnit.length; x++) {
272 orgIds.push(orgUnit[x].id());
275 orgIds.push(orgUnit.id());
278 debug("Grabbing copy tree for " + orgIds);
280 var req = new RemoteRequest(
282 "open-ils.cat.asset.copy_tree.retrieve",
283 null, record.doc_id(), orgIds );
287 if(sync) { /* synchronous call */
289 callback(req.getResultObject());
292 req.setCompleteCallback(
293 function(r) { callback(r.getResultObject()); });
299 /* entry point for displaying the copy details pane */
300 RecordDetailPage.prototype.drawCopyTrees = function(orgUnit, record) {
302 debug("Got ORG unit " + orgUnit);
303 orgUnit = findOrgUnit(orgUnit);
305 debug("OrgUnit depth is: " + findOrgType(orgUnit.ou_type()).depth());
307 //this.displayLocationTree(record);
309 /* display a 'hold on' message */
310 this.treeDiv.appendChild(elem("br"));
311 this.treeDiv.appendChild(elem("br"));
313 /* everyone gets to see the location tree */
314 var depth = parseInt(findOrgType(orgUnit.ou_type()).depth());
316 this.treeDiv.appendChild(elem("div", null, null, "Loading copy information..."));
317 if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols()))
318 this.displayParentLink(orgUnit, record);
319 this.displayTrees(orgUnit, record);
325 RecordDetailPage.prototype.displayLocationTree = function(record) {
331 /* displays a link to view info for the parent org
332 if showMe == true, we don't search for the parent,
333 but use the given orgUnit as the link point */
334 RecordDetailPage.prototype.displayParentLink = function(orgUnit, record, showMe) {
336 var region = orgUnit;
338 region = findOrgUnit(orgUnit.parent_ou());
340 var href = this.parentLink;
341 removeChildren(href);
343 href.appendChild(createAppTextNode(
344 "View Volumes/Copies for " + region.name()));
347 href.onclick = function() {
349 removeChildren(obj.treeDiv);
350 obj.treeDiv.appendChild(elem("br"));
351 obj.treeDiv.appendChild(elem("br"));
352 obj.treeDiv.appendChild(elem("div", null, null, "Loading copy information..."));
354 /* allows the above message to be displayed */
355 setTimeout(function() { obj.displayTrees(region, record, true) }, 100);
358 obj.displayParentLink(orgUnit, record);
360 obj.displayParentLink(orgUnit, record, true);
363 var reg_div = createAppElement("div");
364 reg_div.appendChild(href);
365 this.mainBox.insertBefore(reg_div, this.treeDiv);
368 /* displays copy info for orgUnit and all of it's children.
369 if orgUnit is a region (depth == 1), then we just show
370 all of our children. if it's a branch, sub-branch, etc.
371 the current branch as well as all of it's children are displayed */
372 RecordDetailPage.prototype.displayTrees = function(orgUnit, record, sync) {
374 var orgs = orgUnit.children();
377 if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols()))
378 orgs.unshift(orgUnit);
380 this.grabCopyTree(record, orgs,
382 obj.displayCopyTree(tree, "Volumes/Copies for " + orgUnit.name() );
387 /* displays a single copy tree */
388 RecordDetailPage.prototype.displayCopyTree = function(tree, title) {
390 debug("Displaying copy tree for " + title);
392 var treeDiv = this.treeDiv;
393 removeChildren(treeDiv);
394 add_css_class( treeDiv, "copy_tree_div" );
396 var table = createAppElement("table");
397 add_css_class(table, "copy_tree_table");
398 var header_row = table.insertRow(table.rows.length);
399 add_css_class(header_row, "top_header_row");
400 var header = header_row.insertCell(header_row.cells.length);
402 header.setAttribute("colspan", 3);
403 var bold = createAppElement("b");
404 bold.appendChild(createAppTextNode(title));
405 header.appendChild(bold);
407 var row2 = table.insertRow(table.rows.length);
408 var cell1 = row2.insertCell(row2.cells.length);
409 var cell2 = row2.insertCell(row2.cells.length);
410 var cell3 = row2.insertCell(row2.cells.length);
411 var cell4 = row2.insertCell(row2.cells.length);
413 cell1.appendChild(createAppTextNode("Callnumber"));
414 cell2.appendChild(createAppTextNode("Location"));
415 cell3.appendChild(createAppTextNode("Barcode(s)"));
416 cell4.appendChild(createAppTextNode("Availability"));
418 add_css_class(cell1, "detail_header_cell");
419 add_css_class(cell2, "detail_header_cell");
420 add_css_class(cell3, "detail_header_cell");
421 add_css_class(cell4, "detail_header_cell");
423 if(tree.length == 0) {
424 var row = table.insertRow(table.rows.length);
425 row.insertCell(0).appendChild(
426 createAppTextNode("No copies available for this location"));
430 for( var i in tree ) {
431 var row = table.insertRow(table.rows.length);
432 if(x%2) add_css_class(row, "copy_tree_row_highlight");
433 var volume = tree[i];
435 var cell1 = row.insertCell(row.cells.length);
436 add_css_class(cell1, "detail_item_cell");
437 cell1.appendChild(createAppTextNode(volume.label()));
438 var cell2 = row.insertCell(row.cells.length);
439 add_css_class(cell2, "detail_item_cell");
440 cell2.appendChild(createAppTextNode(
441 findOrgUnit(volume.owning_lib()).name()));
443 var cell3 = row.insertCell(row.cells.length);
444 add_css_class(cell3, "detail_item_cell");
445 cell3.appendChild(createAppTextNode(" "));
447 var cell4 = row.insertCell(row.cells.length);
448 add_css_class(cell4, "detail_item_cell");
449 cell4.appendChild(createAppTextNode(" "));
451 var copies = volume.copies();
453 while(c < copies.length) {
454 var copy = copies[c];
455 if(c == 0) { /* put the first barcode in the same row as the callnumber */
457 cell3.removeChild(cell3.childNodes[0]);
458 cell3.appendChild(createAppTextNode(copy.barcode()));
459 cell4.removeChild(cell4.childNodes[0]);
461 cell4.appendChild(createAppTextNode(
462 find_list(globalCopyStatus,
463 function(i) { return (i.id() == copy.status()); } ).name() ));
467 var row = table.insertRow(table.rows.length);
468 if(x%2) add_css_class(row, "copy_tree_row_highlight");
469 row.insertCell(0).appendChild(createAppTextNode(" "));
470 row.insertCell(1).appendChild(createAppTextNode(" "));
472 var ce = row.insertCell(2);
473 var status_cell = row.insertCell(3);
474 add_css_class(ce, "detail_item_cell");
475 add_css_class(status_cell, "detail_item_cell");
476 ce.appendChild(createAppTextNode(copy.barcode()));
478 status_cell.appendChild(createAppTextNode(
479 find_list(globalCopyStatus,
480 function(i) { return (i.id() == copy.status()); } ).name() ));
488 treeDiv.appendChild(table);