mirror of
https://github.com/Ximi1970/systray-x.git
synced 2025-11-05 04:45:44 +01:00
Add save / restore for accountsTree
This commit is contained in:
@@ -72,6 +72,7 @@ SysTrayX.Accounts = {
|
|||||||
typeInput.setAttribute("type", "checkbox");
|
typeInput.setAttribute("type", "checkbox");
|
||||||
typeInput.setAttribute("name", accounts[prop][i].name);
|
typeInput.setAttribute("name", accounts[prop][i].name);
|
||||||
typeInput.setAttribute("value", accounts[prop][i].id);
|
typeInput.setAttribute("value", accounts[prop][i].id);
|
||||||
|
typeInput.setAttribute("checked", "true");
|
||||||
typeLi.appendChild(typeInput);
|
typeLi.appendChild(typeInput);
|
||||||
let typeText = document.createTextNode(" " + accounts[prop][i].name);
|
let typeText = document.createTextNode(" " + accounts[prop][i].name);
|
||||||
typeLi.appendChild(typeText);
|
typeLi.appendChild(typeText);
|
||||||
@@ -81,6 +82,31 @@ SysTrayX.Accounts = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
treeBase.appendChild(typeLi);
|
treeBase.appendChild(typeLi);
|
||||||
|
|
||||||
|
// Restore saved selection
|
||||||
|
function setAccounts(result) {
|
||||||
|
console.debug("Restore account selection");
|
||||||
|
|
||||||
|
let treeBase = document.getElementById("accountsTree");
|
||||||
|
let accounts = result.accounts || [];
|
||||||
|
for (let i = 0; i < accounts.length; ++i) {
|
||||||
|
let checkbox = treeBase.querySelector(
|
||||||
|
`input[value=${accounts[i].id}]`
|
||||||
|
);
|
||||||
|
if (checkbox) {
|
||||||
|
checkbox.checked = accounts[i].checked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.debug("Restore account selection done");
|
||||||
|
}
|
||||||
|
|
||||||
|
function onError(error) {
|
||||||
|
console.log(`GetAccounts Error: ${error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let getAccounts = browser.storage.sync.get("accounts");
|
||||||
|
getAccounts.then(setAccounts, onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -11,6 +11,30 @@ function saveOptions(e) {
|
|||||||
optionsCheck2: document.querySelector('input[name="check2"]').checked,
|
optionsCheck2: document.querySelector('input[name="check2"]').checked,
|
||||||
optionsCheck3: document.querySelector('input[name="check3"]').checked
|
optionsCheck3: document.querySelector('input[name="check3"]').checked
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get accounts
|
||||||
|
*/
|
||||||
|
|
||||||
|
console.debug("Store accounts");
|
||||||
|
|
||||||
|
let treeBase = document.getElementById("accountsTree");
|
||||||
|
let inputs = treeBase.querySelectorAll("input");
|
||||||
|
let accounts = [];
|
||||||
|
for (let i = 0; i < inputs.length; ++i) {
|
||||||
|
accounts.push({
|
||||||
|
id: inputs[i].value,
|
||||||
|
name: inputs[i].name,
|
||||||
|
checked: inputs[i].checked
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store accounts
|
||||||
|
browser.storage.sync.set({
|
||||||
|
accounts: accounts
|
||||||
|
});
|
||||||
|
|
||||||
|
console.debug("Store accounts done");
|
||||||
}
|
}
|
||||||
|
|
||||||
function restoreOptions() {
|
function restoreOptions() {
|
||||||
|
|||||||
Reference in New Issue
Block a user