gluon-web-model: add MultiListValue class
This commit is contained in:
		
							parent
							
								
									c22ae0449f
								
							
						
					
					
						commit
						29167d9ea9
					
				
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -366,6 +366,13 @@ input[type=password] {
 | 
				
			|||||||
	min-width: 20em;
 | 
						min-width: 20em;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					.gluon-multi-list-option-descr {
 | 
				
			||||||
 | 
						display: inline-block;
 | 
				
			||||||
 | 
						vertical-align: top;
 | 
				
			||||||
 | 
						margin-top: 0.35em;
 | 
				
			||||||
 | 
						margin-left: 0.4em;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.gluon-button {
 | 
					.gluon-button {
 | 
				
			||||||
	@include 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,66 @@ function ListValue:validate()
 | 
				
			|||||||
end
 | 
					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()
 | 
				
			||||||
 | 
						local value = self.default
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if type(value) == "table" then
 | 
				
			||||||
 | 
							return value
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							return { value }
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function MultiListValue:formvalue(http)
 | 
				
			||||||
 | 
						return http:formvaluetable(self:id())
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local DynamicList = class(AbstractValue)
 | 
					local DynamicList = class(AbstractValue)
 | 
				
			||||||
M.DynamicList = DynamicList
 | 
					M.DynamicList = DynamicList
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user