bsw/jbe@19: 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: bsw/jbe@19: function ui.tabs(tabs) bsw/jbe@19: local params = param.get_all_cgi() bsw/jbe@19: local current_tabs_string = params["tab"] bsw/jbe@19: local current_tabs = {} bsw/jbe@19: if current_tabs_string then bsw/jbe@19: for current_tab in current_tabs_string:gmatch("([^%|]+)") do bsw/jbe@19: current_tabs[current_tab] = current_tab bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: local unique_string = param.get("tab_id") or multirand.string(16, '0123456789abcdef') bsw/jbe@19: bsw/jbe@19: function render_tab(tab, first) bsw/jbe@0: local params = param.get_all_cgi() bsw/jbe@19: local active = false bsw/jbe@19: for current_tab in pairs(current_tabs) do bsw/jbe@19: if tab.name == current_tab then bsw/jbe@19: active = true bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: if config.user_tab_mode == "accordeon_first_expanded" then bsw/jbe@19: if first and current_tabs_string == nil then bsw/jbe@19: active = true bsw/jbe@19: end bsw/jbe@19: end jorges@102: jorges@103: if active and not first then jorges@103: app.html_title.prefix = tab.label jorges@103: end jorges@103: bsw/jbe@19: local link_tabs = {} bsw/jbe@19: if config.user_tab_mode == "accordeon" bsw/jbe@19: or config.user_tab_mode == "accordeon_first_expanded" bsw/jbe@19: or config.user_tab_mode == "accordeon_all_expanded" and current_tabs_string bsw/jbe@19: then bsw/jbe@19: if not current_tabs_string and not first then bsw/jbe@19: link_tabs[tabs[1].name] = true bsw/jbe@19: end bsw/jbe@19: for current_tab in pairs(current_tabs) do bsw/jbe@19: if current_tab ~= tab.name then bsw/jbe@19: link_tabs[current_tab] = true bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: elseif config.user_tab_mode == "accordeon_all_expanded" and not current_tabs_string then bsw/jbe@19: for i, current_tab in ipairs(tabs) do bsw/jbe@19: if current_tab.name ~= tab.name then bsw/jbe@19: link_tabs[current_tab.name] = true bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: if not active then bsw/jbe@19: link_tabs[tab.name] = true bsw/jbe@19: end jorges@102: jorges@102: params["tab"] = tab.name bsw/jbe@19: local onclick bsw/jbe@19: if not tab.content then bsw/jbe@19: onclick = bsw/jbe@19: 'if (ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]) {' .. bsw/jbe@19: 'el=document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '");' .. bsw/jbe@19: 'el.innerHTML="";' .. bsw/jbe@19: 'el.style.display="none";' .. bsw/jbe@19: 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=false' .. bsw/jbe@19: '} else {' .. bsw/jbe@19: 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"]=true;' .. bsw/jbe@19: 'document.getElementById("tab' .. unique_string .. '_content_' .. tab.name .. '").style.display="block"; ' .. bsw/jbe@19: ui._partial_load_js{ bsw/jbe@19: params = { tab = tab.name } bsw/jbe@19: } .. bsw/jbe@19: '};' .. bsw/jbe@19: 'return(false);' bsw/jbe@19: end bsw/jbe@19: ui.link{ bsw/jbe@19: attr = { bsw/jbe@19: name = "tab_" .. tab.name, bsw/jbe@19: class = ( bsw@57: tab.name == current_tab and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or bsw@57: not current_tab and i == 1 and "ui_tabs_accordeon_head selected" .. (tab.class and (" " .. tab.class) or "") or bsw@57: "ui_tabs_accordeon_head" .. (tab.class and (" " .. tab.class) or "") bsw/jbe@19: ), bsw/jbe@19: id = "tab" .. unique_string .. "_head_" .. tab.name, bsw/jbe@19: onclick = onclick, bsw/jbe@19: }, bsw/jbe@19: module = request.get_module(), bsw/jbe@19: view = request.get_view(), bsw/jbe@19: id = param.get_id_cgi(), bsw/jbe@19: params = params, bsw/jbe@19: anchor = "tab" .. unique_string .. "_" .. tab.name, bsw/jbe@0: content = function() bsw/jbe@19: if tab.icon then bsw/jbe@19: if not tab.icon.attr then bsw/jbe@19: tab.icon.attr = {} bsw/jbe@19: end bsw/jbe@19: tab.icon.attr.id = "tab" .. unique_string .. "_icon_" .. tab.name bsw/jbe@19: tab.icon.attr.width = 16 bsw/jbe@19: tab.icon.attr.height = 16 bsw/jbe@19: ui.image(tab.icon) bsw/jbe@19: end bsw/jbe@19: slot.put(tab.label) bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: 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: ui.container{ bsw/jbe@19: attr = { bsw@57: class = "ui_tabs_accordeon_content" .. (tab.class and (" " .. tab.class) or ""), bsw/jbe@19: style = not expanded and "display: none;" or nil, bsw/jbe@19: id = "tab" .. unique_string .. "_content_" .. tab.name bsw/jbe@19: }, bsw/jbe@19: content = function() bsw/jbe@19: if expanded then bsw/jbe@19: ui.script{ script = 'ui_tabs_active["' .. unique_string .. '"]["' .. tab.name .. '"] = true;' } bsw/jbe@19: execute.view{ bsw/jbe@19: module = tab.module, bsw/jbe@19: view = tab.view, bsw/jbe@19: id = tab.id, bsw/jbe@19: params = tab.params bsw/jbe@0: } bsw/jbe@19: else bsw/jbe@19: slot.put(" ") bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: if not request.get_json_request_slots() or not current_tabs_string then bsw/jbe@19: ui.script{ script = "ui_tabs_active['" .. unique_string .. "'] = {};" } bsw/jbe@19: ui.container{ bsw/jbe@19: attr = { class = "ui_tabs" }, bsw/jbe@19: content = function() bsw/jbe@19: for i, tab in ipairs(tabs) do bsw/jbe@19: local static_params = tabs.static_params or {} bsw/jbe@19: static_params.tab = tab.name bsw/jbe@19: static_params.tab_id = unique_string bsw/jbe@19: ui.partial{ bsw/jbe@19: module = tabs.module, bsw/jbe@19: view = tabs.view, bsw/jbe@19: id = tabs.id, bsw/jbe@19: params = static_params, bsw/jbe@19: param_names = { "page" }, bsw/jbe@19: hourglass_target = "tab" .. unique_string .. "_icon_" .. tab.name, bsw/jbe@19: target = "tab" .. unique_string .. "_content_" .. tab.name, bsw/jbe@19: content = function() bsw/jbe@19: render_tab(tab, i == 1) bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: else bsw/jbe@19: local dyntab bsw/jbe@0: for i, tab in ipairs(tabs) do bsw/jbe@19: if tab.name == current_tabs_string then bsw/jbe@19: dyntab = tab bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@19: if dyntab then bsw/jbe@19: local static_params = tabs.static_params or {} bsw/jbe@19: static_params.tab = dyntab.name bsw/jbe@19: static_params.tab_id = unique_string bsw/jbe@19: dyntab.params.tab_id = unique_string bsw/jbe@19: ui.partial{ bsw/jbe@19: module = tabs.module, bsw/jbe@19: view = tabs.view, bsw/jbe@19: id = tabs.id, bsw/jbe@19: params = static_params, bsw/jbe@19: param_names = { "page" }, bsw/jbe@19: hourglass_target = "tab" .. unique_string .. "_icon_" .. dyntab.name, bsw/jbe@19: target = "tab" .. unique_string .. "_content_" .. dyntab.name, bsw/jbe@19: content = function() bsw/jbe@19: execute.view{ bsw/jbe@19: module = dyntab.module, bsw/jbe@19: view = dyntab.view, bsw/jbe@19: id = dyntab.id, bsw/jbe@19: params = dyntab.params, bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@0: end bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: else -- 'classic tab' bsw/jbe@0: bsw/jbe@19: function ui.tabs(tabs) bsw/jbe@19: ui.container{ bsw/jbe@19: attr = { class = "ui_tabs" }, bsw/jbe@19: content = function() bsw/jbe@19: local params = param.get_all_cgi() bsw/jbe@19: local current_tab = params["tab"] bsw/jbe@19: ui.container{ bsw/jbe@19: attr = { class = "ui_tabs_links" }, bsw/jbe@19: content = function() bsw/jbe@19: for i, tab in ipairs(tabs) do bsw/jbe@19: params["tab"] = i > 1 and tab.name or nil bsw/jbe@19: ui.link{ bsw/jbe@19: attr = { bsw/jbe@19: class = ( bsw@57: tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or bsw@57: not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or bsw@57: "" .. (tab.class and (" " .. tab.class) or "") bsw/jbe@19: ) bsw/jbe@19: }, bsw/jbe@19: module = request.get_module(), bsw/jbe@19: view = request.get_view(), bsw/jbe@19: id = param.get_id_cgi(), bsw/jbe@19: content = tab.label, bsw/jbe@19: params = params bsw/jbe@19: } bsw/jbe@19: slot.put(" ") bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: for i, tab in ipairs(tabs) do jorges@103: if tab.name == current_tab and i > 1 then jorges@103: app.html_title.prefix = tab.label jorges@103: end bsw/jbe@19: if tab.name == current_tab or not current_tab and i == 1 then bsw/jbe@19: ui.container{ bsw/jbe@19: attr = { class = "ui_tabs_content" }, bsw/jbe@19: content = function() bsw/jbe@19: if tab.content then bsw/jbe@19: tab.content() bsw/jbe@19: else bsw/jbe@19: execute.view{ bsw/jbe@19: module = tab.module, bsw/jbe@19: view = tab.view, bsw/jbe@19: id = tab.id, bsw/jbe@19: params = tab.params, bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: jorges@102: end