webmcp

view framework/env/ui/filters.lua @ 92:774a891dc74f

Removed functions param.get_id_raw() and param.get_all_raw()
author jbe
date Wed Oct 10 17:57:40 2012 +0200 (2012-10-10)
parents 2f8d8edd1836
children 32ec28229bb5
line source
1 --[[--
2 ui.filters{
3 selector = selector, -- selector to be modified
4 label = label, -- text to be displayed when filters are collapsed
5 {
6 name = name1, -- name of first filter (used as GET param)
7 label = label1, -- label of first filter
8 {
9 name = name1a, -- name of first option of first filter
10 label = label1a, -- label of first option of first filter
11 selector_modifier = function(selector)
12 ...
13 end
14 },
15 {
16 name = name1b, -- name of second option of first filter
17 label = label1b, -- label of second option of first filter
18 selector_modifier = function(selector)
19 ...
20 end
21 },
22 ...
23 },
24 {
25 name = name2, -- name of second filter (used as GET param)
26 label = label2, -- label of second filter
27 {
28 ...
29 }, {
30 ...
31 },
32 ...
33 },
34 ...
35 content = function()
36 ... -- inner code where filter is to be applied
37 end
38 }
40 --]]--
42 function ui.filters(args)
43 local el_id = ui.create_unique_id()
44 ui.container{
45 attr = { class = "ui_filter" },
46 content = function()
47 ui.container{
48 attr = {
49 class = "ui_filter_closed_head"
50 },
51 content = function()
52 ui.tag{
53 tag = "span",
54 content = function()
55 local current_options = {}
56 for idx, filter in ipairs(args) do
57 local filter_name = filter.name or "filter"
58 local current_option = atom.string:load(cgi.params[filter_name])
59 if not current_option then
60 current_option = param.get(filter_name)
61 end
62 if not current_option or #current_option == 0 then
63 current_option = filter[1].name
64 end
65 for idx, option in ipairs(filter) do
66 if current_option == option.name then
67 current_options[#current_options+1] = encode.html(filter.label) .. ": " .. encode.html(option.label)
68 end
69 end
70 end
71 slot.put(table.concat(current_options, "; "))
72 end
73 }
74 slot.put(" (")
75 ui.link{
76 attr = {
77 onclick = "this.parentNode.style.display='none'; document.getElementById('" .. el_id .. "_head').style.display='block'; return(false);"
78 },
79 text = args.label,
80 external = "#"
81 }
82 slot.put(")")
83 end
84 }
85 ui.container{
86 attr = {
87 id = el_id .. "_head",
88 style = "display: none;"
89 },
90 content = function()
91 for idx, filter in ipairs(args) do
92 local filter_name = filter.name or "filter"
93 local current_option = atom.string:load(cgi.params[filter_name])
94 if not current_option then
95 current_option = param.get(filter_name)
96 end
97 if not current_option or #current_option == 0 then
98 current_option = filter[1].name
99 end
100 local id = request.get_id_string()
101 local params = request.get_param_strings()
102 ui.container{
103 attr = { class = "ui_filter_head" },
104 content = function()
105 slot.put(filter.label or "Filter", ": ")
106 for idx, option in ipairs(filter) do
107 params[filter_name] = option.name
108 local attr = {}
109 if current_option == option.name then
110 attr.class = "active"
111 option.selector_modifier(args.selector)
112 end
113 ui.link{
114 attr = attr,
115 module = request.get_module(),
116 view = request.get_view(),
117 id = id,
118 params = params,
119 text = option.label,
120 partial = {
121 params = {
122 [filter_name] = option.name
123 }
124 }
125 }
126 end
127 end
128 }
129 end
130 end
131 }
132 end
133 }
134 ui.container{
135 attr = { class = "ui_filter_content" },
136 content = function()
137 args.content()
138 end
139 }
140 end

Impressum / About Us