Skip to content

Commit

Permalink
Fix of table elements selector: #25
Browse files Browse the repository at this point in the history
In OpenWrt 21.02 the table elements (.tr, .th, .td) are changed
from div to "real" table related tags.
  • Loading branch information
wolandmaster committed Jun 26, 2021
1 parent ac66067 commit 66fb718
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ packages-file: ipk
mkdir -p ipk
cp control/control ipk/Packages
echo "Filename: $(IPK)" >> ipk/Packages
du -b ipk/$(IPK) | awk '{print "Size:", $$1}' >> ipk/Packages
wc -c ipk/$(IPK) | awk '{print "Size:", $$1}' >> ipk/Packages
sha256sum ipk/$(IPK) | awk '{print "SHA256sum:", $$1}' >> ipk/Packages
usign -S -m ipk/Packages -s key/sign_key
gzip ipk/Packages
Expand Down
2 changes: 1 addition & 1 deletion control/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: luci-app-rtorrent
Version: 0.2.0
Version: 0.2.1
Depends: libc, rtorrent-rpc, luaexpat, luasocket, luasec, luci-compat, luci-lib-httpprotoutils
Source: https://github.com/wolandmaster/luci-app-rtorrent
Section: luci
Expand Down
3 changes: 2 additions & 1 deletion src/usr/lib/lua/luci/model/cbi/rtorrent/common.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Copyright 2014-2021 Sandor Balazsi <[email protected]>
-- Licensed to the public under the GNU General Public License.

local socket = require "socket"
local url = require "socket.url"
local http = require "socket.http"
local https = require "ssl.https"
Expand All @@ -13,7 +14,7 @@ local rtorrent = require "rtorrent"
local array = require "luci.model.cbi.rtorrent.array"
require "luci.model.cbi.rtorrent.string"

local string, table, os, math, socket, unpack = string, table, os, math, socket, unpack
local string, table, os, math, unpack = string, table, os, math, unpack
local type, ipairs, tostring, tonumber = type, ipairs, tostring, tonumber
local getmetatable = getmetatable

Expand Down
26 changes: 13 additions & 13 deletions src/usr/lib/lua/luci/view/rtorrent/tblsection.htm
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,26 @@
document.addEventListener("luci-loaded", function() {
<% for i, node in ipairs(self.children) do
if node.classes ~= nil and next(node.classes) ~= nil then %>
eachElement("#<%=self.name%> div.th:nth-child(<%=i%>), "
+ "#<%=self.name%> div:not(.placeholder) > div.td:nth-child(<%=i%>)",
eachElement("#<%=self.name%> .th:nth-child(<%=i%>), "
+ "#<%=self.name%> :not(.placeholder) > .td:nth-child(<%=i%>)",
cell => cell.classList.add("<%=table.concat(node.classes, '", "')%>"));
<% end
end %>
<% if #self:cfgsections() > 1
and self.map:get(self:cfgsections()[#self:cfgsections()], ".total_row") then %>
eachElement("div.tr:last-child > div.td", cell => cell.classList.add("bold"));
eachElement("div.tr:not(:last-child) input[type=checkbox]", checkbox => {
eachElement(".tr:last-child > .td", cell => cell.classList.add("bold"));
eachElement(".tr:not(:last-child) input[type=checkbox]", checkbox => {
checkbox.addEventListener("change", async function() {
const invertSelection = (await selectElement(
"div.tr:last-child input[type=checkbox]"))[0];
".tr:last-child input[type=checkbox]"))[0];
updateInvertSelection(invertSelection);
});
});
eachElement("div.tr:last-child input[type=checkbox]", async invertSelection => {
eachElement(".tr:last-child input[type=checkbox]", async invertSelection => {
updateInvertSelection(invertSelection);
invertSelection.addEventListener("change", async function() {
let count = 0, selected = 0;
await eachElement("div.tr:not(:last-child) input[type=checkbox]", checkbox => {
await eachElement(".tr:not(:last-child) input[type=checkbox]", checkbox => {
checkbox.checked = !checkbox.checked;
count++; selected += checkbox.checked ? 1 : 0;
});
Expand All @@ -59,24 +59,24 @@
document.forms[0].addEventListener("reset", function() {
setTimeout(async function() {
const invertSelection = (await selectElement(
"div.tr:last-child input[type=checkbox]"))[0];
".tr:last-child input[type=checkbox]"))[0];
updateInvertSelection(invertSelection);
}, 1);
});
eachElement("div.tr:not(:last-child) select", select => {
eachElement(".tr:not(:last-child) select", select => {
select.addEventListener("change", async function() {
const batchSelect = (await selectElement("div.tr:last-child select"))[0];
const batchSelect = (await selectElement(".tr:last-child select"))[0];
const selectedValues = new Set();
await eachElement("div.tr:not(:last-child) select:not(.hidden)", select => {
await eachElement(".tr:not(:last-child) select:not(.hidden)", select => {
selectedValues.add(select.value);
});
if (selectedValues.size > 1) { batchSelect.value = "mixed"; }
else { batchSelect.value = selectedValues.values().next().value; }
});
});
eachElement("div.tr:last-child select", batchSelect => {
eachElement(".tr:last-child select", batchSelect => {
batchSelect.addEventListener("change", async function() {
await eachElement("div.tr:not(:last-child) select:not(.hidden)", select => {
await eachElement(".tr:not(:last-child) select:not(.hidden)", select => {
select.value = batchSelect.value;
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/usr/lib/lua/luci/view/rtorrent/tblsection_main.htm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
action.addEventListener("click", async function(event) {
if (!event.target.matches("span.open") && !event.target.matches("li.focus")) {
let selected = 0;
await eachElement("div.tr input[type=checkbox]",
await eachElement(".tr input[type=checkbox]",
checkbox => selected += checkbox.checked ? 1 : 0);
if (selected == 0) {
alert("No torrent selected!\n"
Expand Down
2 changes: 1 addition & 1 deletion src/www/luci-static/resources/rtorrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function eachElement(selector, callback, scope) {

async function updateInvertSelection(invertSelection) {
let count = 0, selected = 0;
await eachElement("div.tr:not(:last-child) input[type=checkbox]", checkbox => {
await eachElement(".tr:not(:last-child) input[type=checkbox]", checkbox => {
count++; selected += checkbox.checked ? 1 : 0;
});
invertSelection.checked = (selected == count);
Expand Down

0 comments on commit 66fb718

Please sign in to comment.