rev |
line source |
bsw@295
|
1 function ui.filters(args)
|
bsw@295
|
2 local el_id = ui.create_unique_id()
|
bsw@295
|
3 ui.container{
|
bsw@295
|
4 attr = { class = "ui_filter" },
|
bsw@295
|
5 content = function()
|
bsw@852
|
6 for idx, filter in ipairs(args) do
|
bsw@852
|
7 local filter_name = filter.name or "filter"
|
bsw@1145
|
8 local current_option = atom.string:load(request.get_param{ name = filter_name })
|
bsw@852
|
9 if not current_option then
|
bsw@852
|
10 current_option = param.get(filter_name)
|
bsw@852
|
11 end
|
bsw@852
|
12 local current_option_valid = false
|
bsw@852
|
13 for idx, option in ipairs(filter) do
|
bsw@852
|
14 if current_option == option.name then
|
bsw@852
|
15 current_option_valid = true
|
bsw@295
|
16 end
|
bsw@295
|
17 end
|
bsw@852
|
18 if not current_option or #current_option == 0 or not current_option_valid then
|
bsw@852
|
19 current_option = filter[1].name
|
bsw@852
|
20 end
|
bsw@1145
|
21 local id = request.get_id_string()
|
bsw@1145
|
22 local params = request.get_param_strings()
|
bsw@1045
|
23 local class = "ui_filter_head"
|
bsw@1045
|
24 if filter.class then
|
bsw@1045
|
25 class = class .. " " .. filter.class
|
bsw@1045
|
26 end
|
bsw@852
|
27 ui.container{
|
bsw@1045
|
28 attr = { class = class },
|
bsw@852
|
29 content = function()
|
bsw@852
|
30 slot.put(filter.label)
|
bsw@852
|
31 for idx, option in ipairs(filter) do
|
bsw@852
|
32 params[filter_name] = option.name
|
bsw@852
|
33 local attr = {}
|
bsw@852
|
34 if current_option == option.name then
|
bsw@852
|
35 attr.class = "active"
|
bsw@852
|
36 option.selector_modifier(args.selector)
|
bsw@852
|
37 end
|
bsw@852
|
38 if idx > 1 then
|
bsw@852
|
39 slot.put(" ")
|
bsw@852
|
40 end
|
bsw@852
|
41 ui.link{
|
bsw@852
|
42 attr = attr,
|
bsw@852
|
43 module = request.get_module(),
|
bsw@852
|
44 view = request.get_view(),
|
bsw@852
|
45 id = id,
|
bsw@852
|
46 params = params,
|
bsw@852
|
47 text = option.label,
|
bsw@852
|
48 partial = {
|
bsw@852
|
49 params = {
|
bsw@852
|
50 [filter_name] = option.name
|
bsw@852
|
51 }
|
bsw@852
|
52 }
|
bsw@852
|
53 }
|
bsw@295
|
54 end
|
bsw@295
|
55 end
|
bsw@852
|
56 }
|
bsw@852
|
57 end
|
bsw@295
|
58 end
|
bsw@295
|
59 }
|
bsw@295
|
60 ui.container{
|
bsw@295
|
61 attr = { class = "ui_filter_content" },
|
bsw@295
|
62 content = function()
|
bsw@295
|
63 args.content()
|
bsw@295
|
64 end
|
bsw@295
|
65 }
|
bsw@295
|
66 end
|