Refactor logic to remove duplicate code

This commit is contained in:
Thomas Piccirello 2025-08-17 14:38:21 -07:00
commit f65b261962
No known key found for this signature in database

View file

@ -2860,26 +2860,23 @@ window.qBittorrent.DynamicTable ??= (() => {
*/ */
toggleGlobalCheckbox() { toggleGlobalCheckbox() {
const checkbox = document.getElementById("rootMultiRename_cb"); const checkbox = document.getElementById("rootMultiRename_cb");
const checkboxes = document.querySelectorAll("input.RenamingCB"); const isChecked = checkbox.checked || checkbox.indeterminate;
for (let i = 0; i < checkboxes.length; ++i) { for (const cb of document.querySelectorAll("input.RenamingCB")) {
if (checkbox.checked || checkbox.indeterminate) { cb.indeterminate = false;
const cb = checkboxes[i]; if (isChecked) {
cb.checked = true; cb.checked = true;
cb.indeterminate = false;
cb.state = "checked"; cb.state = "checked";
} }
else { else {
const cb = checkboxes[i];
cb.checked = false; cb.checked = false;
cb.indeterminate = false;
cb.state = "unchecked"; cb.state = "unchecked";
} }
} }
const nodes = this.fileTree.toArray(); const nodes = this.fileTree.toArray();
for (const node of nodes) for (const node of nodes)
node.checked = (checkbox.checked || checkbox.indeterminate) ? 0 : 1; node.checked = isChecked ? 0 : 1;
this.updateGlobalCheckbox(); this.updateGlobalCheckbox();
} }