luci-app-filebrowser: improve button
This commit is contained in:
parent
43883be99c
commit
a26f89e734
@ -7,4 +7,12 @@ function index()
|
||||
local page
|
||||
page = entry({"admin", "nas", "filebrowser"}, cbi("filebrowser"), _("文件管理器"), 100)
|
||||
page.dependent = true
|
||||
entry({"admin","nas","filebrowser","status"},call("act_status")).leaf=true
|
||||
end
|
||||
|
||||
function act_status()
|
||||
local e={}
|
||||
e.running=luci.sys.call("pgrep filebrowser >/dev/null")==0
|
||||
luci.http.prepare_content("application/json")
|
||||
luci.http.write_json(e)
|
||||
end
|
||||
|
||||
@ -1,31 +1,8 @@
|
||||
require("luci.sys")
|
||||
require("luci.util")
|
||||
require("luci.model.ipkg")
|
||||
local fs = require "nixio.fs"
|
||||
m = Map("filebrowser", translate("文件管理器"), translate("FileBrowser是一个基于Go的在线文件管理器,助您方便的管理设备上的文件。"))
|
||||
|
||||
local uci = require "luci.model.uci".cursor()
|
||||
m:section(SimpleSection).template = "filebrowser/filebrowser_status"
|
||||
|
||||
local m, s
|
||||
|
||||
local running=(luci.sys.call("pidof filebrowser > /dev/null") == 0)
|
||||
|
||||
local button = ""
|
||||
local state_msg = ""
|
||||
local trport = uci:get("filebrowser", "config", "port")
|
||||
if running then
|
||||
button = " <input type=\"button\" value=\" " .. translate("打开管理界面") .. " \" onclick=\"window.open('http://'+window.location.hostname+':" .. trport .. "')\"/>"
|
||||
end
|
||||
|
||||
if running then
|
||||
state_msg = "<b><font color=\"green\">" .. translate("FileBrowser运行中") .. "</font></b>"
|
||||
else
|
||||
state_msg = "<b><font color=\"red\">" .. translate("FileBrowser未运行") .. "</font></b>"
|
||||
end
|
||||
|
||||
m = Map("filebrowser", translate("文件管理器"), translate("FileBrowser是一个基于Go的在线文件管理器,助您方便的管理设备上的文件。") .. button
|
||||
.. "<br/><br/>" .. translate("FileBrowser运行状态").. " : " .. state_msg .. "<br/>")
|
||||
|
||||
s = m:section(TypedSection, "filebrowser", "")
|
||||
s = m:section(TypedSection, "filebrowser")
|
||||
s.addremove = false
|
||||
s.anonymous = true
|
||||
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
<script type="text/javascript">//<![CDATA[
|
||||
XHR.poll(1, '<%=url([[admin]], [[nas]], [[filebrowser]], [[status]])%>', null,
|
||||
function(x, data) {
|
||||
var tb = document.getElementById('filebrowser_status');
|
||||
if (data && tb) {
|
||||
if (data.running) {
|
||||
var links = '<font color=green>Filebrowser <%:运行中%></font><input class="cbi-button mar-10" type="button" value="<%:打开管理界面%>" onclick="openwebui();" />';
|
||||
tb.innerHTML = links;
|
||||
} else {
|
||||
tb.innerHTML = '<font color=red>Filebrowser <%:未运行%></font>';
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
function openwebui(){
|
||||
var url = window.location.host+":<%=luci.sys.exec("uci -q get filebrowser.config.port"):gsub("^%s*(.-)%s*$", "%1")%>";
|
||||
window.open('http://'+url,'target','');
|
||||
};
|
||||
//]]>
|
||||
</script>
|
||||
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
|
||||
<fieldset class="cbi-section">
|
||||
<p id="filebrowser_status">
|
||||
<em><%:Collecting data...%></em>
|
||||
</p>
|
||||
</fieldset>
|
||||
Loading…
Reference in New Issue
Block a user