gluon-web-model: add exclusive options for MultiListValue
This commit is contained in:
parent
03b9ffdb24
commit
7805ff700e
File diff suppressed because one or more lines are too long
@ -273,6 +273,10 @@ input[type=checkbox] {
|
||||
text-align: center;
|
||||
font-size: 1.7em;
|
||||
}
|
||||
|
||||
&[disabled] + label {
|
||||
background-color: #dcdcdc !important;
|
||||
}
|
||||
}
|
||||
|
||||
input[type=radio] {
|
||||
|
@ -13,7 +13,9 @@
|
||||
attr("id", id.."."..entry.key) ..
|
||||
attr("name", id) ..
|
||||
attr("value", entry.key) ..
|
||||
attr("checked", (util.contains(self:cfgvalue(), entry.key)) and "checked")
|
||||
attr("checked", (util.contains(self:cfgvalue(), entry.key)) and "checked") ..
|
||||
attr("data-exclusive-with", self.exclusions[entry.key]) ..
|
||||
attr("data-update", "change")
|
||||
%>>
|
||||
<label<%= attr("for", id.."."..entry.key)%>></label>
|
||||
<span class="gluon-multi-list-option-descr"><%|entry.value%></span>
|
||||
|
@ -219,6 +219,20 @@
|
||||
parent.parentNode.style.display = (parent.options.length <= 1) ? 'none' : '';
|
||||
}
|
||||
|
||||
var nodes = document.querySelectorAll('[data-exclusive-with]');
|
||||
for (var i = 0, node; (node = nodes[i]) !== undefined; i++) {
|
||||
var exclusive_with = JSON.parse(node.getAttribute('data-exclusive-with'));
|
||||
|
||||
node.disabled = false;
|
||||
for (var list_item of exclusive_with) {
|
||||
var el = document.getElementById(node.name + '.' + list_item);
|
||||
node.disabled ||= el.checked;
|
||||
}
|
||||
|
||||
if (node.disabled)
|
||||
node.checked = false;
|
||||
}
|
||||
|
||||
if (state) {
|
||||
update();
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -3,6 +3,7 @@
|
||||
-- Licensed to the public under the Apache License 2.0.
|
||||
|
||||
local util = require "gluon.web.util"
|
||||
local gluon_util = require "gluon.util"
|
||||
|
||||
local datatypes = require "gluon.web.model.datatypes"
|
||||
local class = util.class
|
||||
@ -381,6 +382,7 @@ function MultiListValue:value(key, val, ...)
|
||||
return
|
||||
end
|
||||
self.keys[key] = true
|
||||
self.exclusions = {}
|
||||
|
||||
val = val or key
|
||||
table.insert(self.entry_list, {
|
||||
@ -403,9 +405,31 @@ function MultiListValue:validate()
|
||||
end
|
||||
end
|
||||
|
||||
for key, exclusive_with in pairs(self.exclusions) do
|
||||
if gluon_util.contains(self.data, key) then
|
||||
for _, exclusion in ipairs(exclusive_with) do
|
||||
if gluon_util.contains(self.data, exclusion) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function MultiListValue:exclusive(a, b)
|
||||
if not self.exclusions[a] then
|
||||
self.exclusions[a] = {}
|
||||
end
|
||||
if not self.exclusions[b] then
|
||||
self.exclusions[b] = {}
|
||||
end
|
||||
|
||||
gluon_util.add_to_set(self.exclusions[a], b)
|
||||
gluon_util.add_to_set(self.exclusions[b], a)
|
||||
end
|
||||
|
||||
function MultiListValue:defaultvalue()
|
||||
return self.default or {}
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user