]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/templates/opac/parts/header.tt2
5db8139ca0218af8bf488aa6f9eaa51d0b5c8d89
[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     MACRO mkurl(page, params, clear_params) BLOCK;
30
31         # clone the query string to avoid clobberation
32         cgi = CGI.new(CGI.query_string);
33
34         # remove requested params
35         IF clear_params.0; # array
36             FOR p IN clear_params; cgi.delete(p); END;
37         ELSIF clear_params;
38             cgi.delete_all();
39         END;
40
41         # x and y are artifacts of using <input type="image" /> tags 
42         # instead of true submit buttons, and their values are never used.
43         cgi.delete('x', 'y'); 
44
45         # apply user params
46         FOR k IN params.keys;
47             encoded = [];
48             max = params.$k.max;
49             list = (params.$k.0 OR max == -1) ? params.$k : [params.$k];
50             IF list.size == 0; NEXT; END;
51             # CGI croaks on already-decoded strings.  force-encode to be safe.
52             FOR p IN list; encoded.push(ctx.encode_utf8(p)); END;
53             foo = cgi.param("-name", k, "-values", encoded);
54         END;
55
56         # for url brevity, remove any params that have no value
57         FOR p IN cgi.param;
58             val = cgi.param(p);
59             IF val == ''; cgi.delete(p); END;
60
61             # Delete POST vars unless we asked for them
62             UNLESS CGI.url_param(p) OR params.defined(p);
63                 cgi.delete(p);
64             END;
65         END;
66
67         IF page;
68             IF cgi.query_string;
69                 page _ '?' _ cgi.query_string;
70             ELSE;
71                 page;
72             END;
73         ELSE;
74             # staying on the current page
75             cgi.url("-path" => 1, "-query" => 1);
76         END;
77     END;
78
79     # Whether we want Dojo or not may one day be a wholly distinct
80     # concern from whether we want autosuggest, so let's get used to
81     # defining that separately.
82     want_dojo = 0;
83
84     use_autosuggest = ctx.get_cgf("opac.use_autosuggest");
85
86     IF use_autosuggest.enabled == "t";
87         want_dojo = 1;
88     END;
89 %]