specify global origin of data in window builder

This commit is contained in:
buzz-lightsnack-2007 2024-04-30 23:27:11 +08:00
parent 1d96acc37a
commit a10a14893a
2 changed files with 20 additions and 19 deletions

View file

@ -4,6 +4,7 @@ Window and window content management */
import texts from "../../mapping/read.js";
import net from "/scripts/utils/net.js";
import Window from "../window.js";
import {global} from "/scripts/secretariat.js";
export default class windowman {
static new(URL, height, width) {
@ -46,7 +47,7 @@ export default class windowman {
logging.error(err.name, err.message, err.stack, true, [source]);
// Stop loading the page when an error has occured; it's not going to work!
if ((await secretariat.read(`debug`, -1) != null) ? await secretariat.read(`debug`, -1) : true) {
if ((await secretariat.global.read(`debug`, -1) != null) ? await secretariat.global.read(`debug`, -1) : true) {
window.close();
};
};
@ -226,12 +227,12 @@ export default class windowman {
(document.querySelectorAll(`.sidenav`)).forEach(function (sidebar_element) {
if (sidebar_element.getAttribute(`name`)) {
document.querySelector(`[works-sidebar="${sidebar_element.getAttribute(`name`)}"]`)
.addEventListener(`click`, function () {
.addEventListener(`click`, () => {
M.Sidenav.getInstance(sidebar_element).open();
});
} else if (document.querySelector(`[data-action="ui,open,navbar"]`)) {
document.querySelector(`[data-action="ui,open,navbar"]`).forEach(function (button_element) {
button_element.addEventListener(`click`, function() {
button_element.addEventListener(`click`, () => {
M.Sidenav.getInstance(sidebar).open();
});
});
@ -270,7 +271,7 @@ export default class windowman {
let data = {};
data[`source`] = input_element.getAttribute(`data-store`);
// data[`origin`] = (input_element.hasAttribute(`data-store-location`)) ? parseInt(input_element.getAttribute(`data-store-location`)) : -1
data[`value`] = secretariat.read(data[`source`]);
data[`value`] = secretariat.global.read(data[`source`]);
data[`value`].then(async function(value) {
switch (input_element.getAttribute(`type`).toLowerCase()) {
@ -315,7 +316,7 @@ export default class windowman {
UI_item[`source`] = this.getAttribute(`data-store`);
UI_item[`value`] = this.checked;
UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1;
secretariat.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
secretariat.global.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
};
break;
default:
@ -337,7 +338,7 @@ export default class windowman {
: parseInt(this.value)
: this.value;
UI_item[`store`] = (this.hasAttribute(`data-store-location`)) ? parseInt(this.getAttribute(`data-store-location`)) : -1;
secretariat.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
secretariat.global.write(UI_item[`source`], UI_item[`value`], UI_item[`store`]);
};
break;
}
@ -351,7 +352,7 @@ export default class windowman {
*/
async function updates() {
// Get the storage data.
let storage_data = await secretariat.read();
let storage_data = await secretariat.global.read();
async function enable() {
let input_elements = document.querySelectorAll("[data-enable]");
@ -360,10 +361,10 @@ export default class windowman {
input_elements.forEach(async (input_element) => {
if (input_element.getAttribute("data-enable")) {
// Enable the element.
input_element.disabled = ((await secretariat.read(input_element.getAttribute("data-enable"))) != null
? (typeof (await secretariat.read(input_element.getAttribute("data-enable")))).includes(`obj`)
? (Object.keys(await secretariat.read(input_element.getAttribute("data-enable")))).length <= 0
: !(!!(await secretariat.read(input_element.getAttribute("data-enable"))))
input_element.disabled = ((await secretariat.global.read(input_element.getAttribute("data-enable"))) != null
? (typeof (await secretariat.global.read(input_element.getAttribute("data-enable")))).includes(`obj`)
? (Object.keys(await secretariat.global.read(input_element.getAttribute("data-enable")))).length <= 0
: !(!!(await secretariat.global.read(input_element.getAttribute("data-enable"))))
: true);
(input_element.disabled) ? input_element.classList.add(`disabled`) : input_element.classList.remove(`disabled`);