gluon-web-model: allow exclusive options in MultiListValue
This commit is contained in:
		
							parent
							
								
									92feadfa23
								
							
						
					
					
						commit
						fee8384415
					
				
										
											
												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>
 | 
			
		||||
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -13,7 +13,7 @@
 | 
			
		||||
/*
 | 
			
		||||
	Build using:
 | 
			
		||||
 | 
			
		||||
	uglifyjs javascript/gluon-web-model.js -o files/lib/gluon/web/www/static/gluon-web-model.js -c -m --support-ie8
 | 
			
		||||
	uglifyjs javascript/gluon-web-model.js -o files/lib/gluon/web/www/static/gluon-web-model.js -c -m
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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 excusive_with = JSON.parse(node.getAttribute('data-exclusive-with'));
 | 
			
		||||
 | 
			
		||||
			node.disabled = false;
 | 
			
		||||
			for (let list_item of excusive_with) {
 | 
			
		||||
				var el = document.getElementById(node.name + '.' + list_item);
 | 
			
		||||
				node.disabled |= el.checked;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if (node.disabled)
 | 
			
		||||
				node.checked = false;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (state) {
 | 
			
		||||
			update();
 | 
			
		||||
		}
 | 
			
		||||
@ -533,6 +547,7 @@
 | 
			
		||||
			init_dynlist(node, attr);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		update();
 | 
			
		||||
	})();
 | 
			
		||||
})();
 | 
			
		||||
 | 
			
		||||
@ -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()
 | 
			
		||||
	local value = self.default
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user