liquid_feedback_frontend

view env/ui/filters.lua @ 1859:02c34183b6df

Fixed wrong filename in INSTALL file
author bsw
date Tue Nov 28 18:54:51 2023 +0100 (5 months ago)
parents dcacc0b98d70
children
line source
1 local function filters(args)
3 local el_id = ui.create_unique_id()
4 local class = "lf-filter"
5 if args.class then
6 class = class .. " " .. args.class
7 end
8 ui.tag{
9 tag = "fieldset",
10 attr = { class = { class } },
11 content = function()
12 local legend = args.legend
13 if legend then
14 ui.tag{ tag = "legend", attr = { style = "display: none;" }, content = legend }
15 end
16 for idx, filter in ipairs(args) do
17 local filter_name = filter.name or "filter"
18 if filter.selector_modifier then
19 filter.selector_modifier(args.selector)
20 end
21 local current_option_name = atom.string:load(request.get_param{ name = filter_name })
22 if not current_option_name then
23 current_option_name = param.get(filter_name)
24 end
25 local current_option = filter[1]
26 for idx, option in ipairs(filter) do
27 if current_option_name == option.name then
28 current_option = option
29 end
30 end
31 if not current_option_name or #current_option_name == 0 or not current_option then
32 current_option_name = filter[1].name
33 end
34 ui.tag{ tag = "button", attr = { id = "filter-" .. filter_name .. "-menu", class = "mdl-button mdl-js-button" }, content = function()
35 ui.tag{ content = current_option.label }
36 slot.put(" ")
37 ui.tag{ tag = "i", attr = { class = "material-icons", ["aria-hidden"] = "true" }, content = "arrow_drop_down" }
38 end }
39 local id = request.get_id_string()
40 local params = request.get_param_strings()
41 local class = "mdl-menu mdl-js-menu mdl-js-ripple-effect"
42 if filter.class then
43 class = class .. " " .. filter.class
44 end
45 ui.tag{
46 tag = "ul",
47 attr = { class = class, ["data-mdl-for"] = "filter-" .. filter_name .. "-menu" },
48 content = function()
49 for idx, option in ipairs(filter) do
50 params[filter_name] = option.name
51 local attr = {}
52 attr.class = "mdl-menu__link"
53 if current_option_name == option.name then
54 attr.class = attr.class .. " active"
55 option.selector_modifier(args.selector)
56 end
57 if idx > 1 then
58 slot.put(" ")
59 end
60 ui.tag{
61 tag = "li",
62 attr = { class = "mdl-menu__item" },
63 content = function()
64 ui.link{
65 attr = attr,
66 module = request.get_module(),
67 view = request.get_view(),
68 id = id,
69 params = params,
70 content = option.label,
71 partial = {
72 params = {
73 [filter_name] = idx > 1 and option.name or nil
74 }
75 }
76 }
77 end
78 }
79 end
80 end
81 }
82 end
83 end
84 }
85 end
87 function ui.filters(args)
88 if args.slot then
89 slot.select(args.slot, function()
90 filters(args)
91 end)
92 else
93 filters(args)
94 end
95 ui.container{
96 attr = { class = "ui_filter_content" },
97 content = function()
98 args.content()
99 end
100 }
101 end

Impressum / About Us