gluon-web-model: add MultiListValue class
This commit is contained in:
parent
9ac048dbdf
commit
7cd4a189e0
@ -50,6 +50,7 @@ files["package/**/check_site.lua"] = {
|
||||
|
||||
files["package/**/luasrc/lib/gluon/config-mode/*"] = {
|
||||
globals = {
|
||||
"MultiListValue",
|
||||
"DynamicList",
|
||||
"Flag",
|
||||
"Form",
|
||||
|
File diff suppressed because one or more lines are too long
@ -366,6 +366,13 @@ input[type=password] {
|
||||
min-width: 20em;
|
||||
}
|
||||
|
||||
.gluon-multi-list-option-descr {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
margin-top: 0.35em;
|
||||
margin-left: 0.4em;
|
||||
}
|
||||
|
||||
.gluon-button {
|
||||
@include button;
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
<%
|
||||
local br = self.orientation == "horizontal" and '   ' or '<br>'
|
||||
local entries = self:entries()
|
||||
local util = require 'gluon.util'
|
||||
%>
|
||||
<div>
|
||||
<% for i, entry in pairs(entries) do %>
|
||||
<label<%=
|
||||
attr("data-index", i) ..
|
||||
attr("data-depends", self:deplist(entry.deps))
|
||||
%>>
|
||||
<input data-update="click change" type="checkbox"<%=
|
||||
attr("id", id.."."..entry.key) ..
|
||||
attr("name", id) ..
|
||||
attr("value", entry.key) ..
|
||||
attr("checked", (util.contains(self:cfgvalue(), entry.key)) and "checked")
|
||||
%>>
|
||||
<label<%= attr("for", id.."."..entry.key)%>></label>
|
||||
<span class="gluon-multi-list-option-descr"><%|entry.value%></span>
|
||||
</label>
|
||||
<% if i ~= #entries then write(br) end %>
|
||||
<% end %>
|
||||
</div>
|
@ -361,6 +361,60 @@ function ListValue:validate()
|
||||
end
|
||||
|
||||
|
||||
local MultiListValue = class(AbstractValue)
|
||||
M.MultiListValue = MultiListValue
|
||||
|
||||
function MultiListValue:__init__(...)
|
||||
AbstractValue.__init__(self, ...)
|
||||
self.subtemplate = "model/mlvalue"
|
||||
|
||||
self.size = 1
|
||||
|
||||
self.keys = {}
|
||||
self.entry_list = {}
|
||||
end
|
||||
|
||||
function MultiListValue:value(key, val, ...)
|
||||
key = tostring(key)
|
||||
|
||||
if self.keys[key] then
|
||||
return
|
||||
end
|
||||
self.keys[key] = true
|
||||
|
||||
val = val or key
|
||||
table.insert(self.entry_list, {
|
||||
key = key,
|
||||
value = tostring(val),
|
||||
deps = {...},
|
||||
})
|
||||
end
|
||||
|
||||
function MultiListValue:entries()
|
||||
local ret = {unpack(self.entry_list)}
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
function MultiListValue:validate()
|
||||
for _, val in ipairs(self.data) do
|
||||
if not self.keys[val] then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function MultiListValue:defaultvalue()
|
||||
return self.default or {}
|
||||
end
|
||||
|
||||
function MultiListValue:formvalue(http)
|
||||
return http:formvaluetable(self:id())
|
||||
end
|
||||
|
||||
|
||||
local DynamicList = class(AbstractValue)
|
||||
M.DynamicList = DynamicList
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user