]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/header.tt2
76b23141872fc00de94a00907d4667b1383aa069
[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 || CGI.param("query").size;
13     is_special = CGI.param("_special").size;
14
15     # Check if we want to show the detail record view.  Doing this
16     # here because we don't want to repeat logic in multiple other
17     # files, nor do we want to add a new tt2 file just for this.  The
18     # below is currently needed for parts/result/table.tt2,
19     # parts/searchbar.tt2, and results.tt2.
20     show_detail_view = 0;
21     IF CGI.param("detail_record_view").defined;
22         show_detail_view = CGI.param("detail_record_view");
23     ELSIF show_more_details.default == "true" OR
24           show_more_details.default == "hide";
25         show_detail_view = 1;
26     END;
27
28     #variables to use to remove parameters via mkurk
29     expert_search_parms = ['tag','subfield','term','_special'];
30     general_search_parms = ['page','sort','query','bool','contains','pubdate'];
31     browse_search_parms = ['fi:has_browse_entry','bterm','blimit','bpivot'];
32     facet_search_parms = ['facet'];
33
34
35     # -----------------------------------------------------------------------------
36     # mkurl( destination_page, params_to_set, params_to_clear )
37     #
38     # Current page, updated params:
39     # mkurl('', {foo => 'bar', boo => 'baz'});
40     #
41     # New page, one param is a list:
42     # mkurl('http://flarg.baz/squz', {foo => 'bar', boo => ['baz', 'faz']});
43     #
44     # New page, clear all existing params before applying new ones:
45     # mkurl('/fuz/buster', {foo => 'bar', boo => 'baz'}, 1); 
46     #
47     # Current page, clear 'some_param' from the existing params:
48     # mkurl('', {foo => 'bar', boo => 'baz'}, ['some_param']);
49     #
50     # Current page to a named anchor 'copies'
51     # mkurl('', {}, [], 'copies');
52     MACRO mkurl(page, params, clear_params, named_anchor) BLOCK;
53
54         # clone the query string to avoid clobberation
55         cgi = CGI.new(CGI.query_string);
56
57         # remove requested params
58         IF clear_params.0; # array
59             FOR p IN clear_params; cgi.delete(p); END;
60         ELSIF clear_params;
61             cgi.delete_all();
62         END;
63
64         # some standing, hardcoded parameters to always clear
65         # because they're used for specific, transitory purposes
66         cgi.delete('move_cart_by_default');
67         cgi.delete('cart_none_selected');
68         cgi.delete('list_none_selected');
69
70         # x and y are artifacts of using <input type="image" /> tags 
71         # instead of true submit buttons, and their values are never used.
72         cgi.delete('x', 'y'); 
73
74         # apply user params
75         FOR k IN params.keys;
76             encoded = [];
77             max = params.$k.max;
78
79             # The following commented-out line can be fooled. Its replacement
80             # below is what you really mean.
81             # list = (params.$k.0 OR max == -1) ? params.$k : [params.$k];
82             list = params.$k.list;
83
84             IF list.size == 0; NEXT; END;
85             # CGI croaks on already-decoded strings.  force-encode to be safe.
86             FOR p IN list; encoded.push(ctx.encode_utf8(p)); END;
87             foo = cgi.param("-name", k, "-values", encoded);
88         END;
89
90         # for url brevity, remove any params that have no value
91         FOR p IN cgi.param;
92             val = cgi.param(p);
93             IF val == ''; cgi.delete(p); END;
94
95             # Delete POST vars unless we asked for them
96             UNLESS CGI.url_param(p).defined OR params.defined(p);
97                 cgi.delete(p);
98             END;
99         END;
100
101         final = named_anchor ? '#' _ named_anchor : '';
102
103         IF page;
104             IF cgi.query_string;
105                 page _ '?' _ cgi.query_string _ final;
106             ELSE;
107                 page _ final;
108             END;
109         ELSE;
110             # staying on the current page
111             cgi.url("-absolute" => 1, "-path" => 1, "-query" => 1) _ final;
112         END;
113     END;
114
115     # Dojo is required for the copy locations advanced search filter
116     IF ctx.page == 'advanced';
117         want_dojo = 1;
118     END;
119
120     # ... and for code that tweaks visibility of types on the added
121     # content tab
122     IF ctx.page == 'record' AND (ctx.expand_addedcontent OR ctx.expand_all);
123         want_dojo = 1;
124     END;
125
126     use_autosuggest = ctx.get_cgf("opac.use_autosuggest");
127
128     IF use_autosuggest.enabled == "t";
129         want_dojo = 1;
130     END;
131
132     IF ENV.OILS_NOVELIST_URL;
133         want_dojo = 1;
134     END;
135
136     IF ebook_api.enabled == 'true';
137         want_dojo = 1;
138     END;
139
140     # Especially useful for image 'alt' tags and link title tags,
141     # where the content may need to be unique (making it longer)
142     # but should not exceed 75 chars for ideal screen reader support.
143     # usage: html_text_attr('title', 'Link to item I Have A Super Long Title')
144     # the full HTML attribute key="value" is produced
145     MACRO html_text_attr(name, value) BLOCK;
146         IF value.length >= 75;
147             value = value.substr(71, value.length, '...');                        
148         END;                                                                   
149         value = value.replace('\s*$', ''); # remove trailing whitespace          
150         HTML.attributes($name => value); 
151     END;
152
153     MACRO img_alt(text) BLOCK;
154         html_text_attr('alt', text);
155     END;
156
157     # Browser cache-busting key
158     # Fall back to the eg_cache_hash (set by autogen) so that we don't have to
159     # add conditionals into the rest of the templates
160     IF ctx.cache_key AND ctx.cache_key != "?" _ ctx.eg_cache_hash;
161         ctx.cache_key = "?v=" _ ctx.cache_key;
162     ELSE;
163         ctx.cache_key = "?" _ ctx.eg_cache_hash;
164     END;
165 %]