Like I said I'd like to pass down some Lua variables into the template and don't know how. I can duplicate the code like I've done for testing, but I'd like to avoid that. Also, even with the code duplication, how do I grab the token?
My problem must be somewhere else then.
This is my template:
<div class="cbi-value"><label class="cbi-value-title">Service Control</label>
<div class="cbi-value-field">
<form method="post" name="simple-adblock-action" action="<%=url("admin/services/simple-adblock-action")%>">
<%-
local style
if tmpfsStatus == "Stopped" then
style = "cbi-button cbi-button-apply important"
else
style = "cbi-button cbi-button-apply disabled"
end
-%>
<input type="submit" class="<%=style%>" name="start" value="<%:Start%>" />
<%-
local style
if tmpfsStatus == "Stopped" then
style = "cbi-button cbi-button-apply disabled"
else
style = "cbi-button cbi-button-apply important"
end
-%>
<input type="submit" class="<%=style%>" name="dl" value="<%:Force Re-Download%>" />
<%-
local style
if tmpfsStatus == "Stopped" then
style = "cbi-button cbi-button-reset disabled"
else
style = "cbi-button cbi-button-reset important"
end
-%>
<input type="submit" class="<%=style%>" name="stop" value="<%:Stop%>" />
<%-
local style
if enabledFlag ~= "1" then
style = "cbi-button cbi-button-apply important"
else
style = "cbi-button cbi-button-apply disabled"
end
-%>
<input type="submit" class="<%=style%>" name="enable" value="<%:Enable%>" />
<%-
local style
if enabledFlag ~= "1" then
style = "cbi-button cbi-button-reset disabled"
else
style = "cbi-button cbi-button-reset important"
end
-%>
<input type="submit" class="<%=style%>" name="disable" value="<%:Disable%>" />
</form>
</div>
</div>
And looks like the action_simple_adblock function in controller is not even being called:
module("luci.controller.simple-adblock", package.seeall)
function index()
if not nixio.fs.access("/etc/config/simple-adblock") then
return
end
entry({"admin", "services", "simple-adblock"}, cbi("simple-adblock"), _("Simple AdBlock"))
entry({"admin", "services", "simple-adblock-action"}, post("action_simple_adblock")).leaf = true
end
function action_simple_adblock()
luci.sys.exec("logger luci test")
local packageName = "simple-adblock"
if luci.http.formvalue("start") then
luci.sys.init.start(packageName)
elseif luci.http.formvalue("stop") then
luci.sys.init.stop(packageName)
elseif luci.http.formvalue("enable") then
luci.sys.init.enable(packageName)
elseif luci.http.formvalue("disable") then
luci.sys.init.disable(packageName)
elseif luci.http.formvalue("dl") then
luci.util.exec("/etc/init.d/simple-adblock dl")
end
luci.http.redirect(luci.dispatcher.build_url("admin", "services", packageName))
end
Thank you so much! Had to do (new XHR()). but otherwise it works!
I've tried to google, but failed -- how can I delay the re-rendering of the page? Some operations take time and I want to be able to either wait a few seconds or wait until whatever's called with XHR.post has completed.