]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/templates/default/opac/parts/misc_util.tt2
Merge remote-tracking branch 'remotes/working/user/dbs/ttopac-speech-input' into...
[working/Evergreen.git] / Open-ILS / web / templates / default / opac / parts / misc_util.tt2
1 [% 
2     # Extract MARC fields from XML
3     #   get_marc_attrs( { marc_xml => doc } )
4     BLOCK get_marc_attrs;
5         xml = args.marc_xml;
6         args.isbn = xml.findnodes('//*[@tag="020"]/*[@code="a"]').shift.textContent;
7         args.upc = xml.findnodes('//*[@tag="024"]/*[@code="a"]').textContent;
8         args.issn = xml.findnodes('//*[@tag="022"]/*[@code="a"]').textContent;
9         args.title = xml.findnodes('//*[@tag="245"]/*[@code="a"]').textContent;
10         args.author = xml.findnodes('//*[@tag="100"]/*[@code="a"]').textContent;
11         args.publisher = xml.findnodes('//*[@tag="260"]/*[@code="b"]').textContent;
12         args.pubdate = xml.findnodes('//*[@tag="260"]/*[@code="c"]').textContent;
13         args.edition = xml.findnodes('//*[@tag="250"]/*[@code="a"]').textContent ||
14             xml.findnodes('//*[@tag="534"]/*[@code="b"]').textContent ||
15             xml.findnodes('//*[@tag="775"]/*[@code="b"]').textContent;
16         phys = xml.findnodes(
17             '//*[@tag="300"]/*[@code="a" or @code="b" or @code="c" or @code="e"]'
18         );
19         phys_content = [];
20         FOR p IN phys; phys_content.push(p.textContent); END;
21         args.phys_desc = phys_content.join("");
22
23         # MARC Callnumber
24         args.marc_cn = xml.findnodes('//*[@tag="092" or @tag="099"]/*').textContent;
25
26         # clean up the ISBN
27         args.isbn_clean = args.isbn.replace('\ .*', '');
28
29         args.holdings = [];
30         args.uris = [];
31
32         # URI info is in volumes/volume/uris/volume, instead of uri element
33         FOR volume IN xml.findnodes('//*[local-name()="volumes"]/*[local-name()="volume"]');
34
35             # Check volume visibility - could push this into XPath
36             vol.label = volume.getAttribute('label');
37             vol.id = volume.getAttribute('id');
38             NEXT IF volume.getAttribute('opac_visible') == 'false';
39             NEXT IF volume.getAttribute('deleted') == 'true';
40
41             IF vol.label == '##URI##';
42                 FOR uri IN volume.findnodes('./*[local-name()="uris"]/*[local-name()="volume"]');
43                     res.href = uri.getAttribute('href');
44                     res.link = uri.getAttribute('label');
45                     res.note = uri.getAttribute('use_restriction');
46                     args.uris.push(res);
47                 END;
48                 NEXT;
49             ELSE;
50                 copies = volume.findnodes('./*[local-name()="copies"]/*[local-name()="copy"]');
51                 FOR copy IN copies;
52                     # Check copy visibility
53                     cp.deleted = copy.getAttribute('deleted');    
54                     cp.visible = copy.getAttribute('opac_visible');
55                     NEXT IF (cp.deleted == 'true' OR cp.visible == 'false');
56
57                     # Iterate through all of the children to determine visibility
58                     FOR node IN cp.childNodes;
59                         NEXT IF cp.visible == 'false';
60                         vis = node.getAttribute('opac_visible');
61                         del = node.getAttribute('deleted');
62                         IF vis == 'false' or del == 'true';
63                             cp.visible = 'false';
64                         END;
65                     END;
66
67                     NEXT IF cp.visible == 'false';
68                     
69                     loc = copy.findnodes('./*[local-name()="location"]');
70                     circlib = copy.findnodes('./*[local-name()="circlib"]');
71                     status = copy.findnodes('./*[local-name()="status"]');
72
73                     holding = {
74                         label => vol.label,
75                         location => loc.textContent,
76                         library => circlib.textContent,
77                         status => status.textContent
78                         barcode => copy.getAttribute('barcode')
79                     };
80                     args.holdings.push(holding);
81                 END;
82             END;
83         END;
84
85         # Extract the copy count summary
86         count_type = (ctx.is_staff) ? 'staff' : 'public';
87         xpath = '//*[local-name()="counts"]/*[local-name()="count"][@type="' _ count_type _ '"]';
88         FOR node IN xml.findnodes(xpath);
89             args.copy_counts = {};
90             FOR attr IN ['count', 'available', 'unshadow', 'transcendant']; 
91                 args.copy_counts.$attr = node.getAttribute(attr);
92             END;
93         END;
94
95         # "mattype" == "custom marc format specifier"
96         FOR icon_style IN ['mattype', 'item_type']; 
97             node = xml.findnodes(
98                 '//*[local-name()="attributes"]/*[local-name()="field"][@name="' _ icon_style _ '"]');
99             IF node;
100                 args.format_label = node.getAttribute('coded-value')
101                 args.format_icon = ctx.media_prefix _ '/images/format_icons/' _ icon_style _ '/' _ node.textContent _ '.png';
102                 LAST;
103             END;
104         END;
105     END;
106
107     BLOCK get_hold_status;
108         IF hold.hold.status == 4;
109             l("Available");
110             IF ahr.shelf_expire_time;
111                 l('<br/>Expires [_1]', 
112                     date.format(ctx.parse_datetime(ahr.shelf_expire_time), DATE_FORMAT));
113             END;
114         ELSIF hold.hold.estimated_wait AND hold.hold.estimated_wait > 0;
115             # estimated wait is delivered as seconds.
116             SET hwait = POSIX.ceil(hold.hold.estimated_wait / 86400);
117             l("Estimated wait: [quant,_1,day,days]", hwait);
118         ELSIF hold.hold.status == 3;
119             l("In Transit");
120         ELSIF hold.hold.status < 3;
121             l("Waiting for copy");
122         END;
123     END;
124 %]