mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-29 14:45:13 +08:00
🐤 Sync 2026-09-10 23:45:40
This commit is contained in:
1 parent
d6a0283d87
commit
e5ebaf889a
31 files changed
+469
-183
No files matched your search
@@ -1517,11 +1517,111 @@ function set_default_cbi()
|
||||
return cbi.AbstractValue.write(self, section, new_val)
|
||||
end
|
||||
end
|
||||
if true then
|
||||
--HideValue
|
||||
local HideValue = util.class(cbi.DummyValue)
|
||||
function HideValue.__init__(self, ...)
|
||||
cbi.DummyValue.__init__(self, ...)
|
||||
self.template = self.map:template_path("/cbi/hidevalue")
|
||||
self.value = "1"
|
||||
end
|
||||
cbi.HideValue = HideValue
|
||||
end
|
||||
end
|
||||
|
||||
function set_type_cbi(s)
|
||||
local cbi = require "luci.cbi"
|
||||
local s1 = s.parent
|
||||
function s.option(s_self, class, option, ...)
|
||||
local obj = class(s_self.map, s_self, option, ...)
|
||||
obj.config_option = option
|
||||
obj.option_prefix = s_self.option_prefix
|
||||
obj.option = s_self.option_prefix .. option
|
||||
obj.cfgvalue = function(self, section)
|
||||
if self.rewrite_option then
|
||||
return self.map:get(section, self.rewrite_option)
|
||||
else
|
||||
return self.map:get(section, self.config_option)
|
||||
end
|
||||
end
|
||||
obj.write = function(self, section, value)
|
||||
if s1.fields["type"]:formvalue(s_self.section) == s_self.type_name then
|
||||
local new_val = value
|
||||
if util.instanceof(self, cbi.DynamicList) then
|
||||
local new_t = {}
|
||||
if type(value) == "table" then
|
||||
new_t = table_remove_duplicates(value)
|
||||
else
|
||||
new_t = { value }
|
||||
end
|
||||
if self.cast == "string" then
|
||||
new_val = table.concat(new_t, " ")
|
||||
else
|
||||
new_val = new_t
|
||||
end
|
||||
end
|
||||
if self.rewrite_option then
|
||||
self.map:set(section, self.rewrite_option, new_val)
|
||||
else
|
||||
self.map:set(section, self.config_option, new_val)
|
||||
end
|
||||
end
|
||||
end
|
||||
obj.remove = function(self, section)
|
||||
if s1.fields["type"]:formvalue(s_self.section) == s_self.type_name then
|
||||
if self.rewrite_option then
|
||||
self.map:del(section, self.rewrite_option)
|
||||
else
|
||||
self.map:del(section, self.config_option)
|
||||
end
|
||||
end
|
||||
end
|
||||
obj.deplist2json = function(self, section, deplist)
|
||||
local deps, i, d = { }
|
||||
if type(self.deps) == "table" then
|
||||
if not next(self.deps) then
|
||||
self:depends({ type = s.type_name })
|
||||
end
|
||||
local list = deplist or self.deps
|
||||
for i, d in ipairs(list) do
|
||||
if s.type_name and not d["type"] then
|
||||
d["type"] = s.type_name
|
||||
end
|
||||
local a, k, v = { }
|
||||
for k, v in pairs(d) do
|
||||
if k:find("!", 1, true) then
|
||||
a[k] = v
|
||||
elseif k:find("^", 1, true) then
|
||||
a[k:sub(2)] = v
|
||||
elseif k:find(".", 1, true) then
|
||||
a['cbid%s' % k] = v
|
||||
elseif s_self.fields[k] then
|
||||
a['cbid.%s.%s.%s' %{ self.config, section, s_self.fields[k].option }] = v
|
||||
else
|
||||
a['cbid.%s.%s.%s' %{ self.config, section, k }] = v
|
||||
end
|
||||
end
|
||||
deps[#deps+1] = a
|
||||
end
|
||||
end
|
||||
return util.serialize_json(deps)
|
||||
end
|
||||
s_self:append(obj)
|
||||
s_self.fields[option] = obj
|
||||
return obj
|
||||
end
|
||||
end
|
||||
|
||||
function type_cbi_section(s, s2)
|
||||
for i, v in ipairs(s2.children) do
|
||||
local o = s2.children[i]
|
||||
s:append(o)
|
||||
s.fields[o.option] = o
|
||||
end
|
||||
end
|
||||
|
||||
function return_map(map)
|
||||
local cbi = require "luci.cbi"
|
||||
local api = require "luci.passwall.api"
|
||||
if true then
|
||||
-- header
|
||||
local header = cbi.Template(appname .. "/cbi/header")
|
||||
@@ -1537,91 +1637,6 @@ function return_map(map)
|
||||
return map
|
||||
end
|
||||
|
||||
function set_type_cbi(s)
|
||||
local cbi = require "luci.cbi"
|
||||
local s1 = s.parent
|
||||
function s.option(self, class, option, ...)
|
||||
local obj = class(self.map, self, option, ...)
|
||||
obj.config_option = option
|
||||
obj.option_prefix = self.option_prefix
|
||||
obj.option = self.option_prefix .. option
|
||||
obj.cfgvalue = function(o_self, section)
|
||||
if o_self.rewrite_option then
|
||||
return o_self.map:get(section, o_self.rewrite_option)
|
||||
else
|
||||
return o_self.map:get(section, o_self.config_option)
|
||||
end
|
||||
end
|
||||
obj.write = function(o_self, section, value)
|
||||
if s1.fields["type"]:formvalue(self.section) == self.type_name then
|
||||
local new_val = value
|
||||
if util.instanceof(o_self, cbi.DynamicList) then
|
||||
local new_t = {}
|
||||
if type(value) == "table" then
|
||||
new_t = table_remove_duplicates(value)
|
||||
else
|
||||
new_t = { value }
|
||||
end
|
||||
if o_self.cast == "string" then
|
||||
new_val = table.concat(new_t, " ")
|
||||
else
|
||||
new_val = new_t
|
||||
end
|
||||
end
|
||||
if o_self.rewrite_option then
|
||||
o_self.map:set(section, o_self.rewrite_option, new_val)
|
||||
else
|
||||
o_self.map:set(section, o_self.config_option, new_val)
|
||||
end
|
||||
end
|
||||
end
|
||||
obj.remove = function(o_self, section)
|
||||
if s1.fields["type"]:formvalue(self.section) == self.type_name then
|
||||
if o_self.rewrite_option then
|
||||
o_self.map:del(section, o_self.rewrite_option)
|
||||
else
|
||||
o_self.map:del(section, o_self.config_option)
|
||||
end
|
||||
end
|
||||
end
|
||||
obj.depends = function(o_self, field, value)
|
||||
local deps
|
||||
if type(field) == "string" then
|
||||
deps = {}
|
||||
deps[field] = value
|
||||
else
|
||||
deps = field
|
||||
end
|
||||
local new_deps = {}
|
||||
for k, v in pairs(deps) do
|
||||
local n_k = k
|
||||
if self.fields[k] then
|
||||
n_k = self.fields[k].option
|
||||
end
|
||||
new_deps[n_k] = v
|
||||
end
|
||||
new_deps["type"] = self.type_name
|
||||
if next(new_deps) then
|
||||
table.insert(o_self.deps, new_deps)
|
||||
end
|
||||
end
|
||||
self:append(obj)
|
||||
self.fields[option] = obj
|
||||
return obj
|
||||
end
|
||||
end
|
||||
|
||||
function type_cbi_section(s, s2)
|
||||
for i, v in ipairs(s2.children) do
|
||||
local o = s2.children[i]
|
||||
if #o.deps == 0 then
|
||||
o:depends({ type = s2.type_name })
|
||||
end
|
||||
s:append(o)
|
||||
s.fields[o.option] = o
|
||||
end
|
||||
end
|
||||
|
||||
function get_std_domain(domain)
|
||||
domain = trim(domain)
|
||||
if domain == "" then return "" end
|
||||
|
||||
Reference in new issue
Block a user