]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/header.tt2
lp1481844 Change Available Copies Display
[working/Evergreen.git] / Open-ILS / src / templates / opac / parts / header.tt2
1 [%- USE money = format(l('$%.2f'));
2     USE date;
3     USE CGI = CGI_utf8;
4     USE POSIX;
5     USE HTML;
6     SET DATE_FORMAT = l('%m/%d/%Y');
7     PROCESS "opac/parts/config.tt2";
8
9     # Don't wrap in l() here; do that where this format string is actually used.
10     SET HUMAN_NAME_FORMAT = '[_1] [_2] [_3] [_4] [_5]';
11
12     is_advanced = CGI.param("_adv").size;
13     is_special = CGI.param("_special").size;
14
15     #variables to use to remove parameters via mkurk
16     expert_search_parms = ['tag','subfield','term','_special'];
17     general_search_parms = ['page','sort','query','bool','contains','pubdate'];
18     browse_search_parms = ['fi:has_browse_entry','bterm','blimit','bpivot'];
19     facet_search_parms = ['facet'];
20
21
22     # -----------------------------------------------------------------------------
23     # mkurl( destination_page, params_to_set, params_to_clear )
24     #
25     # Current page, updated params:
26     # mkurl('', {foo => 'bar', boo => 'baz'});
27     #
28     # New page, one param is a list:
29     # mkurl('http://flarg.baz/squz', {foo => 'bar', boo => ['baz', 'faz']});
30     #
31     # New page, clear all existing params before applying new ones:
32     # mkurl('/fuz/buster', {foo => 'bar', boo => 'baz'}, 1); 
33     #
34     # Current page, clear 'some_param' from the existing params:
35     # mkurl('', {foo => 'bar', boo => 'baz'}, ['some_param']);
36     #
37     # Current page to a named anchor 'copies'
38     # mkurl('', {}, [], 'copies');
39     MACRO mkurl(page, params, clear_params, named_anchor) BLOCK;
40
41         # clone the query string to avoid clobberation
42         cgi = CGI.new(CGI.query_string);
43
44         # remove requested params
45         IF clear_params.0; # array
46             FOR p IN clear_params; cgi.delete(p); END;
47         ELSIF clear_params;
48             cgi.delete_all();
49         END;
50
51         # x and y are artifacts of using <input type="image" /> tags 
52         # instead of true submit buttons, and their values are never used.
53         cgi.delete('x', 'y'); 
54
55         # apply user params
56         FOR k IN params.keys;
57             encoded = [];
58             max = params.$k.max;
59
60             # The following commented-out line can be fooled. Its replacement
61             # below is what you really mean.
62             # list = (params.$k.0 OR max == -1) ? params.$k : [params.$k];
63             list = params.$k.list;
64
65             IF list.size == 0; NEXT; END;
66             # CGI croaks on already-decoded strings.  force-encode to be safe.
67             FOR p IN list; encoded.push(ctx.encode_utf8(p)); END;
68             foo = cgi.param("-name", k, "-values", encoded);
69         END;
70
71         # for url brevity, remove any params that have no value
72         FOR p IN cgi.param;
73             val = cgi.param(p);
74             IF val == ''; cgi.delete(p); END;
75
76             # Delete POST vars unless we asked for them
77             UNLESS CGI.url_param(p).defined OR params.defined(p);
78                 cgi.delete(p);
79             END;
80         END;
81
82         final = named_anchor ? '#' _ named_anchor : '';
83
84         IF page;
85             IF cgi.query_string;
86                 page _ '?' _ cgi.query_string _ final;
87             ELSE;
88                 page _ final;
89             END;
90         ELSE;
91             # staying on the current page
92             cgi.url("-absolute" => 1, "-path" => 1, "-query" => 1) _ final;
93         END;
94     END;
95
96     # Dojo is required to use the copy locations advanced search filter,
97     # therefore, it should always be enabled.
98     want_dojo = 1;
99
100     use_autosuggest = ctx.get_cgf("opac.use_autosuggest");
101
102     IF use_autosuggest.enabled == "t";
103         want_dojo = 1;
104     END;
105
106     IF ctx.google_books_preview;
107         want_dojo = 1;
108     END;
109
110     IF ENV.OILS_NOVELIST_URL;
111         want_dojo = 1;
112     END;
113
114     # Especially useful for image 'alt' tags and link title tags,
115     # where the content may need to be unique (making it longer)
116     # but should not exceed 75 chars for ideal screen reader support.
117     # usage: html_text_attr('title', 'Link to item I Have A Super Long Title')
118     # the full HTML attribute key="value" is produced
119     MACRO html_text_attr(name, value) BLOCK;
120         IF value.length >= 75;
121             value = value.substr(71, value.length, '...');                        
122         END;                                                                   
123         value = value.replace('\s*$', ''); # remove trailing whitespace          
124         HTML.attributes($name => value); 
125     END;
126
127     MACRO img_alt(text) BLOCK;
128         html_text_attr('alt', text);
129     END;
130 %]