liquid_feedback_frontend

view env/ui/tabs.lua @ 102:d4b4adb9a4df

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

Impressum / About Us