liquid_feedback_frontend
diff env/ui/tabs.lua @ 278:fecd4c13054a
Code/css clean up and minor enhancements
author | bsw |
---|---|
date | Mon Feb 13 01:53:41 2012 +0100 (2012-02-13) |
parents | 7d0f4721d2f3 |
children | c587d8762e62 |
line diff
1.1 --- a/env/ui/tabs.lua Mon Feb 13 00:16:42 2012 +0100 1.2 +++ b/env/ui/tabs.lua Mon Feb 13 01:53:41 2012 +0100 1.3 @@ -1,241 +1,54 @@ 1.4 -if config.user_tab_mode == "accordeon" or config.user_tab_mode == "accordeon_first_expanded" or config.user_tab_mode == "accordeon_all_expanded" then 1.5 - 1.6 - function ui.tabs(tabs) 1.7 - local params = param.get_all_cgi() 1.8 - local current_tabs_string = params["tab"] 1.9 - local current_tabs = {} 1.10 - if current_tabs_string then 1.11 - for current_tab in current_tabs_string:gmatch("([^%|]+)") do 1.12 - current_tabs[current_tab] = current_tab 1.13 - end 1.14 - end 1.15 - 1.16 - local unique_string = param.get("tab_id") or multirand.string(16, '0123456789abcdef') 1.17 - 1.18 - function render_tab(tab, first) 1.19 +function ui.tabs(tabs) 1.20 + ui.container{ 1.21 + attr = { class = "ui_tabs" }, 1.22 + content = function() 1.23 local params = param.get_all_cgi() 1.24 - local active = false 1.25 - for current_tab in pairs(current_tabs) do 1.26 - if tab.name == current_tab then 1.27 - active = true 1.28 - end 1.29 - end 1.30 - if config.user_tab_mode == "accordeon_first_expanded" then 1.31 - if first and current_tabs_string == nil then 1.32 - active = true 1.33 - end 1.34 - end 1.35 - 1.36 - if active and not first then 1.37 - app.html_title.prefix = tab.label 1.38 - end 1.39 - 1.40 - local link_tabs = {} 1.41 - if config.user_tab_mode == "accordeon" 1.42 - or config.user_tab_mode == "accordeon_first_expanded" 1.43 - or config.user_tab_mode == "accordeon_all_expanded" and current_tabs_string 1.44 - then 1.45 - if not current_tabs_string and not first then 1.46 - link_tabs[tabs[1].name] = true 1.47 - end 1.48 - for current_tab in pairs(current_tabs) do 1.49 - if current_tab ~= tab.name then 1.50 - link_tabs[current_tab] = true 1.51 - end 1.52 - end 1.53 - elseif config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string then 1.54 - for i, current_tab in ipairs(tabs) do 1.55 - if current_tab.name ~= tab.name then 1.56 - link_tabs[current_tab.name] = true 1.57 - end 1.58 - end 1.59 - end 1.60 - if not active then 1.61 - link_tabs[tab.name] = true 1.62 - end 1.63 - 1.64 - params["tab"] = tab.name 1.65 - local onclick 1.66 - if not tab.content then 1.67 - onclick = 1.68 - 'if (ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]) {' .. 1.69 - 'el=document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '");' .. 1.70 - 'el.innerHTML="";' .. 1.71 - 'el.style.display="none";' .. 1.72 - 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=false' .. 1.73 - '} else {' .. 1.74 - 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=true;' .. 1.75 - 'document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '").style.display="block"; ' .. 1.76 - ui._partial_load_js{ 1.77 - params = { tab = tab.name } 1.78 - } .. 1.79 - '};' .. 1.80 - 'return(false);' 1.81 - end 1.82 - ui.link{ 1.83 - attr = { 1.84 - name = "tab_" .. tab.name, 1.85 - class = ( 1.86 - tab.name == current_tab and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or 1.87 - not current_tab and i == 1 and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or 1.88 - "ui_tabs_accordeon_head" .. (tab.class and (" " .. tab.class) or "") 1.89 - ), 1.90 - id = "tab" .. unique_string .. "_head_" .. tab.name, 1.91 - onclick = onclick, 1.92 - }, 1.93 - module = request.get_module(), 1.94 - view = request.get_view(), 1.95 - id = param.get_id_cgi(), 1.96 - params = params, 1.97 - anchor = "tab" .. unique_string .. "_" .. tab.name, 1.98 + local current_tab = params["tab"] 1.99 + ui.container{ 1.100 + attr = { class = "ui_tabs_links" }, 1.101 content = function() 1.102 - if tab.icon then 1.103 - if not tab.icon.attr then 1.104 - tab.icon.attr = {} 1.105 - end 1.106 - tab.icon.attr.id = "tab" .. unique_string .. "_icon_" .. tab.name 1.107 - tab.icon.attr.width = 16 1.108 - tab.icon.attr.height = 16 1.109 - ui.image(tab.icon) 1.110 - end 1.111 - slot.put(tab.label) 1.112 - end 1.113 - } 1.114 - local expanded = active or not request.get_json_request_slots() and config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string 1.115 - ui.container{ 1.116 - attr = { 1.117 - class = "ui_tabs_accordeon_content" .. (tab.class and (" " .. tab.class) or ""), 1.118 - style = not expanded and "display: none;" or nil, 1.119 - id = "tab" .. unique_string .. "_content_" .. tab.name 1.120 - }, 1.121 - content = function() 1.122 - if expanded then 1.123 - ui.script{ script = 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"] = true;' } 1.124 - execute.view{ 1.125 - module = tab.module, 1.126 - view = tab.view, 1.127 - id = tab.id, 1.128 - params = tab.params 1.129 + for i, tab in ipairs(tabs) do 1.130 + params["tab"] = i > 1 and tab.name or nil 1.131 + ui.link{ 1.132 + attr = { 1.133 + class = ( 1.134 + tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or 1.135 + not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or 1.136 + "" .. (tab.class and (" " .. tab.class) or "") 1.137 + ) 1.138 + }, 1.139 + module = request.get_module(), 1.140 + view = request.get_view(), 1.141 + id = param.get_id_cgi(), 1.142 + content = tab.label, 1.143 + params = params 1.144 } 1.145 - else 1.146 - slot.put(" ") 1.147 + slot.put(" ") 1.148 end 1.149 end 1.150 } 1.151 - end 1.152 - 1.153 - if not request.get_json_request_slots() or not current_tabs_string then 1.154 - ui.script{ script = "ui_tabs_active['" .. unique_string .. "'] = {};" } 1.155 - ui.container{ 1.156 - attr = { class = "ui_tabs" }, 1.157 - content = function() 1.158 - for i, tab in ipairs(tabs) do 1.159 - local static_params = tabs.static_params or {} 1.160 - static_params.tab = tab.name 1.161 - static_params.tab_id = unique_string 1.162 - ui.partial{ 1.163 - module = tabs.module, 1.164 - view = tabs.view, 1.165 - id = tabs.id, 1.166 - params = static_params, 1.167 - param_names = { "page" }, 1.168 - hourglass_target = "tab" .. unique_string .. "_icon_" .. tab.name, 1.169 - target = "tab" .. unique_string .. "_content_" .. tab.name, 1.170 - content = function() 1.171 - render_tab(tab, i == 1) 1.172 + for i, tab in ipairs(tabs) do 1.173 + if tab.name == current_tab and i > 1 then 1.174 + app.html_title.prefix = tab.label 1.175 end 1.176 - } 1.177 - end 1.178 + if tab.name == current_tab or not current_tab and i == 1 then 1.179 + ui.container{ 1.180 + attr = { class = "ui_tabs_content" }, 1.181 + content = function() 1.182 + if tab.content then 1.183 + tab.content() 1.184 + else 1.185 + execute.view{ 1.186 + module = tab.module, 1.187 + view = tab.view, 1.188 + id = tab.id, 1.189 + params = tab.params, 1.190 + } 1.191 + end 1.192 + end 1.193 + } 1.194 end 1.195 - } 1.196 - else 1.197 - local dyntab 1.198 - for i, tab in ipairs(tabs) do 1.199 - if tab.name == current_tabs_string then 1.200 - dyntab = tab 1.201 - end 1.202 - end 1.203 - if dyntab then 1.204 - local static_params = tabs.static_params or {} 1.205 - static_params.tab = dyntab.name 1.206 - static_params.tab_id = unique_string 1.207 - dyntab.params.tab_id = unique_string 1.208 - ui.partial{ 1.209 - module = tabs.module, 1.210 - view = tabs.view, 1.211 - id = tabs.id, 1.212 - params = static_params, 1.213 - param_names = { "page" }, 1.214 - hourglass_target = "tab" .. unique_string .. "_icon_" .. dyntab.name, 1.215 - target = "tab" .. unique_string .. "_content_" .. dyntab.name, 1.216 - content = function() 1.217 - execute.view{ 1.218 - module = dyntab.module, 1.219 - view = dyntab.view, 1.220 - id = dyntab.id, 1.221 - params = dyntab.params, 1.222 - } 1.223 - end 1.224 - } 1.225 end 1.226 end 1.227 - end 1.228 - 1.229 -else -- 'classic tab' 1.230 - 1.231 - function ui.tabs(tabs) 1.232 - ui.container{ 1.233 - attr = { class = "ui_tabs" }, 1.234 - content = function() 1.235 - local params = param.get_all_cgi() 1.236 - local current_tab = params["tab"] 1.237 - ui.container{ 1.238 - attr = { class = "ui_tabs_links" }, 1.239 - content = function() 1.240 - for i, tab in ipairs(tabs) do 1.241 - params["tab"] = i > 1 and tab.name or nil 1.242 - ui.link{ 1.243 - attr = { 1.244 - class = ( 1.245 - tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or 1.246 - not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or 1.247 - "" .. (tab.class and (" " .. tab.class) or "") 1.248 - ) 1.249 - }, 1.250 - module = request.get_module(), 1.251 - view = request.get_view(), 1.252 - id = param.get_id_cgi(), 1.253 - content = tab.label, 1.254 - params = params 1.255 - } 1.256 - slot.put(" ") 1.257 - end 1.258 - end 1.259 - } 1.260 - for i, tab in ipairs(tabs) do 1.261 - if tab.name == current_tab and i > 1 then 1.262 - app.html_title.prefix = tab.label 1.263 - end 1.264 - if tab.name == current_tab or not current_tab and i == 1 then 1.265 - ui.container{ 1.266 - attr = { class = "ui_tabs_content" }, 1.267 - content = function() 1.268 - if tab.content then 1.269 - tab.content() 1.270 - else 1.271 - execute.view{ 1.272 - module = tab.module, 1.273 - view = tab.view, 1.274 - id = tab.id, 1.275 - params = tab.params, 1.276 - } 1.277 - end 1.278 - end 1.279 - } 1.280 - end 1.281 - end 1.282 - end 1.283 - } 1.284 - end 1.285 - 1.286 + } 1.287 end