bsw@278: function ui.tabs(tabs) bsw@286: local attr = tabs.attr or {} bsw@286: attr.class = (attr.class and attr.class .. " " or "") .. "ui_tabs" bsw@278: ui.container{ bsw@286: attr = attr, bsw@278: content = function() bsw/jbe@0: local params = param.get_all_cgi() bsw@278: local current_tab = params["tab"] bsw@278: ui.container{ bsw@278: attr = { class = "ui_tabs_links" }, bsw/jbe@0: content = function() bsw@278: for i, tab in ipairs(tabs) do bsw@292: local params = param.get_all_cgi() bsw@292: if tab.link_params then bsw@292: for key, value in pairs(tab.link_params) do bsw@292: params[key] = value bsw@292: end bsw@292: end bsw@278: params["tab"] = i > 1 and tab.name or nil bsw@278: ui.link{ bsw@278: attr = { bsw@278: class = ( bsw@278: tab.name == current_tab and "selected" .. (tab.class and (" " .. tab.class) or "") or bsw@278: not current_tab and i == 1 and "selected" .. (tab.class and (" " .. tab.class) or "") or bsw@278: "" .. (tab.class and (" " .. tab.class) or "") bsw@278: ) bsw@278: }, bsw@278: module = request.get_module(), bsw@278: view = request.get_view(), bsw@278: id = param.get_id_cgi(), bsw@278: content = tab.label, bsw@278: params = params bsw/jbe@0: } bsw@278: slot.put(" ") bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: } bsw@278: for i, tab in ipairs(tabs) do bsw@278: if tab.name == current_tab and i > 1 then bsw@278: app.html_title.prefix = tab.label bsw/jbe@19: end bsw@278: if tab.name == current_tab or not current_tab and i == 1 then bsw@278: ui.container{ bsw@278: attr = { class = "ui_tabs_content" }, bsw@278: content = function() bsw@278: if tab.content then bsw@278: tab.content() bsw@278: else bsw@278: execute.view{ bsw@278: module = tab.module, bsw@278: view = tab.view, bsw@278: id = tab.id, bsw@278: params = tab.params, bsw@278: } bsw@278: end bsw@278: end bsw@278: } bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@0: end bsw@278: } jorges@102: end