local util = require("util")
local data = util.merge({notification=''},{ opts = app.opts })
data.plugins = ""
function pluginInput(opt)
local html = ""
html = html .. [[
]]
html = html .. opt.title
html = html .. [[
]]
local value = app.opts[ opt.key:gsub("^app.opts.","") ]
if type(opt.values) == 'table' then
html = html .. util.template('\n"
else
html = html .. util.template('',{
key = opt.key,
value = value
})
end
html = html .. util.template([[
${info}
]],opt)
return html
end
function pluginUI(seen)
return function(name,plugin)
if seen[ plugin.name ] then return end -- already processed
seen[ plugin.name ] = true
local plugindata = util.flatten(plugin,"plugin")
plugindata.opts = ""
foreach(plugin.opts, function(k,opt)
plugindata.opts = plugindata.opts .. pluginInput(opt)
end)
data.plugins = data.plugins .. util.template( LoadAsset('/page/admin/plugin.html'), plugindata)
end
end
function saveData()
if GetMethod() == 'POST' then
local params = GetParams()
local saveconfig = false
foreach(params, function(k,v)
if v[1]:match("^opts.") then
app.opts[ v[1]:gsub("^opts.","") ] = v[2] -- update
saveconfig = true
end
end)
if saveconfig then
app.set('app.opts', app.opts )
data.notification = '
updated
'
else
data.notification = '
no changes detected
'
end
end
end
local seen = {}
foreach( app.plugin, pluginUI(seen) )
saveData()
local html = util.template( LoadAsset("page/admin/index.html"),data)
SetStatus(200)
SetHeader('Content-Type', 'text/html; charset=utf-8')
Write( html )