Commits

Anonymous committed a29c8ff

New function ui.filters{...}

Also changed version information to "1.0.8"

  • Participants
  • Parent commits 39652c7
  • Tags v1.0.8

Comments (0)

Files changed (4)

doc/autodoc-header.htmlpart

         color: #505050;
       }
     </style>
-    <title>WebMCP 1.0.7 Documentation</title>
+    <title>WebMCP 1.0.8 Documentation</title>
   </head>
   <body>
-    <h1>WebMCP 1.0.7 Documentation</h1>
+    <h1>WebMCP 1.0.8 Documentation</h1>
     <p>
       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.
     </p>

framework/cgi-bin/webmcp.lua

 #!/usr/bin/env lua
 
-_WEBMCP_VERSION = "1.0.7"
+_WEBMCP_VERSION = "1.0.8"
 
 -- include "../lib/" in search path for libraries
 do

framework/env/ui/container.lua

   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
 }
 

framework/env/ui/filters.lua

+--[[--
+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