]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/RecordDetailPage.js
299bac8d02353565688c92258d6d1271e9e8318e
[Evergreen.git] / Open-ILS / src / javascript / opac / RecordDetailPage.js
1 var globalRecordDetailPage = null;
2 RecordDetailPage.prototype                                      = new Page();
3 RecordDetailPage.prototype.constructor  = RecordDetailPage;
4 RecordDetailPage.baseClass                                      = Page.constructor;
5
6 var globalDetailRecord;
7
8 function RecordDetailPage() {
9         if( globalRecordDetailPage != null )
10                 return globalRecordDetailPage;
11         this.searchBar  = new SearchBarChunk();
12 }
13
14 RecordDetailPage.prototype.setPageTrail = function() {
15         var box = getById("page_trail");
16         if(!box) return;
17
18         var d = this.buildTrailLink("start",true);
19         if(d) {
20                 box.appendChild(d);
21         } else {
22                 d = this.buildTrailLink("advanced_search",true);
23                 if(d)
24                         box.appendChild(d);
25         }
26
27         var b = this.buildTrailLink("mr_result", true);
28
29         if(b) {
30                 box.appendChild(this.buildDivider());
31                 box.appendChild(b);
32         }
33
34         box.appendChild(this.buildDivider());
35         try {
36                 box.appendChild(this.buildTrailLink("record_result", true));
37         } catch(E) {} /* doesn't work when deep linking */
38
39         box.appendChild(this.buildDivider());
40         box.appendChild(
41                 this.buildTrailLink("record_detail",false));
42 }
43
44
45 RecordDetailPage.instance = function() {
46         if( globalRecordDetailPage != null )
47                 return globalRecordDetailPage;
48         return new RecordDetailPage();
49 }
50
51 RecordDetailPage.prototype.init = function() {
52         debug("Initing RecordDetailPage");
53         this.draw();
54 }
55
56 RecordDetailPage.prototype.draw = function() {
57         this.mainBox = getById("record_detail_copy_info");
58
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);
65
66         this.mainBox.appendChild(elem("br"));
67         this.parentLink = elem("a",
68                 { href : "javascript:void(0)",
69                         id : "parent_link",
70                   style : "text-decoration:underline" } );
71
72         var a = elem("a", 
73                 {       href : "javascript:void(0)", 
74                         style : "text-decoration:underline" }, null,
75                 "Select a location whose Volumes/Copies you wish to see");
76
77         var obj = this;
78         a.onclick =  function(evt) {
79                 obj.copyLocationTree.toggle(null, 100, 100);
80         };
81
82         leftLink.appendChild(a);
83         rightLink.appendChild(this.parentLink);
84
85         /* --------------------------------------------- */
86
87                 
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);
93
94         this.copyLocationTree.setObjects();
95
96
97
98         this.treeDiv = elem("div");
99         this.mainBox.appendChild(this.treeDiv);
100
101         this.fetchRecord(paramObj.__record); /* sets this.record */
102         this.viewMarc = getById("record_detail_view_marc");
103         
104
105 }
106
107
108 function buildCustomOrgTree(org_node, root) {
109
110         debug("performing custom org tree build");
111         var item;
112
113         if(root) {
114                 item = new WebFXTree(org_node.name());
115                 item.setBehavior('classic');
116         } else {
117                 item = new WebFXTreeItem(org_node.name());
118         }
119
120         item.action = 
121                 "javascript:globalPage.drawCopyTrees(" + 
122                 org_node.id() + ", logicNode.globalDetailRecord );" +
123                 "globalPage.copyLocationTree.hide();"; 
124                 
125         
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)
132                                 item.add(tree_node);
133                 }
134         }
135
136         return item;
137 }
138
139
140 RecordDetailPage.prototype.setViewMarc = function(record) {
141         var marcb = elem( "a", 
142                 { 
143                         href:"javascript:void(0)", 
144                         style: "text-decoration:underline" 
145                 }, 
146                 {}, "View MARC" );
147
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);
152 }
153
154
155 RecordDetailPage.prototype.fetchRecord = function(id) {
156         if(!id) {
157                 debug("No ID in fetchRecord");
158                 return;
159         }
160
161         var req = new RemoteRequest(
162                 "open-ils.search",
163                 "open-ils.search.biblio.record.mods_slim.retrieve",
164                 id );
165
166         var obj = this;
167         req.setCompleteCallback(
168                 function() { 
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);
175                 } 
176         );
177
178         req.send();
179 }
180
181
182 RecordDetailPage.prototype.drawRecord = function(record) {
183
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");
187
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");
191
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");
196
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");
206
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()));
213
214         edition_cell.appendChild(
215                 createAppTextNode(record.edition()));
216         pubdate_cell.appendChild(
217                 createAppTextNode(record.pubdate()));
218         publisher_cell.appendChild(
219                 createAppTextNode(record.publisher()));
220
221         subject_cell.appendChild(
222                 createAppTextNode(record.subject()));
223         tcn_cell.appendChild(
224                 createAppTextNode(record.tcn()));
225
226
227
228
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(" "));
234
235         resource_cell.appendChild(
236                 createAppTextNode(record.types_of_resource()));
237
238
239         pic_cell.appendChild(this.mkImage(record));
240
241         var orgUnit = globalSelectedLocation;
242         if(!orgUnit) orgUnit = globalLocation;
243
244         this.drawCopyTrees(orgUnit, record);
245 }
246
247 /* sets up the cover art image */
248 RecordDetailPage.prototype.mkImage = function(record) {
249
250         var isbn = record.isbn();
251         if(isbn) isbn = isbn.replace(/\s+/,"");
252         else isbn = "";
253
254         var big_pic = elem("a", {
255                 href : "http://images.amazon.com/images/P/" +isbn + ".01.LZZZZZZZ.jpg",
256                 title : "Click for larger image" } );
257
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);
261
262         return big_pic;
263 }
264
265
266 /* if sync, it is a synchronous call */
267 RecordDetailPage.prototype.grabCopyTree = function(record, orgUnit, callback, sync) {
268
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());
273                 }
274         } else {
275                 orgIds.push(orgUnit.id());
276         }
277
278         debug("Grabbing copy tree for " + orgIds);
279
280         var req = new RemoteRequest(
281                 "open-ils.cat",
282                 "open-ils.cat.asset.copy_tree.retrieve",
283                 null, record.doc_id(), orgIds );        
284
285         var obj = this;
286
287         if(sync) { /* synchronous call */
288                 req.send(true);
289                 callback(req.getResultObject());
290
291         } else {
292                 req.setCompleteCallback( 
293                         function(r) { callback(r.getResultObject()); });
294                 req.send();
295         }
296 }
297
298
299 /* entry point for displaying the copy details pane */
300 RecordDetailPage.prototype.drawCopyTrees = function(orgUnit, record) {
301
302         debug("Got ORG unit " + orgUnit);
303         orgUnit = findOrgUnit(orgUnit);
304
305         debug("OrgUnit depth is: " + findOrgType(orgUnit.ou_type()).depth());
306
307         //this.displayLocationTree(record);
308
309         /* display a 'hold on' message */
310         this.treeDiv.appendChild(elem("br"));
311         this.treeDiv.appendChild(elem("br"));
312
313         /* everyone gets to see the location tree */
314         var depth = parseInt(findOrgType(orgUnit.ou_type()).depth());
315         if(depth != 0) {
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);
320         }
321 }
322
323
324 /*
325 RecordDetailPage.prototype.displayLocationTree = function(record) {
326 }
327 */
328
329
330
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) {
335
336         var region = orgUnit;
337         if(!showMe)
338                 region = findOrgUnit(orgUnit.parent_ou());
339
340         var href = this.parentLink;
341         removeChildren(href);
342
343         href.appendChild(createAppTextNode(
344                 "View Volumes/Copies for " + region.name()));
345
346         var obj = this;
347         href.onclick = function() { 
348
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..."));
353
354                 /* allows the above message to be displayed */
355                 setTimeout(function() { obj.displayTrees(region, record, true) }, 100); 
356
357                 if(showMe)
358                         obj.displayParentLink(orgUnit, record);
359                 else
360                         obj.displayParentLink(orgUnit, record, true);
361         }
362
363         var reg_div = createAppElement("div");
364         reg_div.appendChild(href);
365         this.mainBox.insertBefore(reg_div, this.treeDiv);
366 }
367
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) {
373         var obj = this;
374         var orgs = orgUnit.children();
375         if(!orgs) orgs = [];
376
377         if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols()))
378                 orgs.unshift(orgUnit);
379
380         this.grabCopyTree(record, orgs, 
381                 function(tree) {
382                         obj.displayCopyTree(tree, "Volumes/Copies for " + orgUnit.name() );
383                 }, sync );
384 }
385
386
387 /*  displays a single copy tree */
388 RecordDetailPage.prototype.displayCopyTree = function(tree, title) {
389         
390         debug("Displaying copy tree for " + title);
391
392         var treeDiv =  this.treeDiv;
393         removeChildren(treeDiv);
394         add_css_class( treeDiv, "copy_tree_div" );
395
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);
401         header.colSpan = 3;
402         header.setAttribute("colspan", 3);
403         var bold = createAppElement("b");
404         bold.appendChild(createAppTextNode(title));
405         header.appendChild(bold);
406
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);
412
413         cell1.appendChild(createAppTextNode("Callnumber"));
414         cell2.appendChild(createAppTextNode("Location"));
415         cell3.appendChild(createAppTextNode("Barcode(s)"));
416         cell4.appendChild(createAppTextNode("Availability"));
417
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");
422
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"));
427         }
428
429         var x = 0;
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];
434
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()));
442
443                 var cell3 = row.insertCell(row.cells.length);
444                 add_css_class(cell3, "detail_item_cell");
445                 cell3.appendChild(createAppTextNode(" "));
446
447                 var cell4 = row.insertCell(row.cells.length);
448                 add_css_class(cell4, "detail_item_cell");
449                 cell4.appendChild(createAppTextNode(" "));
450                 
451                 var copies = volume.copies();
452                 var c = 0;
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 */
456
457                                 cell3.removeChild(cell3.childNodes[0]);
458                                 cell3.appendChild(createAppTextNode(copy.barcode()));
459                                 cell4.removeChild(cell4.childNodes[0]);
460
461                                 cell4.appendChild(createAppTextNode(
462                                         find_list(globalCopyStatus, 
463                                                 function(i) { return (i.id() == copy.status()); } ).name() ));
464
465                         } else {
466
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(" "));
471
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()));
477
478                                 status_cell.appendChild(createAppTextNode(
479                                         find_list(globalCopyStatus, 
480                                                 function(i) { return (i.id() == copy.status()); } ).name() ));
481                         }
482
483                         c++;
484                 }
485                 x++;
486         }
487
488         treeDiv.appendChild(table);
489 }
490
491