liquid_feedback_frontend
changeset 295:fac04b72bc9a
Added modified filters function
author | bsw |
---|---|
date | Sat Feb 25 21:19:12 2012 +0100 (2012-02-25) |
parents | fee2fcc5d88e |
children | d39fa6c0ff0b |
files | env/ui/filters.lua |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/env/ui/filters.lua Sat Feb 25 21:19:12 2012 +0100 1.3 @@ -0,0 +1,142 @@ 1.4 +--[[-- 1.5 +ui.filters{ 1.6 + selector = selector, -- selector to be modified 1.7 + label = label, -- text to be displayed when filters are collapsed 1.8 + { 1.9 + name = name1, -- name of first filter (used as GET param) 1.10 + label = label1, -- label of first filter 1.11 + { 1.12 + name = name1a, -- name of first option of first filter 1.13 + label = label1a, -- label of first option of first filter 1.14 + selector_modifier = function(selector) 1.15 + ... 1.16 + end 1.17 + }, 1.18 + { 1.19 + name = name1b, -- name of second option of first filter 1.20 + label = label1b, -- label of second option of first filter 1.21 + selector_modifier = function(selector) 1.22 + ... 1.23 + end 1.24 + }, 1.25 + ... 1.26 + }, 1.27 + { 1.28 + name = name2, -- name of second filter (used as GET param) 1.29 + label = label2, -- label of second filter 1.30 + { 1.31 + ... 1.32 + }, { 1.33 + ... 1.34 + }, 1.35 + ... 1.36 + }, 1.37 + ... 1.38 + content = function() 1.39 + ... -- inner code where filter is to be applied 1.40 + end 1.41 +} 1.42 + 1.43 +--]]-- 1.44 + 1.45 +function ui.filters(args) 1.46 + local el_id = ui.create_unique_id() 1.47 + ui.container{ 1.48 + attr = { class = "ui_filter" }, 1.49 + content = function() 1.50 + ui.container{ 1.51 + attr = { 1.52 + class = "ui_filter_closed_head" 1.53 + }, 1.54 + content = function() 1.55 + if args.folded then 1.56 + ui.tag{ 1.57 + tag = "span", 1.58 + content = function() 1.59 + local current_options = {} 1.60 + for idx, filter in ipairs(args) do 1.61 + local filter_name = filter.name or "filter" 1.62 + local current_option = atom.string:load(cgi.params[filter_name]) 1.63 + if not current_option then 1.64 + current_option = param.get(filter_name) 1.65 + end 1.66 + if not current_option or #current_option == 0 then 1.67 + current_option = filter[1].name 1.68 + end 1.69 + for idx, option in ipairs(filter) do 1.70 + if current_option == option.name then 1.71 + current_options[#current_options+1] = encode.html(filter.label) .. ": " .. encode.html(option.label) 1.72 + end 1.73 + end 1.74 + end 1.75 + slot.put(table.concat(current_options, "; ")) 1.76 + end 1.77 + } 1.78 + slot.put(" (") 1.79 + ui.link{ 1.80 + attr = { 1.81 + onclick = "this.parentNode.style.display='none'; document.getElementById('" .. el_id .. "_head').style.display='block'; return(false);" 1.82 + }, 1.83 + text = args.label, 1.84 + external = "#" 1.85 + } 1.86 + slot.put(")") 1.87 + end 1.88 + end 1.89 + } 1.90 + ui.container{ 1.91 + attr = { 1.92 + id = el_id .. "_head", 1.93 + style = args.folded and "display: none;" or nil 1.94 + }, 1.95 + content = function() 1.96 + for idx, filter in ipairs(args) do 1.97 + local filter_name = filter.name or "filter" 1.98 + local current_option = atom.string:load(cgi.params[filter_name]) 1.99 + if not current_option then 1.100 + current_option = param.get(filter_name) 1.101 + end 1.102 + if not current_option or #current_option == 0 then 1.103 + current_option = filter[1].name 1.104 + end 1.105 + local id = param.get_id_cgi() 1.106 + local params = param.get_all_cgi() 1.107 + ui.container{ 1.108 + attr = { class = "ui_filter_head" }, 1.109 + content = function() 1.110 + slot.put(filter.label) 1.111 + for idx, option in ipairs(filter) do 1.112 + params[filter_name] = option.name 1.113 + local attr = {} 1.114 + if current_option == option.name then 1.115 + attr.class = "active" 1.116 + option.selector_modifier(args.selector) 1.117 + end 1.118 + ui.link{ 1.119 + attr = attr, 1.120 + module = request.get_module(), 1.121 + view = request.get_view(), 1.122 + id = id, 1.123 + params = params, 1.124 + text = option.label, 1.125 + partial = { 1.126 + params = { 1.127 + [filter_name] = option.name 1.128 + } 1.129 + } 1.130 + } 1.131 + end 1.132 + end 1.133 + } 1.134 + end 1.135 + end 1.136 + } 1.137 + end 1.138 + } 1.139 + ui.container{ 1.140 + attr = { class = "ui_filter_content" }, 1.141 + content = function() 1.142 + args.content() 1.143 + end 1.144 + } 1.145 +end