liquid_feedback_frontend

annotate env/ui/filters.lua @ 852:376e3ed9b245

Removed not needed code from ui.filters, handle invalid filter options better
author bsw
date Fri Aug 17 00:22:48 2012 +0200 (2012-08-17)
parents 76d7eafb3893
children 701a5cf6b067
rev   line source
bsw@295 1 function ui.filters(args)
bsw@295 2 local el_id = ui.create_unique_id()
bsw@295 3 ui.container{
bsw@295 4 attr = { class = "ui_filter" },
bsw@295 5 content = function()
bsw@852 6 for idx, filter in ipairs(args) do
bsw@852 7 local filter_name = filter.name or "filter"
bsw@852 8 local current_option = atom.string:load(cgi.params[filter_name])
bsw@852 9 if not current_option then
bsw@852 10 current_option = param.get(filter_name)
bsw@852 11 end
bsw@852 12 local current_option_valid = false
bsw@852 13 for idx, option in ipairs(filter) do
bsw@852 14 if current_option == option.name then
bsw@852 15 current_option_valid = true
bsw@295 16 end
bsw@295 17 end
bsw@852 18 if not current_option or #current_option == 0 or not current_option_valid then
bsw@852 19 current_option = filter[1].name
bsw@852 20 end
bsw@852 21 local id = param.get_id_cgi()
bsw@852 22 local params = param.get_all_cgi()
bsw@852 23 ui.container{
bsw@852 24 attr = { class = "ui_filter_head" },
bsw@852 25 content = function()
bsw@852 26 slot.put(filter.label)
bsw@852 27 for idx, option in ipairs(filter) do
bsw@852 28 params[filter_name] = option.name
bsw@852 29 local attr = {}
bsw@852 30 if current_option == option.name then
bsw@852 31 attr.class = "active"
bsw@852 32 option.selector_modifier(args.selector)
bsw@852 33 end
bsw@852 34 if idx > 1 then
bsw@852 35 slot.put(" ")
bsw@852 36 end
bsw@852 37 ui.link{
bsw@852 38 attr = attr,
bsw@852 39 module = request.get_module(),
bsw@852 40 view = request.get_view(),
bsw@852 41 id = id,
bsw@852 42 params = params,
bsw@852 43 text = option.label,
bsw@852 44 partial = {
bsw@852 45 params = {
bsw@852 46 [filter_name] = option.name
bsw@852 47 }
bsw@852 48 }
bsw@852 49 }
bsw@295 50 end
bsw@295 51 end
bsw@852 52 }
bsw@852 53 end
bsw@295 54 end
bsw@295 55 }
bsw@295 56 ui.container{
bsw@295 57 attr = { class = "ui_filter_content" },
bsw@295 58 content = function()
bsw@295 59 args.content()
bsw@295 60 end
bsw@295 61 }
bsw@295 62 end

Impressum / About Us