]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/javascript/opac/RecordDetailPage.js
added some permission exception handling..
[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 table = elem("table", { width: "100%" } );
60         table.width = "100%";
61
62         var linksDiv = table.insertRow(0);
63         var leftLink = linksDiv.insertCell(0);
64         var rightLink = linksDiv.insertCell(1);
65
66         leftLink.width = "50%";
67         rightLink.width = "50%";
68         leftLink.align = "left";
69         rightLink.align = "right";
70
71         this.parentLink = elem("a",
72                 { href : "javascript:void(0)",
73                         id : "parent_link",
74                   style : "text-decoration:underline" } );
75
76         var a = elem("a", 
77                 {       href : "javascript:void(0)", 
78                         style : "text-decoration:underline" }, null,
79                 "Select a location whose Volumes/Copies you wish to see");
80
81         var obj = this;
82         a.onclick =  function(evt) {
83                 obj.copyLocationTree.toggle(null, 100, 100);
84         };
85
86
87         leftLink.appendChild(a);
88         rightLink.appendChild(this.parentLink);
89         this.mainBox.appendChild(table);
90
91         /* --------------------------------------------- */
92
93                 
94         this.copyLocationTree =  new LocationTree(
95                 globalOrgTree, "record_detail_tree", "record_detail_tree_container" );
96         td = this.copyLocationTree.newSpot();
97         this.copyLocationTree.treeBuilder = buildCustomOrgTree;
98         this.mainBox.appendChild(td);
99
100         this.copyLocationTree.setObjects();
101
102
103
104         this.treeDiv = elem("div");
105         this.mainBox.appendChild(this.treeDiv);
106
107         this.fetchRecord(paramObj.__record); /* sets this.record */
108         this.viewMarc = getById("record_detail_view_marc");
109         
110
111 }
112
113
114 function buildCustomOrgTree(org_node, root) {
115
116         debug("performing custom org tree build");
117         var item;
118
119         if(root) {
120                 item = new WebFXTree(org_node.name());
121                 item.setBehavior('classic');
122         } else {
123                 item = new WebFXTreeItem(org_node.name());
124         }
125
126         item.action = 
127                 "javascript:globalPage.drawCopyTrees(" + 
128                 org_node.id() + ", logicNode.globalDetailRecord );" +
129                 "globalPage.copyLocationTree.hide();"; 
130                 
131         
132         for( var index in org_node.children()) {
133                 var childorg = org_node.children()[index];
134                 if( childorg != null ) {
135                         debug("Adding " + childorg.name() + " to org tree");
136                         var tree_node = buildCustomOrgTree(childorg);
137                         if(tree_node != null)
138                                 item.add(tree_node);
139                 }
140         }
141
142         return item;
143 }
144
145
146 RecordDetailPage.prototype.setViewMarc = function(record) {
147         var marcb = elem( "a", 
148                 { 
149                         href:"javascript:void(0)", 
150                         style: "text-decoration:underline" 
151                 }, 
152                 {}, "View MARC" );
153
154         debug(".ou_type()Setting up view marc callback with record " + record.doc_id());
155         var func = buildViewMARCWindow(record);
156         marcb.onclick = func;
157         this.viewMarc.appendChild(marcb);
158 }
159
160
161 RecordDetailPage.prototype.fetchRecord = function(id) {
162         if(!id) {
163                 debug("No ID in fetchRecord");
164                 return;
165         }
166
167         var req = new RemoteRequest(
168                 "open-ils.search",
169                 "open-ils.search.biblio.record.mods_slim.retrieve",
170                 id );
171
172         var obj = this;
173         req.setCompleteCallback(
174                 function() { 
175                         obj.record = req.getResultObject();
176                         globalDetailRecord = obj.record;
177                         obj.copyLocationTree.widget = 
178                                 buildCustomOrgTree(globalOrgTree, obj.record, true);
179                         obj.drawRecord(obj.record); 
180                         obj.setViewMarc(obj.record);
181                 } 
182         );
183
184         req.send();
185 }
186
187
188 RecordDetailPage.prototype.drawRecord = function(record) {
189
190         var title_cell                  = getById("record_detail_title_cell");
191         var author_cell         = getById("record_detail_author_cell");
192         var isbn_cell                   = getById("record_detail_isbn_cell");
193
194         var edition_cell                = getById("record_detail_edition_cell");
195         var pubdate_cell                = getById("record_detail_pubdate_cell");
196         var publisher_cell      = getById("record_detail_publisher_cell");
197
198         var subject_cell                = getById("record_detail_subject_cell");
199         var tcn_cell                    = getById("record_detail_tcn_cell");
200         var resource_cell               = getById("record_detail_resource_cell");
201         var pic_cell                    = getById("record_detail_pic_cell");
202
203         add_css_class(title_cell,               "detail_item_cell");
204         add_css_class(author_cell,              "detail_item_cell");
205         add_css_class(isbn_cell,                "detail_item_cell");
206         add_css_class(edition_cell,     "detail_item_cell");
207         add_css_class(pubdate_cell,     "detail_item_cell");
208         add_css_class(publisher_cell, "detail_item_cell");
209         add_css_class(subject_cell,     "detail_item_cell");
210         add_css_class(tcn_cell,                 "detail_item_cell");
211         add_css_class(resource_cell,    "detail_item_cell");
212
213         title_cell.appendChild(
214                 createAppTextNode(normalize(record.title())));
215         author_cell.appendChild(
216                 createAppTextNode(normalize(record.author())));
217         isbn_cell.appendChild(
218                 createAppTextNode(record.isbn()));
219
220         edition_cell.appendChild(
221                 createAppTextNode(record.edition()));
222         pubdate_cell.appendChild(
223                 createAppTextNode(record.pubdate()));
224         publisher_cell.appendChild(
225                 createAppTextNode(record.publisher()));
226
227         subject_cell.appendChild(
228                 createAppTextNode(record.subject()));
229         tcn_cell.appendChild(
230                 createAppTextNode(record.tcn()));
231
232
233
234
235         var resource = record.types_of_resource()[0];
236         var r_pic = elem("img", 
237                 { src: "/images/" + resource + ".jpg" } );
238         resource_cell.appendChild(r_pic);
239         resource_cell.appendChild(createAppTextNode(" "));
240
241         resource_cell.appendChild(
242                 createAppTextNode(record.types_of_resource()));
243
244
245         pic_cell.appendChild(this.mkImage(record));
246
247         var orgUnit = globalSelectedLocation;
248         if(!orgUnit) orgUnit = globalLocation;
249
250         this.drawCopyTrees(orgUnit, record);
251 }
252
253 /* sets up the cover art image */
254 RecordDetailPage.prototype.mkImage = function(record) {
255
256         var isbn = record.isbn();
257         if(isbn) isbn = isbn.replace(/\s+/,"");
258         else isbn = "";
259
260         var big_pic = elem("a", {
261                 href : "http://images.amazon.com/images/P/" +isbn + ".01.LZZZZZZZ.jpg",
262                 title : "Click for larger image" } );
263
264         var img_src = "http://images.amazon.com/images/P/" +isbn + ".01.MZZZZZZZ.jpg";
265         var pic = elem ( "img", { src : img_src }, { border : "0px none" });
266         big_pic.appendChild(pic);
267
268         return big_pic;
269 }
270
271
272 /* if sync, it is a synchronous call */
273 RecordDetailPage.prototype.grabCopyTree = function(record, orgUnit, callback, sync) {
274
275         var orgIds = new Array();
276         if(orgUnit.constructor == Array) {
277                 for(var x = 0; x < orgUnit.length; x++) {
278                         orgIds.push(orgUnit[x].id());
279                 }
280         } else {
281                 orgIds.push(orgUnit.id());
282         }
283
284         debug("Grabbing copy tree for " + orgIds);
285
286         var req = new RemoteRequest(
287                 "open-ils.cat",
288                 "open-ils.cat.asset.copy_tree.retrieve",
289                 null, record.doc_id(), orgIds );        
290
291         var obj = this;
292
293         if(sync) { /* synchronous call */
294                 req.send(true);
295                 callback(req.getResultObject());
296
297         } else {
298                 req.setCompleteCallback( 
299                         function(r) { callback(r.getResultObject()); });
300                 req.send();
301         }
302 }
303
304
305 /* entry point for displaying the copy details pane */
306 RecordDetailPage.prototype.drawCopyTrees = function(orgUnit, record) {
307
308         debug("Got ORG unit " + orgUnit);
309         orgUnit = findOrgUnit(orgUnit);
310
311         debug("OrgUnit depth is: " + findOrgType(orgUnit.ou_type()).depth());
312
313         //this.displayLocationTree(record);
314
315         /* display a 'hold on' message */
316         this.treeDiv.appendChild(elem("br"));
317         this.treeDiv.appendChild(elem("br"));
318
319         /* everyone gets to see the location tree */
320         var depth = parseInt(findOrgType(orgUnit.ou_type()).depth());
321         if(depth != 0) {
322                 this.treeDiv.appendChild(elem("div", null, null, "Loading copy information..."));
323                 if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols()))
324                         this.displayParentLink(orgUnit, record);
325                 this.displayTrees(orgUnit, record);
326         }
327 }
328
329
330 /*
331 RecordDetailPage.prototype.displayLocationTree = function(record) {
332 }
333 */
334
335
336
337 /* displays a link to view info for the parent org 
338         if showMe == true, we don't search for the parent, 
339         but use the given orgUnit as the link point */
340 RecordDetailPage.prototype.displayParentLink = function(orgUnit, record, showMe) {
341
342         var region = orgUnit;
343         if(!showMe)
344                 region = findOrgUnit(orgUnit.parent_ou());
345
346         var href = this.parentLink;
347         removeChildren(href);
348
349         href.appendChild(createAppTextNode(
350                 "View Volumes/Copies for " + region.name()));
351
352         var obj = this;
353         href.onclick = function() { 
354
355                 removeChildren(obj.treeDiv);
356                 obj.treeDiv.appendChild(elem("br"));
357                 obj.treeDiv.appendChild(elem("br"));
358                 obj.treeDiv.appendChild(elem("div", null, null, "Loading copy information..."));
359
360                 /* allows the above message to be displayed */
361                 setTimeout(function() { obj.displayTrees(region, record, true) }, 100); 
362
363                 if(showMe)
364                         obj.displayParentLink(orgUnit, record);
365                 else
366                         obj.displayParentLink(orgUnit, record, true);
367         }
368
369         var reg_div = createAppElement("div");
370         //reg_div.appendChild(href);
371         this.mainBox.insertBefore(reg_div, this.treeDiv);
372 }
373
374 /* displays copy info for orgUnit and all of it's children.
375         if orgUnit is a region (depth == 1), then we just show
376         all of our children.  if it's a branch, sub-branch, etc.
377         the current branch as well as all of it's children are displayed */
378 RecordDetailPage.prototype.displayTrees = function(orgUnit, record, sync) {
379         var obj = this;
380         var orgs = orgUnit.children();
381         if(!orgs) orgs = [];
382
383         if(parseInt(findOrgType(orgUnit.ou_type()).can_have_vols()))
384                 orgs.unshift(orgUnit);
385
386         this.grabCopyTree(record, orgs, 
387                 function(tree) {
388                         obj.displayCopyTree(tree, "Volumes/Copies for " + orgUnit.name() );
389                 }, sync );
390 }
391
392
393 /*  displays a single copy tree */
394 RecordDetailPage.prototype.displayCopyTree = function(tree, title) {
395         
396         debug("Displaying copy tree for " + title);
397
398         var treeDiv =  this.treeDiv;
399         removeChildren(treeDiv);
400         add_css_class( treeDiv, "copy_tree_div" );
401
402         var table = createAppElement("table");
403         add_css_class(table, "copy_tree_table");
404         var header_row = table.insertRow(table.rows.length);
405         add_css_class(header_row, "top_header_row");
406         var header = header_row.insertCell(header_row.cells.length);
407         header.colSpan = 3;
408         header.setAttribute("colspan", 3);
409         var bold = createAppElement("b");
410         bold.appendChild(createAppTextNode(title));
411         header.appendChild(bold);
412
413         var row2                = table.insertRow(table.rows.length);
414         var cell1       = row2.insertCell(row2.cells.length);
415         var cell2       = row2.insertCell(row2.cells.length);
416         var cell3       = row2.insertCell(row2.cells.length);
417         var cell4       = row2.insertCell(row2.cells.length);
418
419         cell1.appendChild(createAppTextNode("Callnumber"));
420         cell2.appendChild(createAppTextNode("Location"));
421         cell3.appendChild(createAppTextNode("Barcode(s)"));
422         cell4.appendChild(createAppTextNode("Availability"));
423
424         add_css_class(cell1, "detail_header_cell");
425         add_css_class(cell2, "detail_header_cell");
426         add_css_class(cell3, "detail_header_cell");
427         add_css_class(cell4, "detail_header_cell");
428
429         if(tree.length == 0) {
430                 var row = table.insertRow(table.rows.length);
431                 row.insertCell(0).appendChild(
432                         createAppTextNode("No copies available for this location"));
433         }
434
435         var x = 0;
436         for( var i in tree ) {
437                 var row = table.insertRow(table.rows.length);
438                 if(x%2) add_css_class(row, "copy_tree_row_highlight");
439                 var volume = tree[i];
440
441                 var cell1 = row.insertCell(row.cells.length);
442                 add_css_class(cell1, "detail_item_cell");
443                 cell1.appendChild(createAppTextNode(volume.label()));
444                 var cell2 = row.insertCell(row.cells.length);
445                 add_css_class(cell2, "detail_item_cell");
446                 cell2.appendChild(createAppTextNode(
447                         findOrgUnit(volume.owning_lib()).name()));
448
449                 var cell3 = row.insertCell(row.cells.length);
450                 add_css_class(cell3, "detail_item_cell");
451                 cell3.appendChild(createAppTextNode(" "));
452
453                 var cell4 = row.insertCell(row.cells.length);
454                 add_css_class(cell4, "detail_item_cell");
455                 cell4.appendChild(createAppTextNode(" "));
456                 
457                 var copies = volume.copies();
458                 var c = 0;
459                 while(c < copies.length) {
460                         var copy = copies[c];
461                         if(c == 0) { /* put the first barcode in the same row as the callnumber */
462
463                                 cell3.removeChild(cell3.childNodes[0]);
464                                 cell3.appendChild(createAppTextNode(copy.barcode()));
465                                 cell4.removeChild(cell4.childNodes[0]);
466
467                                 cell4.appendChild(createAppTextNode(
468                                         find_list(globalCopyStatus, 
469                                                 function(i) { return (i.id() == copy.status()); } ).name() ));
470
471                         } else {
472
473                                 var row = table.insertRow(table.rows.length);
474                                 if(x%2) add_css_class(row, "copy_tree_row_highlight");
475                                 row.insertCell(0).appendChild(createAppTextNode(" "));
476                                 row.insertCell(1).appendChild(createAppTextNode(" "));
477
478                                 var ce = row.insertCell(2);
479                                 var status_cell = row.insertCell(3);
480                                 add_css_class(ce, "detail_item_cell");
481                                 add_css_class(status_cell, "detail_item_cell");
482                                 ce.appendChild(createAppTextNode(copy.barcode()));
483
484                                 status_cell.appendChild(createAppTextNode(
485                                         find_list(globalCopyStatus, 
486                                                 function(i) { return (i.id() == copy.status()); } ).name() ));
487                         }
488
489                         c++;
490                 }
491                 x++;
492         }
493
494         treeDiv.appendChild(table);
495 }
496
497