luci-app-qbittorrent: improve button

This commit is contained in:
CN_SZTL 2020-03-08 16:11:16 +08:00
parent 7c31f81213
commit 740cf28db5
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
2 changed files with 7 additions and 12 deletions

View File

@ -1,13 +1,3 @@
local e=require"luci.model.uci".cursor()
local o=e:get_first("qbittorrent","qbittorrent","port") or 8080
local a=(luci.sys.call("pidof qbittorrent-nox > /dev/null")==0)
local t=""
if a then
t="<br/><br/><input type=\"button\" value=\" " .. translate("Open Web Interface") .. " \" onclick=\"window.open('http://'+window.location.hostname+':" .. o .. "')\"/>"
end
m = Map("qbittorrent", translate("qBittorrent"), translate("qBittorrent is a cross-platform free and open-source BitTorrent client.").."<br/>"..translate("Default login username: admin, password: adminadmin.")..t)
m:section(SimpleSection).template="qbittorrent/qbittorrent_status"

View File

@ -4,7 +4,7 @@ XHR.poll(3, '<%=url([[admin]], [[nas]], [[qBittorrent]], [[status]])%>', null,
var tb = document.getElementById('qBittorrent_status');
if (data && tb) {
if (data.running) {
var links = '<em><b><font color=green>qBittorrent <%:RUNNING%></font></b></em>';
var links = '<em><b><font color=green>qBittorrent <%:RUNNING%></font></b></em><input class="cbi-button mar-10" type="button" value="<%:Open Web Interface%>" onclick="openwebui();" />';
tb.innerHTML = links;
} else {
tb.innerHTML = '<em><b><font color=red>qBittorrent <%:NOT RUNNING%></font></b></em>';
@ -12,6 +12,11 @@ XHR.poll(3, '<%=url([[admin]], [[nas]], [[qBittorrent]], [[status]])%>', null,
}
}
);
function openwebui(){
var url = window.location.host+":<%=luci.sys.exec("uci -q get qbittorrent.config.port"):gsub("^%s*(.-)%s*$", "%1")%>";
window.open('http://'+url,'target','');
};
//]]>
</script>
<style>.mar-10 {margin-left: 50px; margin-right: 10px;}</style>
@ -19,4 +24,4 @@ XHR.poll(3, '<%=url([[admin]], [[nas]], [[qBittorrent]], [[status]])%>', null,
<p id="qBittorrent_status">
<em><%:Collecting data...%></em>
</p>
</fieldset>
</fieldset>