liquid_feedback_frontend

view env/ui/filters.lua @ 1309:32cc544d5a5b

Cumulative patch for upcoming frontend version 4
author bsw/jbe
date Sun Jul 15 14:07:29 2018 +0200 (2018-07-15)
parents 904f6807f7fa
children 3ab878ba277e
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.container{
9 attr = { class = { class } },
10 content = function()
11 for idx, filter in ipairs(args) do
12 local filter_name = filter.name or "filter"
13 local current_option_name = atom.string:load(request.get_param{ name = filter_name })
14 if not current_option_name then
15 current_option_name = param.get(filter_name)
16 end
17 local current_option = filter[1]
18 for idx, option in ipairs(filter) do
19 if current_option_name == option.name then
20 current_option = option
21 end
22 end
23 if not current_option_name or #current_option_name == 0 or not current_option then
24 current_option_name = filter[1].name
25 end
26 ui.tag{ tag = "button", attr = { id = "filter-" .. filter_name .. "-menu", class = "mdl-button mdl-js-button" }, content = function()
27 ui.tag{ content = current_option.label }
28 slot.put(" ")
29 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "arrow_drop_down" }
30 end }
31 local id = request.get_id_string()
32 local params = request.get_param_strings()
33 local class = "mdl-menu mdl-js-menu mdl-js-ripple-effect"
34 if filter.class then
35 class = class .. " " .. filter.class
36 end
37 ui.tag{
38 tag = "ul",
39 attr = { class = class, ["data-mdl-for"] = "filter-" .. filter_name .. "-menu" },
40 content = function()
41 for idx, option in ipairs(filter) do
42 params[filter_name] = option.name
43 local attr = {}
44 attr.class = "mdl-menu__link"
45 if current_option_name == option.name then
46 attr.class = attr.class .. " active"
47 option.selector_modifier(args.selector)
48 end
49 if idx > 1 then
50 slot.put(" ")
51 end
52 ui.tag{
53 tag = "li",
54 attr = { class = "mdl-menu__item" },
55 content = function()
56 ui.link{
57 attr = attr,
58 module = request.get_module(),
59 view = request.get_view(),
60 id = id,
61 params = params,
62 content = option.label,
63 partial = {
64 params = {
65 [filter_name] = idx > 1 and option.name or nil
66 }
67 }
68 }
69 end
70 }
71 end
72 end
73 }
74 end
75 end
76 }
77 end
79 function ui.filters(args)
80 if args.slot then
81 slot.select(args.slot, function()
82 filters(args)
83 end)
84 else
85 filters(args)
86 end
87 ui.container{
88 attr = { class = "ui_filter_content" },
89 content = function()
90 args.content()
91 end
92 }
93 end

Impressum / About Us