liquid_feedback_frontend

changeset 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 82f13fbbc05a
children 350218637753
files env/ui/filters.lua
line diff
     1.1 --- a/env/ui/filters.lua	Fri Aug 17 00:03:23 2012 +0200
     1.2 +++ b/env/ui/filters.lua	Fri Aug 17 00:22:48 2012 +0200
     1.3 @@ -1,139 +1,56 @@
     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 +      for idx, filter in ipairs(args) do
    1.88 +        local filter_name = filter.name or "filter"
    1.89 +        local current_option = atom.string:load(cgi.params[filter_name])
    1.90 +        if not current_option then
    1.91 +          current_option = param.get(filter_name)
    1.92 +        end
    1.93 +        local current_option_valid = false
    1.94 +        for idx, option in ipairs(filter) do
    1.95 +          if current_option == option.name then
    1.96 +            current_option_valid = true
    1.97            end
    1.98          end
    1.99 -      }
   1.100 -      ui.container{
   1.101 -        attr = {
   1.102 -          id = el_id .. "_head",
   1.103 -          style = args.folded and "display: none;" or nil
   1.104 -        },
   1.105 -        content = function()
   1.106 -          for idx, filter in ipairs(args) do
   1.107 -            local filter_name = filter.name or "filter"
   1.108 -            local current_option = atom.string:load(cgi.params[filter_name])
   1.109 -            if not current_option then
   1.110 -              current_option = param.get(filter_name)
   1.111 -            end
   1.112 -            if not current_option or #current_option == 0 then
   1.113 -              current_option = filter[1].name
   1.114 +        if not current_option or #current_option == 0 or not current_option_valid then
   1.115 +          current_option = filter[1].name
   1.116 +        end
   1.117 +        local id     = param.get_id_cgi()
   1.118 +        local params = param.get_all_cgi()
   1.119 +        ui.container{
   1.120 +          attr = { class = "ui_filter_head" },
   1.121 +          content = function()
   1.122 +            slot.put(filter.label)
   1.123 +            for idx, option in ipairs(filter) do
   1.124 +              params[filter_name] = option.name
   1.125 +              local attr = {}
   1.126 +              if current_option == option.name then
   1.127 +                attr.class = "active"
   1.128 +                option.selector_modifier(args.selector)
   1.129 +              end
   1.130 +              if idx > 1 then
   1.131 +                slot.put(" ")
   1.132 +              end
   1.133 +              ui.link{
   1.134 +                attr    = attr,
   1.135 +                module  = request.get_module(),
   1.136 +                view    = request.get_view(),
   1.137 +                id      = id,
   1.138 +                params  = params,
   1.139 +                text    = option.label,
   1.140 +                partial = {
   1.141 +                  params = {
   1.142 +                    [filter_name] = option.name
   1.143 +                  }
   1.144 +                }
   1.145 +              }
   1.146              end
   1.147 -            local id     = param.get_id_cgi()
   1.148 -            local params = param.get_all_cgi()
   1.149 -            ui.container{
   1.150 -              attr = { class = "ui_filter_head" },
   1.151 -              content = function()
   1.152 -                slot.put(filter.label)
   1.153 -                for idx, option in ipairs(filter) do
   1.154 -                  params[filter_name] = option.name
   1.155 -                  local attr = {}
   1.156 -                  if current_option == option.name then
   1.157 -                    attr.class = "active"
   1.158 -                    option.selector_modifier(args.selector)
   1.159 -                  end
   1.160 -                  if idx > 1 then
   1.161 -                    slot.put(" ")
   1.162 -                  end
   1.163 -                  ui.link{
   1.164 -                    attr    = attr,
   1.165 -                    module  = request.get_module(),
   1.166 -                    view    = request.get_view(),
   1.167 -                    id      = id,
   1.168 -                    params  = params,
   1.169 -                    text    = option.label,
   1.170 -                    partial = {
   1.171 -                      params = {
   1.172 -                        [filter_name] = option.name
   1.173 -                      }
   1.174 -                    }
   1.175 -                  }
   1.176 -                end
   1.177 -              end
   1.178 -            }
   1.179            end
   1.180 -        end
   1.181 -      }
   1.182 +        }
   1.183 +      end
   1.184      end
   1.185    }
   1.186    ui.container{

Impressum / About Us