# HG changeset patch # User jbe/bsw # Date 1266696058 -3600 # Node ID a29c8ffb3f82ccfae9f20a8b3bb1bdf0db2fa1c3 # Parent 39652c779afe406b9f25881629432222efd3e054 New function ui.filters{...} Also changed version information to "1.0.8" diff -r 39652c779afe -r a29c8ffb3f82 doc/autodoc-header.htmlpart --- a/doc/autodoc-header.htmlpart Fri Feb 19 16:49:00 2010 +0100 +++ b/doc/autodoc-header.htmlpart Sat Feb 20 21:00:58 2010 +0100 @@ -55,10 +55,10 @@ color: #505050; } -
WebMCP is a completely new web development framework, and has not been extensively tested yet. The API might change at any time, but in future releases there will be a list of all changes, which break downward compatibility.
diff -r 39652c779afe -r a29c8ffb3f82 framework/cgi-bin/webmcp.lua --- a/framework/cgi-bin/webmcp.lua Fri Feb 19 16:49:00 2010 +0100 +++ b/framework/cgi-bin/webmcp.lua Sat Feb 20 21:00:58 2010 +0100 @@ -1,6 +1,6 @@ #!/usr/bin/env lua -_WEBMCP_VERSION = "1.0.7" +_WEBMCP_VERSION = "1.0.8" -- include "../lib/" in search path for libraries do diff -r 39652c779afe -r a29c8ffb3f82 framework/env/ui/container.lua --- a/framework/env/ui/container.lua Fri Feb 19 16:49:00 2010 +0100 +++ b/framework/env/ui/container.lua Sat Feb 20 21:00:58 2010 +0100 @@ -9,7 +9,7 @@ legend_attr = legend_attr, -- HTML attributes for a legend tag content_first = content_first, -- set to true to place label or legend after the content content = function() - ... -- + ... end } diff -r 39652c779afe -r a29c8ffb3f82 framework/env/ui/filters.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/ui/filters.lua Sat Feb 20 21:00:58 2010 +0100 @@ -0,0 +1,140 @@ +--[[-- +ui.filters{ + selector = selector, -- selector to be modified + label = label, -- text to be displayed when filters are collapsed + { + name = name1, -- name of first filter (used as GET param) + label = label1, -- label of first filter + { + name = name1a, -- name of first option of first filter + label = label1a, -- label of first option of first filter + selector_modifier = function(selector) + ... + end + }, + { + name = name1b, -- name of second option of first filter + label = label1b, -- label of second option of first filter + selector_modifier = function(selector) + ... + end + }, + ... + }, + { + name = name2, -- name of second filter (used as GET param) + label = label2, -- label of second filter + { + ... + }, { + ... + }, + ... + }, + ... + content = function() + ... -- inner code where filter is to be applied + end +} + +--]]-- + +function ui.filters(args) + local el_id = ui.create_unique_id() + ui.container{ + attr = { class = "ui_filter" }, + content = function() + ui.container{ + attr = { + class = "ui_filter_closed_head" + }, + content = function() + ui.tag{ + tag = "span", + content = function() + local current_options = {} + for idx, filter in ipairs(args) do + local filter_name = filter.name or "filter" + local current_option = atom.string:load(cgi.params[filter_name]) + if not current_option then + current_option = param.get(filter_name) + end + if not current_option or #current_option == 0 then + current_option = filter[1].name + end + for idx, option in ipairs(filter) do + if current_option == option.name then + current_options[#current_options+1] = encode.html(filter.label) .. ": " .. encode.html(option.label) + end + end + end + slot.put(table.concat(current_options, "; ")) + end + } + slot.put(" (") + ui.link{ + attr = { + onclick = "this.parentNode.style.display='none'; document.getElementById('" .. el_id .. "_head').style.display='block'; return(false);" + }, + text = args.label, + external = "#" + } + slot.put(")") + end + } + ui.container{ + attr = { + id = el_id .. "_head", + style = "display: none;" + }, + content = function() + for idx, filter in ipairs(args) do + local filter_name = filter.name or "filter" + local current_option = atom.string:load(cgi.params[filter_name]) + if not current_option then + current_option = param.get(filter_name) + end + if not current_option or #current_option == 0 then + current_option = filter[1].name + end + local id = param.get_id_cgi() + local params = param.get_all_cgi() + ui.container{ + attr = { class = "ui_filter_head" }, + content = function() + slot.put(filter.label or "Filter", ": ") + for idx, option in ipairs(filter) do + params[filter_name] = option.name + local attr = {} + if current_option == option.name then + attr.class = "active" + option.selector_modifier(args.selector) + end + ui.link{ + attr = attr, + module = request.get_module(), + view = request.get_view(), + id = id, + params = params, + text = option.label, + partial = { + params = { + [filter_name] = option.name + } + } + } + end + end + } + end + end + } + end + } + ui.container{ + attr = { class = "ui_filter_content" }, + content = function() + args.content() + end + } +end