lp1863252 toward geosort
[Evergreen.git] / Open-ILS / src / templates / opac / parts / record / copy_table.tt2
1 [%-
2
3 # If being used in serial mode, flatten list of units so that they can be
4 # used like one long list of copies without changing so much code below.
5 IF serial_holdings;
6     copies = [];
7     FOREACH h IN serial_holdings;
8         units = h.units.slice(0); # copy
9         FOREACH unit IN units;
10             unit.holding_label = h.label;
11         END;
12         copies = copies.merge(units);
13     END;
14 END;
15
16 FOREACH copy_info IN copies;
17     IF copy_info.call_number_label != '##URI##';
18         has_copies = 'true';
19     END;
20     IF copy_info.part_label != '';
21         has_parts = 'true';
22     END;
23     IF has_parts && has_copies;
24         LAST;
25     END;
26 END;
27 -%]
28 [%- MACRO display_ou_distance(ou) BLOCK;
29     km = ctx.ou_distances.$ou;
30     IF km && km != '-1';
31         IF ctx.get_org_setting(ctx.physical_loc || ctx.search_ou, 'opac.geographic_proximity_in_miles');
32             distance = l('[_1] mi', POSIX.sprintf('%.01f', km / 1.609));
33         ELSE;
34             distance = l('[_1] km', POSIX.sprintf('%.01f', km));
35         END;
36     ELSE;
37         distance = '-';
38     END;
39 %]
40 [% distance %]
41 [%- END %]
42 [%-
43 IF has_copies or ctx.foreign_copies;
44   depth = CGI.param('copy_depth').defined ? CGI.param('copy_depth') : CGI.param('depth').defined ? CGI.param('depth') : ctx.copy_summary.last.depth;
45   total_copies = ctx.copy_summary.$depth.count;
46 %]
47 [% use_courses = (ctx.get_org_setting(ctx.aou_tree.id, 'circ.course_materials_opt_in') == 1) ? 1 : 0 %]
48 [% IF ctx.geo_sort %]
49 <form method="GET">
50 [% FOREACH p IN CGI.params.keys; NEXT IF p == 'geographic-location' %]
51   <input type="hidden" name="[% p | html %]" value="[% CGI.params.$p | html %]"/>
52 [% END %]
53 <span with="50%">
54 <th colspan="6">
55     [% l("Sort by distance from:") %]
56     <input type="text" id="geographic-location-box" name="geographic-location" aria-label="[% l('Enter address or postal code') %]" placeholder="[% l('Enter address/postal code') %]" class="search-box" x-webkit-speech="" value="[% p = 'geographic-location'; CGI.params.$p %]"></input>
57     <button type="submit" class="opac-button">[% l('Go') %]</button>
58 </span>
59 [% p = 'geographic-location'; IF CGI.params.$p && !ctx.has_valid_coords %]
60 <span class="alert">[% l('Sorry, your address is not recognized') %]</span>
61 [% END %]
62 </form>
63 [% p = 'geographic-location'; IF CGI.params.$p && ctx.has_valid_coords %]
64 <form method="GET">
65 [% FOREACH p IN CGI.params.keys; NEXT IF p == 'geographic-location' %]
66   <input type="hidden" name="[% p | html %]" value="[% CGI.params.$p | html %]"/>
67 [% END %]
68    <button type="submit" class="opac-button">[% l('Use default item sort') %]</button>
69 </form>
70 [% END %]
71 [% END %]
72 <table class="table_no_border_space table_no_cell_pad table_no_border" width="100%" id="rdetails_status">
73     <thead>
74         <tr>
75             [% IF serial_holdings -%]
76             <th scope='col'>[% l("Issue Label") %]</th>
77             [%- ELSE -%]
78             <th scope='col'>[% l("Location") %]</th>
79             [%- END %]
80             <th scope='col'>[% l("Call Number / Copy Notes") %]</th>
81             [%- IF has_parts == 'true' %]
82             <th scope='col'>[% l("Part") %]</th>
83             [%- END %]
84             <th scope='col'>[% l("Barcode") %]</th>
85             <th scope='col'>[% l("Shelving Location") %]</th>
86             [% IF ctx.is_staff || use_courses %]
87             <th scope='col'>[% l("Circulation Modifier") %]</th>
88             [% END %]
89             [% IF ctx.is_staff %]
90             <th scope='col'>[% l("Age Hold Protection") %]</th>
91             <th scope='col'>[% l("Active/Create Date") %]</th>
92             [%- END %]
93             [%- IF ctx.is_staff OR serial_holdings %]
94             <th scope='col'>[% l("Holdable?") %]</th>
95             [%- END %]
96             <th scope='col'>[% l("Status") %]</th>
97             <th scope='col'>[% l("Due Date") %]</th>
98             [%- IF use_courses %]
99             <th scope='col'>[% l("Courses") %]</th>
100             [%- END %]
101             [%- IF ctx.geo_sort && ctx.has_valid_coords %]
102             <th scope='col'>[% l("Distance") %]</th>
103             [%- END %]
104         </tr>
105     </thead>
106     <tbody class="copy_details_table">
107 [%- FOREACH peer IN ctx.foreign_copies;
108         FOREACH bib IN peer.foreign_copy_maps; %]
109     <tr class="copy_details_row"><td>
110     [%- bib_lib_name = ctx.get_aou(bib.target_copy.circ_lib).name | html;
111         l("[_1] (foreign item)", bib_lib_name); -%]
112         <ul><li>
113             <span class="bib_peer_type">[% bib.peer_type.name | html %]</span>:
114             <a href="[% mkurl(ctx.opac_root _ '/record/' _ bib.target_copy.call_number.record) %]">
115                 <span class="bib_peer_title">[% peer.title | html %]</span> / 
116                 <span class="bib_peer_author">[% peer.author | html %]</span>
117             </a>
118         </li></ul>
119     </td>
120     <td>[% bib.target_copy.call_number.label | html %]</td>
121     <td>[% bib.target_copy.barcode | html %]</td>
122     <td>[% bib.target_copy.location.name | html %]</td>
123     <td>[% bib.target_copy.status.name | html %]</td>
124     <td>[% date.format(ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),DATE_FORMAT) %]</td>
125     [%- IF ctx.get_org_setting(CGI.param('loc'))
126         OR use_courses %]
127     <td></td>
128     [%- END %]
129     [%- IF ctx.geo_sort && ctx.has_valid_coords %]
130     <td>[% display_ou_distance(bib.target_copy.circ_lib) %]</td>
131     [%- END %]
132 </tr>
133    [%- END; # FOREACH peer
134 END; # FOREACH bib
135 -%]
136         [%- last_cn = 0;
137         FOR copy_info IN copies;
138             callnum = copy_info.call_number_label;
139             NEXT IF callnum == '##URI##';
140
141             callnum_prefix = copy_info.call_number_prefix_label;
142             IF callnum_prefix != "";
143                 callnum = callnum_prefix _ " " _ callnum;
144             END;
145
146             callnum_suffix = copy_info.call_number_suffix_label;
147             IF callnum_suffix != "";
148                 callnum = callnum  _ " " _ callnum_suffix;
149             END;
150         -%]
151         <tr class="copy_details_offers_row" property="offers" typeof="Offer">
152             [%- IF serial_holdings %]<td class='rdetail-issue-issue'>
153                 [%- copy_info.holding_label | html; -%]
154             </td>
155             [%- ELSE %]<td>
156             [%- INCLUDE "opac/parts/library_name_link.tt2"; -%]
157                 <link property="businessFunction" href="http://purl.org/goodrelations/v1#LeaseOut">
158                 <meta property="price" content="0.00">
159             </td>[% END %]
160             <td><span property="sku">[% callnum | html %]</span> [% IF ctx.get_org_setting(CGI.param('loc') 
161                 OR ctx.aou_tree.id, 'sms.enable') == 1 %](<a href="[% mkurl(ctx.opac_root _ '/sms_cn', 
162                {copy_id => copy_info.id}) %];rec=[%- ctx.bre_id -%]" rel="nofollow" vocab="">Text</a>)[% END %]</td>
163             [%- IF has_parts == 'true' %]
164             <td>[% copy_info.part_label | html %]</td>
165             [%- END %]
166             <td property="serialNumber">
167                 [% copy_info.barcode | html -%]
168                 [% IF ctx.is_staff %]
169                   [%- IF ctx.is_browser_staff %]
170                     <a target="_blank" href="[% ctx.base_path %]/staff/cat/item/[% copy_info.id %]">[% l('view') %]</a>
171                     [% IF ctx.has_perm('UPDATE_COPY', copy_info.circ_lib) 
172                         OR ctx.has_perm('UPDATE_COPY', copy_info.call_number_owning_lib) %]
173                         <span> | </span>
174                         <a href="javascript:;" onclick='window.open("[% ctx.base_path %]/staff/cat/item/[% copy_info.id %]/edit", "_blank");'>[% l('edit') %]</a>
175                     [% END %]
176                   [% ELSE %]
177                     <a onclick="xulG.new_tab(xulG.urls.XUL_COPY_STATUS, {}, {'from_item_details_new': true, 'barcodes': ['[%- copy_info.barcode | html | replace('\'', '\\\'') -%]']})"
178                         href="javascript:;">[% l('view') %]</a>
179                     [%# if the user can edit copies, show the copy edit link %]
180                     [% IF ctx.has_perm('UPDATE_COPY', copy_info.circ_lib) 
181                         OR ctx.has_perm('UPDATE_COPY', copy_info.call_number_owning_lib) %]
182                         <span> | </span>
183                         <a href="javascript:;" 
184                             onclick="xulG.volume_item_creator({copy_id : [% copy_info.id %]})">
185                             [% l(' edit') %]
186                         </a>
187                     [% END %]
188                   [% END %]
189                 [% END %]
190                 [%- IF attrs.gtin13;
191                     '<meta property="gtin13" content="' _ attrs.gtin13 _ '" />';
192                 END; -%]
193             </td>
194             <td property="availableAtOrFrom">[%- INCLUDE "opac/parts/location_name_link.tt2"; -%]</td>
195
196             [% IF copy_info.courses.size > 0 || ctx.is_staff %]
197             <td>[% copy_info.circ_modifier | html %]</td>
198             [% ELSIF use_courses %]
199             <td></td>
200             [% END %]
201             [% IF ctx.is_staff %]
202             <td>
203                 [% copy_info.age_protect ?
204                     ctx.get_crahp(copy_info.age_protect).name : l('None') | html %]
205             </td>
206             <td>[% 
207                 IF ctx.get_org_setting(copy_info.circ_lib, 'circ.holds.age_protect.active_date') == 1;
208                     disp_date = copy_info.active_date ? copy_info.active_date : copy_info.create_date;
209                 ELSE;
210                     disp_date = copy_info.create_date;
211                 END;
212             
213                 IF disp_date;
214                     date.format(
215                         ctx.parse_datetime(disp_date),
216                         DATE_FORMAT
217                     );
218                 ELSE;
219                    '-';
220                 END;
221             %]</td>
222             [% END # is_staff %]
223             [% IF ctx.is_staff OR serial_holdings %]
224             <td>[%  # Show copy/volume hold links to staff (without
225                 # checking whether they have permissions to do those).
226                 overall_holdable = (
227                     copy_info.holdable == 't' AND
228                     copy_info.location_holdable == 't' AND
229                     copy_info.status_holdable == 't'
230                 );
231                 IF overall_holdable;
232                     hold_link = '';
233                     param_sep = l(" / ");
234
235                     # Only staff get to place copy or volume holds
236                     IF ctx.is_staff; 
237                         hold_link = '<a href="' _
238                             mkurl(ctx.opac_root _ '/place_hold', {
239                                 hold_target => copy_info.id,
240                                 hold_type => 'C',
241                                 hold_source_page => mkurl()
242                             }) _ '">' _ l('Copy hold') _ '</a>';
243                         IF copy_info.call_number != last_cn;
244                             last_cn = copy_info.call_number; 
245                             hold_link = hold_link _ param_sep;
246                             hold_link = hold_link _ '<a href="' _
247                                 mkurl(ctx.opac_root _ '/place_hold', {
248                                     hold_target => copy_info.call_number,
249                                     hold_type => 'V',
250                                     hold_source_page => mkurl()
251                                 }) _ '">' _ l('Volume hold') _ '</a>';
252                         END;
253                         IF serial_holdings;
254                             hold_link = hold_link _ param_sep;
255                         END;
256                     END; 
257                     IF serial_holdings; 
258                         hold_link = hold_link _
259                             '<a class="rdetail-issue-place-hold" href="' _
260                             mkurl(ctx.opac_root _ '/place_hold', {
261                                 hold_target => copy_info.issuance,
262                                 hold_type => 'I',
263                                 hold_source_page => mkurl()
264                             }) _ '" rel="nofollow" vocab="">' _ l('Issue hold') _ '</a>';
265                     END; 
266
267                     hold_link;
268                 ELSE; 
269                     l("Not holdable");
270                 END %]</td>
271             [%- END %]
272             <td>[%-
273                 schema_copy_status.${copy_info.status_code};
274                 copy_info.copy_status | html;
275             -%]</td>
276             <td>[%
277                 IF copy_info.due_date;
278                     date.format(
279                         ctx.parse_datetime(copy_info.due_date, copy_info.circ_circ_lib),
280                         DATE_FORMAT
281                     );
282                 ELSE;
283                     '-';
284                 END %]</td>
285             [%- IF use_courses %]
286             <td>[%- FOREACH course IN copy_info.courses %]
287                 <div>[% course.course_number %]</div>
288             [% END %]</td>
289             [% END %]
290             [%- IF ctx.geo_sort && ctx.has_valid_coords %]
291                <td>[% display_ou_distance(copy_info.circ_lib) %]</td>
292             [%- END %]
293         </tr>
294
295         [% IF copy_info.notes; %]
296             [% FOREACH note IN copy_info.notes; %]
297                 <tr><td>&nbsp;</td><td class="copy_note" colspan="4" property="description"><strong>[% note.title | html %]:</strong> [% note.value | html %]</td></tr>
298             [% END %]
299         [% END %]
300
301         [% IF copy_info.tags; %]
302             [% FOREACH tag IN copy_info.tags; %]
303                 <tr class="copy_tag_row">
304                     <td>&nbsp;</td>
305                     <td class="copy_tag" colspan="4">
306                         <span class="copy_tag_type_label">[% tag.tag_type.label _ ": " | html %]</span>
307                         <span class="copy_tag_value">
308                             [% IF tag.url %]
309                             <a href="[% tag.url | html %]">
310                             [% END %]
311                                 [% tag.value | html %]
312                             [% IF tag.url %]
313                             </a>
314                             [% END %]
315                         </span>
316                     </td>
317                 <tr>
318             [% END %]
319         [% END %]
320
321 <tr><td>
322 [%- IF copy_info.peer_bib_marc.size > 0;
323 '<ul>';
324     FOREACH bib IN copy_info.peer_bib_marc;
325         attrs = {marc_xml => bib};
326         PROCESS get_marc_attrs args=attrs %]
327 [%- IF attrs.bibid != ctx.bre_id; -%]
328     <li property="isRelatedTo" typeof="Product">
329         [%- # Map the bound-with relationship -%]
330         <a href="[% mkurl(ctx.opac_root _ '/record/' _ attrs.bibid) %]" property="url">
331             <span class="bib_peer_title" property="name">[% attrs.title | html %]</span>
332             / <span class="bib_peer_author">[% attrs.author | html %]</span>
333         </a>
334     </li>
335 [%- END; # IF attrs.bibid %]
336 [%- END; # FOREACH bib in copy_info.peer_bib_marc
337 '</ul>';
338     END # IF copy_info.peer_bib_marc.size
339 %]
340 </td></tr>
341 [%- END; # FOR copy_info
342 %]
343         <tr>
344         [%- IF ctx.copy_offset > 0 AND NOT serial_holdings;
345             new_offset = ctx.copy_offset - ctx.copy_limit;
346             IF new_offset < 0; new_offset = 0; END %]
347             <td>
348                 <a href="[% mkurl('', {copy_offset => new_offset, copy_limit => ctx.copy_limit}) %]">&laquo; [%
349                     l('Previous [_1]', ctx.copy_offset - new_offset) %]</a>
350             </td>
351         [%- END %]
352         [%- IF copies.size >= ctx.copy_limit AND NOT serial_holdings AND (ctx.copy_offset + ctx.copy_limit < total_copies) %]
353             <td>
354                 <a href="[% mkurl('', {copy_offset => ctx.copy_offset + ctx.copy_limit, copy_limit => ctx.copy_limit}) %]">[%
355                     l('Next [_1]', ctx.copy_limit) %] &raquo;</a>
356             </td>
357         [%- END %]
358         </tr>
359         [% IF NOT serial_holdings -%]
360         <tr>
361             <td>
362                 [%- more_copies_limit = 50 %] [%# TODO: config %]
363                 [%- IF  ctx.copy_limit != more_copies_limit AND copies.size >= ctx.copy_limit AND ctx.copy_limit < total_copies %]
364                     <div class="rdetail_show_copies">
365                         <img src="[% ctx.media_prefix %]/images/plus_sign.png[% ctx.cache_key %]" alt="[% l('Show more copies icon') %]"/>
366                         <a href="[% mkurl('', {copy_limit => more_copies_limit, copy_offset => 0}) %]">[% l('Show more copies') %]</a>
367                     </div>
368                 [%- ELSIF ctx.copy_limit == more_copies_limit %]
369                     <div  class="rdetail_show_copies">
370                         <img src="[% ctx.media_prefix %]/images/minus_sign.png[% ctx.cache_key %]" alt="[% l('Show fewer copies icon') %]"/>
371                         <a href="[% mkurl('', {copy_limit => 0, copy_offset => 0}) %]">[% l('Show fewer copies') %]</a>
372                     </div>
373                 [%- END %]
374             </td>
375         </tr>
376         [%- END %]
377     </tbody>
378 </table>
379 [% END; %]