webmcp
changeset 14:a29c8ffb3f82 v1.0.8
New function ui.filters{...}
Also changed version information to "1.0.8"
Also changed version information to "1.0.8"
author | jbe/bsw |
---|---|
date | Sat Feb 20 21:00:58 2010 +0100 (2010-02-20) |
parents | 39652c779afe |
children | 6441487fa12f |
files | doc/autodoc-header.htmlpart framework/cgi-bin/webmcp.lua framework/env/ui/container.lua framework/env/ui/filters.lua |
line diff
1.1 --- a/doc/autodoc-header.htmlpart Fri Feb 19 16:49:00 2010 +0100 1.2 +++ b/doc/autodoc-header.htmlpart Sat Feb 20 21:00:58 2010 +0100 1.3 @@ -55,10 +55,10 @@ 1.4 color: #505050; 1.5 } 1.6 </style> 1.7 - <title>WebMCP 1.0.7 Documentation</title> 1.8 + <title>WebMCP 1.0.8 Documentation</title> 1.9 </head> 1.10 <body> 1.11 - <h1>WebMCP 1.0.7 Documentation</h1> 1.12 + <h1>WebMCP 1.0.8 Documentation</h1> 1.13 <p> 1.14 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. 1.15 </p>
2.1 --- a/framework/cgi-bin/webmcp.lua Fri Feb 19 16:49:00 2010 +0100 2.2 +++ b/framework/cgi-bin/webmcp.lua Sat Feb 20 21:00:58 2010 +0100 2.3 @@ -1,6 +1,6 @@ 2.4 #!/usr/bin/env lua 2.5 2.6 -_WEBMCP_VERSION = "1.0.7" 2.7 +_WEBMCP_VERSION = "1.0.8" 2.8 2.9 -- include "../lib/" in search path for libraries 2.10 do
3.1 --- a/framework/env/ui/container.lua Fri Feb 19 16:49:00 2010 +0100 3.2 +++ b/framework/env/ui/container.lua Sat Feb 20 21:00:58 2010 +0100 3.3 @@ -9,7 +9,7 @@ 3.4 legend_attr = legend_attr, -- HTML attributes for a legend tag 3.5 content_first = content_first, -- set to true to place label or legend after the content 3.6 content = function() 3.7 - ... -- 3.8 + ... 3.9 end 3.10 } 3.11
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/framework/env/ui/filters.lua Sat Feb 20 21:00:58 2010 +0100 4.3 @@ -0,0 +1,140 @@ 4.4 +--[[-- 4.5 +ui.filters{ 4.6 + selector = selector, -- selector to be modified 4.7 + label = label, -- text to be displayed when filters are collapsed 4.8 + { 4.9 + name = name1, -- name of first filter (used as GET param) 4.10 + label = label1, -- label of first filter 4.11 + { 4.12 + name = name1a, -- name of first option of first filter 4.13 + label = label1a, -- label of first option of first filter 4.14 + selector_modifier = function(selector) 4.15 + ... 4.16 + end 4.17 + }, 4.18 + { 4.19 + name = name1b, -- name of second option of first filter 4.20 + label = label1b, -- label of second option of first filter 4.21 + selector_modifier = function(selector) 4.22 + ... 4.23 + end 4.24 + }, 4.25 + ... 4.26 + }, 4.27 + { 4.28 + name = name2, -- name of second filter (used as GET param) 4.29 + label = label2, -- label of second filter 4.30 + { 4.31 + ... 4.32 + }, { 4.33 + ... 4.34 + }, 4.35 + ... 4.36 + }, 4.37 + ... 4.38 + content = function() 4.39 + ... -- inner code where filter is to be applied 4.40 + end 4.41 +} 4.42 + 4.43 +--]]-- 4.44 + 4.45 +function ui.filters(args) 4.46 + local el_id = ui.create_unique_id() 4.47 + ui.container{ 4.48 + attr = { class = "ui_filter" }, 4.49 + content = function() 4.50 + ui.container{ 4.51 + attr = { 4.52 + class = "ui_filter_closed_head" 4.53 + }, 4.54 + content = function() 4.55 + ui.tag{ 4.56 + tag = "span", 4.57 + content = function() 4.58 + local current_options = {} 4.59 + for idx, filter in ipairs(args) do 4.60 + local filter_name = filter.name or "filter" 4.61 + local current_option = atom.string:load(cgi.params[filter_name]) 4.62 + if not current_option then 4.63 + current_option = param.get(filter_name) 4.64 + end 4.65 + if not current_option or #current_option == 0 then 4.66 + current_option = filter[1].name 4.67 + end 4.68 + for idx, option in ipairs(filter) do 4.69 + if current_option == option.name then 4.70 + current_options[#current_options+1] = encode.html(filter.label) .. ": " .. encode.html(option.label) 4.71 + end 4.72 + end 4.73 + end 4.74 + slot.put(table.concat(current_options, "; ")) 4.75 + end 4.76 + } 4.77 + slot.put(" (") 4.78 + ui.link{ 4.79 + attr = { 4.80 + onclick = "this.parentNode.style.display='none'; document.getElementById('" .. el_id .. "_head').style.display='block'; return(false);" 4.81 + }, 4.82 + text = args.label, 4.83 + external = "#" 4.84 + } 4.85 + slot.put(")") 4.86 + end 4.87 + } 4.88 + ui.container{ 4.89 + attr = { 4.90 + id = el_id .. "_head", 4.91 + style = "display: none;" 4.92 + }, 4.93 + content = function() 4.94 + for idx, filter in ipairs(args) do 4.95 + local filter_name = filter.name or "filter" 4.96 + local current_option = atom.string:load(cgi.params[filter_name]) 4.97 + if not current_option then 4.98 + current_option = param.get(filter_name) 4.99 + end 4.100 + if not current_option or #current_option == 0 then 4.101 + current_option = filter[1].name 4.102 + end 4.103 + local id = param.get_id_cgi() 4.104 + local params = param.get_all_cgi() 4.105 + ui.container{ 4.106 + attr = { class = "ui_filter_head" }, 4.107 + content = function() 4.108 + slot.put(filter.label or "Filter", ": ") 4.109 + for idx, option in ipairs(filter) do 4.110 + params[filter_name] = option.name 4.111 + local attr = {} 4.112 + if current_option == option.name then 4.113 + attr.class = "active" 4.114 + option.selector_modifier(args.selector) 4.115 + end 4.116 + ui.link{ 4.117 + attr = attr, 4.118 + module = request.get_module(), 4.119 + view = request.get_view(), 4.120 + id = id, 4.121 + params = params, 4.122 + text = option.label, 4.123 + partial = { 4.124 + params = { 4.125 + [filter_name] = option.name 4.126 + } 4.127 + } 4.128 + } 4.129 + end 4.130 + end 4.131 + } 4.132 + end 4.133 + end 4.134 + } 4.135 + end 4.136 + } 4.137 + ui.container{ 4.138 + attr = { class = "ui_filter_content" }, 4.139 + content = function() 4.140 + args.content() 4.141 + end 4.142 + } 4.143 +end