73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import {JSONRPC} from "./jrpc.js";
|
|
|
|
const App = {
|
|
config: {},
|
|
networks: {},
|
|
RPC: JSONRPC
|
|
};
|
|
|
|
|
|
App.auth = async function () {
|
|
let authorized = await JSONRPC.__invoke("auth");
|
|
if (!authorized) {
|
|
do {
|
|
let pass = prompt("Password");
|
|
authorized = await JSONRPC.__invoke("auth", {
|
|
"password": pass
|
|
});
|
|
|
|
if (!authorized) {
|
|
alert("Wrong password");
|
|
}
|
|
} while (!authorized);
|
|
}
|
|
|
|
this.config = await JSONRPC.__invoke("getConfig");
|
|
this.networks = await JSONRPC.__invoke("getNetworks");
|
|
|
|
|
|
for (const key of this.config.plugins) {
|
|
$("body").append("<" + "script type='module' src='/plugins/" + key + "/plugin.js'><" + "/script>");
|
|
}
|
|
|
|
$("#loading").hide();
|
|
|
|
this.fillNetworks();
|
|
|
|
$("#panel").show();
|
|
}
|
|
|
|
App.fillNetworks = function () {
|
|
const that = this;
|
|
let proto = $("#net-table tr");
|
|
proto.detach();
|
|
|
|
for (const net in this.networks) {
|
|
let item = proto.clone();
|
|
item.find("input").prop('checked', this.config.networks.indexOf(net) !== -1).change(function () {
|
|
if ($(this).prop('checked')) {
|
|
that.config.networks.push(net);
|
|
} else {
|
|
that.config.networks = that.config.networks.filter(e => e !== net);
|
|
}
|
|
});
|
|
item.find("span").text(net);
|
|
$("#net-table").append(item);
|
|
}
|
|
}
|
|
|
|
App.render = async function () {
|
|
await this.auth();
|
|
$("#save").click(function () {
|
|
const self = $(this);
|
|
self.prop("disabled", true);
|
|
(async function () {
|
|
await JSONRPC.__invoke("setConfig", App.config);
|
|
alert("Config saved!");
|
|
self.prop("disabled", false);
|
|
})();
|
|
});
|
|
}
|
|
|
|
|
|
export {App}; |