Title sez goal, 1000 words below;
I have stripped this down as much as I can, to simplify debugging - which I have failed at
To get the picture above, I manually populated the config file, which loads OK;
I seem to missing / not comprehending something.
What I am seeing (firefox console), on page load:
many instances (SyntaxError: "Unhandled token "value""):
raise https://127.0.0.1/luci-static/resources/luci.js?v=git-19.196.26199-784e764:84
compile https://127.0.0.1/luci-static/resources/validation.js:17
__init__ https://127.0.0.1/luci-static/resources/validation.js:1
ClassConstructor https://127.0.0.1/luci-static/resources/luci.js?v=git-19.196.26199-784e764:11
create https://127.0.0.1/luci-static/resources/validation.js:12
cbi_validate_field https://127.0.0.1/luci-static/resources/cbi.js?v=git-19.196.26199-784e764:58
cbi_init https://127.0.0.1/luci-static/resources/cbi.js?v=git-19.196.26199-784e764:46
setupDOM https://127.0.0.1/luci-static/resources/luci.js?v=git-19.196.26199-784e764:clock1130:
many instances (SyntaxError: "Unhandled token "button""):
raise https://127.0.0.1/luci-static/resources/luci.js?v=git-19.196.26199-784e764:84
compile https://127.0.0.1/luci-static/resources/validation.js:17
__init__ https://127.0.0.1/luci-static/resources/validation.js:1
ClassConstructor https://127.0.0.1/luci-static/resources/luci.js?v=git-19.196.26199-784e764:11
create https://127.0.0.1/luci-static/resources/validation.js:12
cbi_validate_field https://127.0.0.1/luci-static/resources/cbi.js?v=git-19.196.26199-784e764:58
cbi_init https://127.0.0.1/luci-static/resources/cbi.js?v=git-19.196.26199-784e764:46
setupDOM https://127.0.0.1/luci-static/resources/luci.js?v=git-19.196.26199-784e764:113
When I select an example and press OK nothing but page reload happens.
Files:
/etc/config/example (starts empty until section created)
/etc/config/example_sections (used to populate dropbox for examples to select, selected contents to /etc/config/example when added):
config example 'Select'
option name 'Please select example'
config example 'example_1'
option name 'example_1'
option description 'Example_1'
option product_url 'www.rossco.org'
option payment_id ''
config example 'example_2'
option name 'example_2'
option description 'Example_2'
option product_url 'www.rossco.org'
option payment_id ''
/usr/lib/lua/luci/controller/example.lua:
-- luci.controller.name of application directory.name of application(resolves to application.lua)
module("luci.controller.example", package.seeall)
function index()
if not nixio.fs.access("/etc/config/example") then
return
end
local page
-- this adds the top level tab and defaults to the first sub-tab, also it is set to position 30
entry({"admin", "system", "Example"}, firstchild(), "Example", 2).dependent=false
entry({"admin", "system", "Example", "example"}, cbi("example_tab"), "Registration", 1)
end
/usr/lib/lua/luci/model/cbi/example_tab.lua:
-- to see call tree for functions (to understand calling order)
-- m.message = m.message .. debug.traceback()
local util = require("luci.util")
local uci = require "luci.model.uci".cursor()
local fs = require "nixio.fs"
local logfile = "/var/log/vtdaemon.log"
local licenseFile = "example"
local licensesFile = "example_sections"
local daemonCmd = "vtdaemon -D file logfile -S "
local a, b, c, btn1, btn2, btn3, btn4, btn5, m, m1, s, s1
local select_options = { }
m = Map(licenseFile, translate("Manage Applications / Licences"), "")
-- licenseFile is the config file in /etc/config
--m.message = ""
s = m:section(TypedSection, "example", "Select Example to Add")
-- example is the section called "example" in config file
s.addremove = true
s.sectionhead = "Application"
s.template = "cbi/tblsection"
s.template_addremove = "example-select-input-add"
s.add_select_options = select_options
uci:load(licensesFile)
uci:foreach( licensesFile, "example",
function(section)
select_options[section['.name']] = section['name'] or section['description']
end
)
function s.create(self, name)
-- sections are initially created from /etc/config/example_sections
-- by: m = Map("example", translate("Manage Licences"), "")
-- and s.create is only called when a new section is created from dropdown listbox
-- section is populated with defaults from /etc/config/example_sections
if name and not name:match("[^a-zA-Z0-9_]") then
if name ~= "Select" then
-- Don`t add section if "Select" (used only for dropdown section default menu entry)
uci:section( licenseFile, "example", name, uci:get_all( licensesFile, name ) )
uci:save(licenseFile)
end
else
m.message = "invalid"
self.invalid_cts = true
end
end
function s.validate(self, section)
if section == "Select" then
return nil
end
return section
end
function s.remove(self, section)
-- Remove application first
local cmd = daemonCmd .. section .. " -U"
cmdret = luci.sys.exec( cmd )
return TypedSection.remove(self, section)
end
function s.remove(self, section)
-- Remove application first
local cmd = daemonCmd .. section .. " -U"
cmdret = luci.sys.exec( cmd )
return TypedSection.remove(self, section)
end
a = s:option(Value, "description", translate("Description")); a.optional=false; a.rmempty = false;
a.readonly = true
function a.cfgvalue(self, section)
local val = AbstractValue.cfgvalue(self, section)
return val
end
b = s:option(Value, "product_url", translate("Application Support Site")); b.optional=false; b.rmempty = false;
b.readonly = true
function b.cfgvalue(self, section)
local val = AbstractValue.cfgvalue(self, section)
return val
end
c = s:option(Value, "payment_id", translate("Purchase Receipt ID#")); c.optional=false; c.rmempty = false;
function c.cfgvalue(self, section)
local val = AbstractValue.cfgvalue(self, section)
return val or ""
end
function c:validate(value)
if ( value ~= nil ) and ( string.len(value) > 63 ) then
return nil, translate("Receipt maximum length = 63")
end
return value
end
btn = s:option( Button, "_btn1", translate("Register"), "")
btn.value = "Register"
function btn.write(self, section, value)
local cmd = daemonCmd .. section .. " -R"
cmdret = luci.sys.exec( cmd )
return reload
end
btn = s:option( Button, "_btn2", translate("Install"), "")
btn.value = "Install"
function btn.write(self, section, value)
local cmd = daemonCmd .. section .. " -G"
cmdret = luci.sys.exec( cmd )
return reload
end
btn = s:option( Button, "_btn3", translate("Verify"), "")
btn.value = "Verify"
function btn.write(self, section, value)
local cmd = daemonCmd .. section .. " -V"
cmdret = luci.sys.exec( cmd )
return reload
end
btn = s:option( Button, "_btn4", translate("Remove"), "")
btn.value = "Remove"
function btn.write(self, section, value)
local cmd = daemonCmd .. section .. " -U"
cmdret = luci.sys.exec( cmd )
return reload
end
return m, m1, m2
/usr/lib/lua/luci/view/example-select-input-add.htm (custom template for populating dropdown):
<div class="cbi-section-create">
<select class="cbi-section-create-name" name="cbi.cts.<%=self.config%>.<%=self.sectiontype%>.select">
<%- for k, v in luci.util.kspairs(self.add_select_options) do %>
<option value="<%=k%>"><%=luci.util.pcdata(v)%></option>
<% end -%>
</select>
<input class="cbi-button cbi-button-add" type="submit" value="<%:Add%>" title="<%:Add%>" />
</div>
At my wits end on this. Any suggestions?
Thanks;
Bill