]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/record/authors.tt2
LP1615805 No inputs after submit in patron search (AngularJS)
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / record / authors.tt2
1 [%-  
2
3 PROCESS "opac/parts/relators.tt2";
4
5 author_cnt = 0;
6 authors = [
7     {
8         type => 'author', 
9         label => l('Author'),
10         xpath => '//*[@tag="100"]|//*[@tag="110"]|//*[@tag="111"]'
11     }, {
12         type => 'added', 
13         label => l('Added Author'),
14         xpath => '//*[@tag="700"]|//*[@tag="710"]|//*[@tag="711"]'
15     }, {
16         type => 'cast', 
17         label => l('Cast'),
18         xpath => '//*[@tag="511"][@ind1="1"]'
19     }, {
20         type => 'notes', 
21         label => l('Author Notes: '),
22         xpath => '' # Comes from added content...
23     }
24 ];
25
26 BLOCK find_hl_value;
27     outlist = [];
28     norm_needle = PROCESS normalize_string(unnorm_string=needle);
29     FOREACH hl IN attrs.display_field_list;
30         norm_value = PROCESS normalize_string(unnorm_string=hl.value);
31         outlist.push(hl.$f) IF norm_value == norm_needle;
32     END;
33
34     outlist.0;
35 END;
36
37 BLOCK normalize_string;
38     unnorm_string.replace('[#"^$\+\-,\.:;&|\[\]()]', ' ').replace('\s+',' ').replace('^\s+','').replace('\s+$','');
39 END;
40
41 BLOCK normalize_qterm;
42     PROCESS normalize_string(unnorm_string=subfield.textContent);
43 END;
44
45 BLOCK normalize_authors;
46     link_term = link_term _ ' ' _ sf;
47     sf_raw = PROCESS normalize_qterm;
48     qterm = qterm _ ' ' _ sf_raw;
49     indexed_term = 1;
50 END;
51
52 BLOCK build_author_links;
53     FOR node IN ctx.marc_xml.findnodes(xpath);
54         author_cnt = author_cnt + 1;
55         contrib_ref = '#schemacontrib' _ author_cnt;
56         iprop = ''; # schema.org item type / property
57         link_term = ''; # Linked term (e.g. Personal name + Fuller form of name)
58         supp_term = ''; # Supplementary terms
59         qterm = ''; # Search query
60         tlabels = [];
61         birthdate = '';
62         deathdate = '';
63         graphics = [];
64         tag = node.getAttribute('tag');
65         FOR subfield IN node.childNodes;
66             indexed_term = '';
67             NEXT UNLESS subfield.nodeName == "subfield";
68             code = subfield.getAttribute('code');
69             IF code == '4';
70                 relcode = subfield.textContent.substr(0,3);
71                 tlabels.push( relators.$relcode || label );
72             END;
73             IF code == 'e';
74                 tlabels.push( subfield.textContent() );
75                 indexed_term = 1;
76             END;
77             IF code == '6';
78                target_field = tag;
79                linked_fields = [subfield.textContent()];
80                get_linked_880s;
81             END;
82             NEXT UNLESS code.match('[a-z]');
83             sf = subfield.textContent | html;
84
85             # Only Persons have birth/death dates in schema.org
86             # Match personal/corporate/conference MODS subfields
87             IF tag.substr(1,2) == '00';
88                 IF code.match('[abcqu]');
89                     PROCESS normalize_authors;
90                 END;
91                 IF code.match('d');
92                     IF subfield.textContent.match('^\s*\d{4}');
93                         birthdate = subfield.textContent.replace('^\s*(\d{4}).*$', '$1');
94                     END;
95                     IF subfield.textContent.match('-\d{4}.*$');
96                         deathdate = subfield.textContent.replace('^\s*.{4}\-(\d{4}).*$', '$1');
97                     END;
98                     indexed_term = 1;
99                     sf_raw = PROCESS normalize_qterm;
100                     qterm = qterm _ ' ' _ sf_raw;
101                 END;
102             ELSIF tag.substr(1,2) == '10';
103                 IF code.match('[abcdn]');
104                     PROCESS normalize_authors;
105                 END;
106             ELSIF code.match('[acdeq]');
107                 PROCESS normalize_authors;
108             END;
109             UNLESS indexed_term;
110                 supp_term = supp_term _ ' ' _ sf;
111             END;
112         END;
113         url = mkurl(ctx.opac_root _ '/results', {query => qterm.replace('^\s*(.*?)\s*$', '$1'), qtype => 'author'}, stop_parms.merge(expert_search_parms, general_search_parms, browse_search_parms, facet_search_parms));
114         tlabel = tlabels.join(', ');
115         tlabels = [];
116         author_type = (tlabel || label) | html;
117         
118         # schema.org changes
119         IF type == 'author';
120             IF tag.substr(1,2) == '10' && args.schema.itemtype && args.schema.itemtype.match('MusicAlbum');
121                 iprop = ' typeof="MusicGroup" property="byArtist"';
122             ELSIF tag.substr(1,2) == '00';
123                 iprop = ' typeof="Person" property="author"';
124             ELSE;
125                 iprop = ' typeof="Organization" property="author"';
126             END;
127         ELSIF type == 'added';
128             IF tag.substr(1,2) == '00';
129                 iprop = ' typeof="Person" property="contributor';
130             ELSE;
131                 iprop = ' typeof="Organization" property="contributor';
132             END;
133             IF relcode;
134                 iprop = iprop _ ' http://id.loc.gov/vocabulary/relators/' _ relcode;
135             END;
136             iprop = iprop _ '"';
137         END;
138         desc_str = '<span property="description">(' _ author_type _ ').</span>';
139         link_term = link_term.replace('^\s+', '');
140         match_term = link_term _ ' ' _ birthdate _ ' ' _ deathdate;
141         matching_author_hl = PROCESS find_hl_value needle=match_term f=attrs.hl_field;
142         authtml = '<span class="rdetail-author-div"' _ iprop _ ' resource="' _ contrib_ref _ '"><a href="' _ url _ '"><span resource="' _ contrib_ref _ '">';
143         IF iprop; authtml = authtml _ '<span property="name">'; END;
144         IF matching_author_hl;
145             IF type == 'cast';
146                 link_str = matching_author_hl _ '</span></a> ' _ desc_str _ '</span>';
147                 authtml = authtml _ accordion(link_str, null, 'this.previousElementSibling');
148             ELSE;
149                 authtml = authtml _ matching_author_hl;
150             END;
151         ELSE;
152             IF type == 'cast';
153                 link_str = link_term _ '</span></a> ' _ desc_str _ '</span>';
154                 authtml = authtml _ accordion(link_str, null, 'this.previousElementSibling');
155             ELSE;
156                 authtml = authtml _ link_term;
157             END;
158         END;
159         IF iprop; authtml = authtml _ '</span>'; END;
160         IF birthdate AND !matching_author_hl;
161             authtml = authtml _ ' <span property="birthDate">' _ birthdate _ '</span>-';
162         END;
163         IF deathdate AND !matching_author_hl;
164             authtml = authtml _ '<span property="deathDate">' _ deathdate _ '</span>';
165         END;
166         IF type != 'cast'; authtml = authtml _ '</span></a>'; END; # End search link
167
168         # Display supplemental terms (mostly about the author's work)
169         IF supp_term;
170             authtml = authtml _ ' ' _ supp_term;
171         END;
172
173         # Display linked 880 fields
174         FOREACH link880 IN graphics;
175             diratt = '';
176             IF link880.dir;
177                 diratt = ' dir="' _ link880.dir _ '"';
178             END;
179             authlist_graphical.push('<span class="graphic880"' _ diratt _ '>' _ link880.value _ '</span>');
180         END;
181         IF type != 'cast';
182             authtml = authtml _ desc_str;
183             authtml = authtml _ '</span>'; # End author span
184         END;
185         authlist.push(authtml);
186     END;
187 END;
188 %]
189
190 <div class='rdetail_authors_div'>
191 [%- FOREACH author IN authors;
192     NEXT UNLESS author.xpath; 
193     authlist = [];
194     authlist_graphical = [];
195     authstr = '';
196     graphical_string = '';
197     PROCESS build_author_links(
198         xpath=author.xpath, label=author.label, type=author.type
199     );
200     IF authlist_graphical.size;
201     %] <div class="content_field"> [%
202         accordion(authlist_graphical.join());
203     %] </div> [% END;
204     IF authlist.size;
205     %] <div class="content_field"> [%
206         accordion(authlist.join());
207     %] </div> [% END;
208 END %]
209 </div>
210
211