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