liquid_feedback_frontend

view env/ui/tabs.lua @ 34:a851cc1d9903

Beautified report view for closed issues
author bsw
date Wed Feb 24 12:37:28 2010 +0100 (2010-02-24)
parents 00d1004545f1
children 4f39f0a0d5b5
line source
1 if config.user_tab_mode == "accordeon" or config.user_tab_mode == "accordeon_first_expanded" or config.user_tab_mode == "accordeon_all_expanded" then
3 function ui.tabs(tabs)
4 local params = param.get_all_cgi()
5 local current_tabs_string = params["tab"]
6 local current_tabs = {}
7 if current_tabs_string then
8 for current_tab in current_tabs_string:gmatch("([^%|]+)") do
9 current_tabs[current_tab] = current_tab
10 end
11 end
13 local unique_string = param.get("tab_id") or multirand.string(16, '0123456789abcdef')
15 function render_tab(tab, first)
16 local params = param.get_all_cgi()
17 local active = false
18 for current_tab in pairs(current_tabs) do
19 if tab.name == current_tab then
20 active = true
21 end
22 end
23 if config.user_tab_mode == "accordeon_first_expanded" then
24 if first and current_tabs_string == nil then
25 active = true
26 end
27 end
28 local link_tabs = {}
29 if config.user_tab_mode == "accordeon"
30 or config.user_tab_mode == "accordeon_first_expanded"
31 or config.user_tab_mode == "accordeon_all_expanded" and current_tabs_string
32 then
33 if not current_tabs_string and not first then
34 link_tabs[tabs[1].name] = true
35 end
36 for current_tab in pairs(current_tabs) do
37 if current_tab ~= tab.name then
38 link_tabs[current_tab] = true
39 end
40 end
41 elseif config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string then
42 for i, current_tab in ipairs(tabs) do
43 if current_tab.name ~= tab.name then
44 link_tabs[current_tab.name] = true
45 end
46 end
47 end
48 if not active then
49 link_tabs[tab.name] = true
50 end
51 local link_tab_string = ""
52 for link_tab in pairs(link_tabs) do
53 if #link_tab_string > 0 then
54 link_tab_string = link_tab_string .. "|"
55 end
56 link_tab_string = link_tab_string .. link_tab
57 end
58 params["tab"] = link_tab_string
59 local onclick
60 if not tab.content then
61 onclick =
62 'if (ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]) {' ..
63 'el=document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '");' ..
64 'el.innerHTML="";' ..
65 'el.style.display="none";' ..
66 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=false' ..
67 '} else {' ..
68 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=true;' ..
69 'document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '").style.display="block"; ' ..
70 ui._partial_load_js{
71 params = { tab = tab.name }
72 } ..
73 '};' ..
74 'return(false);'
75 end
76 ui.link{
77 attr = {
78 name = "tab_" .. tab.name,
79 class = (
80 tab.name == current_tab and "ui_tabs_accordeon_head selected" or
81 not current_tab and i == 1 and "ui_tabs_accordeon_head selected" or
82 "ui_tabs_accordeon_head"
83 ),
84 id = "tab" .. unique_string .. "_head_" .. tab.name,
85 onclick = onclick,
86 },
87 module = request.get_module(),
88 view = request.get_view(),
89 id = param.get_id_cgi(),
90 params = params,
91 anchor = "tab" .. unique_string .. "_" .. tab.name,
92 content = function()
93 if tab.icon then
94 if not tab.icon.attr then
95 tab.icon.attr = {}
96 end
97 tab.icon.attr.id = "tab" .. unique_string .. "_icon_" .. tab.name
98 tab.icon.attr.width = 16
99 tab.icon.attr.height = 16
100 ui.image(tab.icon)
101 end
102 slot.put(tab.label)
103 end
104 }
105 local expanded = active or not request.get_json_request_slots() and config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string
106 ui.container{
107 attr = {
108 class = "ui_tabs_accordeon_content",
109 style = not expanded and "display: none;" or nil,
110 id = "tab" .. unique_string .. "_content_" .. tab.name
111 },
112 content = function()
113 if expanded then
114 ui.script{ script = 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"] = true;' }
115 execute.view{
116 module = tab.module,
117 view = tab.view,
118 id = tab.id,
119 params = tab.params
120 }
121 else
122 slot.put(" ")
123 end
124 end
125 }
126 end
128 if not request.get_json_request_slots() or not current_tabs_string then
129 ui.script{ script = "ui_tabs_active['" .. unique_string .. "'] = {};" }
130 ui.container{
131 attr = { class = "ui_tabs" },
132 content = function()
133 for i, tab in ipairs(tabs) do
134 local static_params = tabs.static_params or {}
135 static_params.tab = tab.name
136 static_params.tab_id = unique_string
137 ui.partial{
138 module = tabs.module,
139 view = tabs.view,
140 id = tabs.id,
141 params = static_params,
142 param_names = { "page" },
143 hourglass_target = "tab" .. unique_string .. "_icon_" .. tab.name,
144 target = "tab" .. unique_string .. "_content_" .. tab.name,
145 content = function()
146 render_tab(tab, i == 1)
147 end
148 }
149 end
150 end
151 }
152 else
153 local dyntab
154 for i, tab in ipairs(tabs) do
155 if tab.name == current_tabs_string then
156 dyntab = tab
157 end
158 end
159 if dyntab then
160 local static_params = tabs.static_params or {}
161 static_params.tab = dyntab.name
162 static_params.tab_id = unique_string
163 dyntab.params.tab_id = unique_string
164 ui.partial{
165 module = tabs.module,
166 view = tabs.view,
167 id = tabs.id,
168 params = static_params,
169 param_names = { "page" },
170 hourglass_target = "tab" .. unique_string .. "_icon_" .. dyntab.name,
171 target = "tab" .. unique_string .. "_content_" .. dyntab.name,
172 content = function()
173 execute.view{
174 module = dyntab.module,
175 view = dyntab.view,
176 id = dyntab.id,
177 params = dyntab.params,
178 }
179 end
180 }
181 end
182 end
183 end
185 else -- 'classic tab'
187 function ui.tabs(tabs)
188 ui.container{
189 attr = { class = "ui_tabs" },
190 content = function()
191 local params = param.get_all_cgi()
192 local current_tab = params["tab"]
193 ui.container{
194 attr = { class = "ui_tabs_links" },
195 content = function()
196 for i, tab in ipairs(tabs) do
197 params["tab"] = i > 1 and tab.name or nil
198 ui.link{
199 attr = {
200 class = (
201 tab.name == current_tab and "selected" or
202 not current_tab and i == 1 and "selected" or
203 ""
204 )
205 },
206 module = request.get_module(),
207 view = request.get_view(),
208 id = param.get_id_cgi(),
209 content = tab.label,
210 params = params
211 }
212 slot.put(" ")
213 end
214 end
215 }
216 for i, tab in ipairs(tabs) do
217 if tab.name == current_tab or not current_tab and i == 1 then
218 ui.container{
219 attr = { class = "ui_tabs_content" },
220 content = function()
221 if tab.content then
222 tab.content()
223 else
224 execute.view{
225 module = tab.module,
226 view = tab.view,
227 id = tab.id,
228 params = tab.params,
229 }
230 end
231 end
232 }
233 end
234 end
235 end
236 }
237 end
239 end

Impressum / About Us