update app_logic.js

This commit is contained in:
naielv
2025-08-11 15:43:05 +02:00
parent e6688bf74c
commit 0b748e45f8

View File

@@ -4,14 +4,15 @@ function tableScroll(query) {
//var secretTokenEl = document.getElementById("secretToken"); //var secretTokenEl = document.getElementById("secretToken");
var groupIdEl = document.getElementById("groupId"); var groupIdEl = document.getElementById("groupId");
var container = document.getElementById("container"); var container = document.getElementById("container");
function LinkAccount(LinkAccount_group, LinkAccount_secret, refresh = false) { function LinkAccount(LinkAccount_group, LinkAccount_secret, refresh = false) {
GROUPID = LinkAccount_group.toUpperCase(); GROUPID = LinkAccount_group.toUpperCase();
SECRET = LinkAccount_secret.toUpperCase(); SECRET = LinkAccount_secret.toUpperCase();
localStorage.setItem("TELESEC_AUTO", "YES"); localStorage.setItem("TELESEC_AUTO", "YES");
localStorage.setItem("TELESEC_groupid", GROUPID); localStorage.setItem("TELESEC_groupid", GROUPID);
localStorage.setItem("TELESEC_secret", SECRET); localStorage.setItem("TELESEC_secret", SECRET);
TABLE = GROUPID + ":telesec.tech.eus"; TABLE = GROUPID + ":telesec.tech.eus";
//secretTokenEl.innerText = SECRET; //secretTokenEl.innerText = SECRET;
groupIdEl.innerText = GROUPID; groupIdEl.innerText = GROUPID;
@@ -33,26 +34,8 @@ if (urlParams.get("login") != null) {
); );
//location.search = ""; //location.search = "";
} }
function open_page(params) { function open_page(params) {
if (SUB_LOGGED_IN != true) {
PAGES["login"].index();
return;
}
if (params == "") {
params = "index";
}
var path = params.split(",");
var app = path[0];
if (path[1] == undefined) {
PAGES[app].index();
return;
}
PAGES[app].edit(path[1]);
}
function setUrlHash(hash) {
location.hash = "#" + hash;
}
window.onhashchange = () => {
try { try {
if (EVENTLISTENER != null) { if (EVENTLISTENER != null) {
try { try {
@@ -70,9 +53,31 @@ window.onhashchange = () => {
} catch (e) { } catch (e) {
console.debug("EVENTLISTENER onhashchange", e); console.debug("EVENTLISTENER onhashchange", e);
} }
if (SUB_LOGGED_IN != true) {
PAGES["login"].index();
return;
}
if (params == "") {
params = "index";
}
var path = params.split(",");
var app = path[0];
if (path[1] == undefined) {
PAGES[app].index();
return;
}
PAGES[app].edit(path[1]);
}
function setUrlHash(hash) {
location.hash = "#" + hash;
}
window.onhashchange = () => {
open_page(location.hash.replace("#", "")); open_page(location.hash.replace("#", ""));
}; };
function download(filename, text) { function download(filename, text) {
var element = document.createElement("a"); var element = document.createElement("a");
element.setAttribute( element.setAttribute(
@@ -80,14 +85,15 @@ function download(filename, text) {
"data:application/octet-stream;charset=utf-8," + encodeURIComponent(text) "data:application/octet-stream;charset=utf-8," + encodeURIComponent(text)
); );
element.setAttribute("download", filename); element.setAttribute("download", filename);
element.style.display = "none"; element.style.display = "none";
document.body.appendChild(element); document.body.appendChild(element);
element.click(); element.click();
document.body.removeChild(element); document.body.removeChild(element);
} }
function resizeInputImage( function resizeInputImage(
file, file,
callback, callback,
@@ -95,51 +101,54 @@ function resizeInputImage(
targetQuality = 0.75 targetQuality = 0.75
) { ) {
const reader = new FileReader(); const reader = new FileReader();
reader.onload = function (event) { reader.onload = function(event) {
const img = new Image(); const img = new Image();
img.onload = function () { img.onload = function() {
const aspectRatio = img.width / img.height; const aspectRatio = img.width / img.height;
const targetWidth = targetHeight * aspectRatio; const targetWidth = targetHeight * aspectRatio;
const canvas = document.createElement("canvas"); const canvas = document.createElement("canvas");
canvas.width = targetWidth; canvas.width = targetWidth;
canvas.height = targetHeight; canvas.height = targetHeight;
const ctx = canvas.getContext("2d"); const ctx = canvas.getContext("2d");
ctx.fillStyle = "#ffffff"; ctx.fillStyle = "#ffffff";
ctx.fillRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(img, 0, 0, targetWidth, targetHeight); ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
// Get resized image as Blob // Get resized image as Blob
const dataURL = canvas.toDataURL("image/jpeg", targetQuality); const dataURL = canvas.toDataURL("image/jpeg", targetQuality);
callback(dataURL); callback(dataURL);
}; };
img.src = event.target.result; img.src = event.target.result;
}; };
reader.readAsDataURL(file); reader.readAsDataURL(file);
} }
function CurrentISODate() { function CurrentISODate() {
return new Date().toISOString().split("T")[0].replace("T", " "); return new Date().toISOString().split("T")[0].replace("T", " ");
} }
function CurrentISOTime() { function CurrentISOTime() {
return new Date().toISOString(); return new Date().toISOString();
} }
function fixGunLocalStorage() { function fixGunLocalStorage() {
localStorage.removeItem("radata"); localStorage.removeItem("radata");
removeCache(); removeCache();
location.reload(); location.reload();
} }
function betterGunPut(ref, data) { function betterGunPut(ref, data) {
ref.put(data, (ack) => { ref.put(data, (ack) => {
if (ack.err) { if (ack.err) {
toastr.error( toastr.error(
ack.err + "<br>Pulsa aqui para reiniciar la app", ack.err + "<br>Pulsa aqui para reiniciar la app",
"Error al guardar", "Error al guardar", { onclick: () => fixGunLocalStorage() }
{ onclick: () => fixGunLocalStorage() }
); );
} else { } else {
console.debug("Guardado correctamente"); console.debug("Guardado correctamente");
@@ -161,4 +170,4 @@ setInterval(() => {
}, 5000); }, 5000);
gun.get(TABLE).on((data) => { gun.get(TABLE).on((data) => {
var e = true; var e = true;
}); });