--[[
-FFLuCI - Configuration Bind Interface
+LuCI - Configuration Bind Interface
Description:
Offers an interface for binding confiugration values to certain
limitations under the License.
]]--
-module("ffluci.cbi", package.seeall)
+module("luci.cbi", package.seeall)
-require("ffluci.template")
-require("ffluci.util")
-require("ffluci.http")
-require("ffluci.model.uci")
+require("luci.template")
+require("luci.util")
+require("luci.http")
+require("luci.model.uci")
-local class = ffluci.util.class
-local instanceof = ffluci.util.instanceof
+local class = luci.util.class
+local instanceof = luci.util.instanceof
-- Loads a CBI map from given file, creating an environment and returns it
function load(cbimap)
- require("ffluci.fs")
- require("ffluci.i18n")
- require("ffluci.config")
- require("ffluci.sys")
+ require("luci.fs")
+ require("luci.i18n")
+ require("luci.config")
+ require("luci.sys")
- local cbidir = ffluci.sys.libpath() .. "/model/cbi/"
+ local cbidir = luci.sys.libpath() .. "/model/cbi/"
local func, err = loadfile(cbidir..cbimap..".lua")
if not func then
return nil
end
- ffluci.i18n.loadc("cbi")
+ luci.i18n.loadc("cbi")
- ffluci.util.resfenv(func)
- ffluci.util.updfenv(func, ffluci.cbi)
- ffluci.util.extfenv(func, "translate", ffluci.i18n.translate)
+ luci.util.resfenv(func)
+ luci.util.updfenv(func, luci.cbi)
+ luci.util.extfenv(func, "translate", luci.i18n.translate)
local map = func()
scope = scope or {}
scope.self = self
- ffluci.template.render(self.template, scope)
+ luci.template.render(self.template, scope)
end
-- Render the children
Node.__init__(self, ...)
self.config = config
self.template = "cbi/map"
- self.uci = ffluci.model.uci.Session()
+ self.uci = luci.model.uci.Session()
self.ucidata, self.uciorder = self.uci:sections(self.config)
if not self.ucidata or not self.uciorder then
error("Unable to read UCI data: " .. self.config)
self.optionals[section] = {}
- local field = ffluci.http.formvalue("cbi.opt."..self.config.."."..section)
+ local field = luci.http.formvalue("cbi.opt."..self.config.."."..section)
for k,v in ipairs(self.children) do
if v.optional and not v:cfgvalue(section) then
if field == v.option then
return
end
- local arr = ffluci.util.clone(self:cfgvalue(section))
- local form = ffluci.http.formvaluetable("cbid."..self.config.."."..section)
+ local arr = luci.util.clone(self:cfgvalue(section))
+ local form = luci.http.formvaluetable("cbid."..self.config.."."..section)
for k, v in pairs(form) do
arr[k] = v
end
if self.addremove then
local path = self.config.."."..s
if active then -- Remove the section
- if ffluci.http.formvalue("cbi.rns."..path) and self:remove(s) then
+ if luci.http.formvalue("cbi.rns."..path) and self:remove(s) then
return
end
else -- Create and apply default values
- if ffluci.http.formvalue("cbi.cns."..path) and self:create(s) then
+ if luci.http.formvalue("cbi.cns."..path) and self:create(s) then
for k,v in pairs(self.children) do
v:write(s, v.default)
end
if active then
AbstractSection.parse_dynamic(self, s)
- if ffluci.http.formvalue("cbi.submit") then
+ if luci.http.formvalue("cbi.submit") then
Node.parse(self, s)
end
AbstractSection.parse_optionals(self, s)
if self.addremove then
-- Create
local crval = "cbi.cts." .. self.config .. "." .. self.sectiontype
- local name = ffluci.http.formvalue(crval)
+ local name = luci.http.formvalue(crval)
if self.anonymous then
if name then
self:create()
-- Remove
crval = "cbi.rts." .. self.config
- name = ffluci.http.formvaluetable(crval)
+ name = luci.http.formvaluetable(crval)
for k,v in pairs(name) do
if self:cfgvalue(k) and self:checkscope(k) then
self:remove(k)
for i, k in ipairs(self:cfgsections()) do
AbstractSection.parse_dynamic(self, k)
- if ffluci.http.formvalue("cbi.submit") then
+ if luci.http.formvalue("cbi.submit") then
Node.parse(self, k)
end
AbstractSection.parse_optionals(self, k)
-- Return whether this object should be created
function AbstractValue.formcreated(self, section)
local key = "cbi.opt."..self.config.."."..section
- return (ffluci.http.formvalue(key) == self.option)
+ return (luci.http.formvalue(key) == self.option)
end
-- Returns the formvalue for this object
function AbstractValue.formvalue(self, section)
local key = "cbid."..self.map.config.."."..section.."."..self.option
- return ffluci.http.formvalue(key)
+ return luci.http.formvalue(key)
end
function AbstractValue.parse(self, section)
val = nil
end
- return ffluci.util.validate(val, self.isnumber, self.isinteger)
+ return luci.util.validate(val, self.isnumber, self.isinteger)
end
end
function DummyValue.render(self, s)
- ffluci.template.render(self.template, {self=self, section=s})
+ luci.template.render(self.template, {self=self, section=s})
end
end
function ListValue.validate(self, val)
- if ffluci.util.contains(self.keylist, val) then
+ if luci.util.contains(self.keylist, val) then
return val
else
return nil
return {}
end
- return ffluci.util.split(val, self.delimiter)
+ return luci.util.split(val, self.delimiter)
end
function MultiValue.validate(self, val)
local result = ""
for value in val:gmatch("[^\n]+") do
- if ffluci.util.contains(self.keylist, value) then
+ if luci.util.contains(self.keylist, value) then
result = result .. self.delimiter .. value
end
end