]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/header.tt2
Merge branch 'master' of git.evergreen-ils.org:Evergreen-DocBook into doc_consolidati...
[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     # -----------------------------------------------------------------------------
16     # mkurl( destination_page, params_to_set, params_to_clear )
17     #
18     # Current page, updated params:
19     # mkurl('', {foo => 'bar', boo => 'baz'});
20     #
21     # New page, one param is a list:
22     # mkurl('http://flarg.baz/squz', {foo => 'bar', boo => ['baz', 'faz']});
23     #
24     # New page, clear all existing params before applying new ones:
25     # mkurl('/fuz/buster', {foo => 'bar', boo => 'baz'}, 1); 
26     #
27     # Current page, clear 'some_param' from the existing params:
28     # mkurl('', {foo => 'bar', boo => 'baz'}, ['some_param']);
29     #
30     # Current page to a named anchor 'copies'
31     # mkurl('', {}, [], 'copies');
32     MACRO mkurl(page, params, clear_params, named_anchor) BLOCK;
33
34         # clone the query string to avoid clobberation
35         cgi = CGI.new(CGI.query_string);
36
37         # remove requested params
38         IF clear_params.0; # array
39             FOR p IN clear_params; cgi.delete(p); END;
40         ELSIF clear_params;
41             cgi.delete_all();
42         END;
43
44         # x and y are artifacts of using <input type="image" /> tags 
45         # instead of true submit buttons, and their values are never used.
46         cgi.delete('x', 'y'); 
47
48         # apply user params
49         FOR k IN params.keys;
50             encoded = [];
51             max = params.$k.max;
52
53             # The following commented-out line can be fooled. Its replacement
54             # below is what you really mean.
55             # list = (params.$k.0 OR max == -1) ? params.$k : [params.$k];
56             list = params.$k.list;
57
58             IF list.size == 0; NEXT; END;
59             # CGI croaks on already-decoded strings.  force-encode to be safe.
60             FOR p IN list; encoded.push(ctx.encode_utf8(p)); END;
61             foo = cgi.param("-name", k, "-values", encoded);
62         END;
63
64         # for url brevity, remove any params that have no value
65         FOR p IN cgi.param;
66             val = cgi.param(p);
67             IF val == ''; cgi.delete(p); END;
68
69             # Delete POST vars unless we asked for them
70             UNLESS CGI.url_param(p).defined OR params.defined(p);
71                 cgi.delete(p);
72             END;
73         END;
74
75         final = named_anchor ? '#' _ named_anchor : '';
76
77         IF page;
78             IF cgi.query_string;
79                 page _ '?' _ cgi.query_string _ final;
80             ELSE;
81                 page _ final;
82             END;
83         ELSE;
84             # staying on the current page
85             cgi.url("-path" => 1, "-query" => 1) _ final;
86         END;
87     END;
88
89     # Whether we want Dojo or not may one day be a wholly distinct
90     # concern from whether we want autosuggest, so let's get used to
91     # defining that separately.
92     want_dojo = 0;
93
94     use_autosuggest = ctx.get_cgf("opac.use_autosuggest");
95
96     IF use_autosuggest.enabled == "t";
97         want_dojo = 1;
98     END;
99 %]