This commit is contained in:
naielv
2025-07-30 22:38:25 +02:00
parent 970b1dddf7
commit 03c132a6bd
8 changed files with 348 additions and 266 deletions

View File

@@ -34,6 +34,10 @@ if (urlParams.get("login") != null) {
//location.search = "";
}
function open_page(params) {
if (SUB_LOGGED_IN != true) {
PAGES["login"].index();
return;
}
if (params == "") {
params = "index";
}

View File

@@ -215,7 +215,9 @@ function addCategory_Personas(
options,
defaultval,
change_cb = () => {},
label = "Persona"
label = "Persona",
open_default = false,
default_empty_text = "- Lista Vacia -"
) {
var details_0 = document.createElement("details"); // children: img_0, summary_0
//details_0.open = true;
@@ -233,6 +235,9 @@ function addCategory_Personas(
span_0.append(p.Nombre || "", " ", img_0);
summary_0.append(label, span_0);
details_0.append(summary_0, document.createElement("br"));
if (open_default == true) {
details_0.open = true;
}
details_0.style.textAlign = "center";
details_0.style.margin = "5px";
details_0.style.padding = "5px";
@@ -302,6 +307,11 @@ function addCategory_Personas(
//btn.style.fontSize="17.5px"
details_0.append(btn);
});
if (Object.entries(options).length == 0) {
var btn = document.createElement("b");
btn.append(default_empty_text);
details_0.append(btn);
}
}
const SC_actions_icons = {
Tamaño: "static/ico/sizes.png",
@@ -493,7 +503,6 @@ gun
.get("personas")
.map()
.on((data, key, _msg, _ev) => {
if (data != null) {
function add_row(data, key) {
if (data != null) {
data["_key"] = key;
@@ -509,7 +518,6 @@ gun
} else {
add_row(data, key);
}
}
});
function SC_parse(json) {
@@ -656,7 +664,6 @@ function TS_IndexElement(
}
return 0;
}
var tablebody_EL = document.getElementById(tablebody);
tablebody_EL.innerHTML = "";
Object.values(rows)
.sort(sorter)
@@ -675,34 +682,39 @@ function TS_IndexElement(
config.forEach((key) => {
switch (key.type) {
case "raw":
const tdRaw = document.createElement('td');
const rawContent = (data[key.key] || key.default || "").replace(/\n/g, '<br>');
const tdRaw = document.createElement("td");
const rawContent = (data[key.key] || key.default || "").replace(
/\n/g,
"<br>"
);
tdRaw.innerHTML = rawContent;
new_tr.appendChild(tdRaw);
break;
case "comanda":
const tdComanda = document.createElement('td');
const tdComanda = document.createElement("td");
const parsedComanda = JSON.parse(data.Comanda);
const precio = SC_priceCalc(parsedComanda)[0];
// Create a temporary div to parse the HTML from setLayeredImages
const tempDiv = document.createElement('div');
const tempDiv = document.createElement("div");
tempDiv.innerHTML = setLayeredImages(parsedComanda, data._key);
tdComanda.appendChild(tempDiv.firstChild);
const pre = document.createElement('pre');
pre.style.fontSize = '15px';
pre.style.display = 'inline-block';
const pre = document.createElement("pre");
pre.style.fontSize = "15px";
pre.style.display = "inline-block";
const spanPrecio = document.createElement('span');
spanPrecio.style.fontSize = '20px';
spanPrecio.innerHTML = SC_Personas[data.Persona].Puntos >= 10 ?
`Total: Gratis!(${precio}c)` :
`Total: ${precio}c`;
const spanPrecio = document.createElement("span");
spanPrecio.style.fontSize = "20px";
spanPrecio.innerHTML =
SC_Personas[data.Persona].Puntos >= 10
? `Total: Gratis!(${precio}c)`
: `Total: ${precio}c`;
pre.appendChild(spanPrecio);
pre.appendChild(document.createTextNode('\n'));
pre.innerHTML += SC_parse_short(parsedComanda) + "<hr>" + data.Notas;
pre.appendChild(document.createTextNode("\n"));
pre.innerHTML +=
SC_parse_short(parsedComanda) + "<hr>" + data.Notas;
tdComanda.appendChild(pre);
new_tr.appendChild(tdComanda);
@@ -712,19 +724,19 @@ function TS_IndexElement(
if (urlParams.get("sc_nobtn") == "yes") {
sc_nobtn = "pointer-events: none; opacity: 0.5";
}
const td = document.createElement('td');
td.style.fontSize = '17px';
const td = document.createElement("td");
td.style.fontSize = "17px";
if (sc_nobtn) {
td.style.pointerEvents = 'none';
td.style.opacity = '0.5';
td.style.pointerEvents = "none";
td.style.opacity = "0.5";
}
// Create buttons
const createButton = (text, state) => {
const button = document.createElement('button');
const button = document.createElement("button");
button.textContent = text;
if (data.Estado === state) {
button.className = 'rojo';
button.className = "rojo";
}
button.onclick = (event) => {
event.preventDefault();
@@ -741,20 +753,24 @@ function TS_IndexElement(
// Create all buttons
const buttons = [
createButton('Pedido', 'Pedido'),
createButton('En preparación', 'En preparación'),
createButton('Listo', 'Listo'),
createButton('Entregado', 'Entregado'),
createButton('Deuda', 'Deuda')
createButton("Pedido", "Pedido"),
createButton("En preparación", "En preparación"),
createButton("Listo", "Listo"),
createButton("Entregado", "Entregado"),
createButton("Deuda", "Deuda"),
];
// Create paid button separately due to different behavior
const paidButton = document.createElement('button');
paidButton.textContent = 'Pagado';
const paidButton = document.createElement("button");
paidButton.textContent = "Pagado";
paidButton.onclick = (event) => {
event.preventDefault();
event.stopPropagation();
if (!confirm("¿Quieres marcar como pagado? - Se borrara la comanda y se actualizarán los puntos.")) {
if (
!confirm(
"¿Quieres marcar como pagado? - Se borrara la comanda y se actualizarán los puntos."
)
) {
return false;
}
data.Estado = "Pagado";
@@ -762,22 +778,33 @@ function TS_IndexElement(
toastr.success("Guardado!");
if (SC_Personas[data.Persona].Puntos >= 10) {
SC_Personas[data.Persona].Puntos -= 10;
toastr.success("¡Comada gratis para " + SC_Personas[data.Persona].Nombre + "!");
toastr.success("¡Comada gratis para " + SC_Personas[data.Persona].Nombre + "!");
toastr.success(
"¡Comada gratis para " +
SC_Personas[data.Persona].Nombre +
"!"
);
toastr.success(
"¡Comada gratis para " +
SC_Personas[data.Persona].Nombre +
"!"
);
} else {
SC_Personas[data.Persona].Puntos += 1;
toastr.success("¡Comada DE PAGO!");
}
SEA.encrypt(SC_Personas[data.Persona], SECRET, (encrypted) => {
betterGunPut(gun.get(TABLE).get("personas").get(data.Persona), encrypted);
betterGunPut(
gun.get(TABLE).get("personas").get(data.Persona),
encrypted
);
});
return false;
};
// Add all buttons to td with line breaks between
buttons.forEach(button => {
buttons.forEach((button) => {
td.appendChild(button);
td.appendChild(document.createElement('br'));
td.appendChild(document.createElement("br"));
});
td.appendChild(paidButton);
new_tr.appendChild(td);
@@ -786,41 +813,45 @@ function TS_IndexElement(
break;
case "persona":
const persona = SC_Personas[data[key.key]];
const regco = stringToColour((persona.Region || "?").toLowerCase());
const regco = stringToColour(
(persona.Region || "?").toLowerCase()
);
const tdPersona = document.createElement('td');
tdPersona.style.textAlign = 'center';
tdPersona.style.fontSize = '20px';
const tdPersona = document.createElement("td");
tdPersona.style.textAlign = "center";
tdPersona.style.fontSize = "20px";
tdPersona.style.backgroundColor = regco;
tdPersona.style.color = colorIsDarkAdvanced(regco);
const regionSpan = document.createElement('span');
regionSpan.style.fontSize = '40px';
regionSpan.style.textTransform = 'capitalize';
const regionSpan = document.createElement("span");
regionSpan.style.fontSize = "40px";
regionSpan.style.textTransform = "capitalize";
regionSpan.textContent = (persona.Region || "?").toLowerCase();
tdPersona.appendChild(regionSpan);
tdPersona.appendChild(document.createElement('br'));
tdPersona.appendChild(document.createElement("br"));
const infoSpan = document.createElement('span');
infoSpan.style.backgroundColor = 'white';
infoSpan.style.border = '2px solid black';
infoSpan.style.borderRadius = '5px';
infoSpan.style.display = 'inline-block';
infoSpan.style.padding = '5px';
infoSpan.style.color = 'black';
const infoSpan = document.createElement("span");
infoSpan.style.backgroundColor = "white";
infoSpan.style.border = "2px solid black";
infoSpan.style.borderRadius = "5px";
infoSpan.style.display = "inline-block";
infoSpan.style.padding = "5px";
infoSpan.style.color = "black";
const img = document.createElement('img');
const img = document.createElement("img");
img.src = persona.Foto || "static/ico/user_generic.png";
img.height = 70;
infoSpan.appendChild(img);
infoSpan.appendChild(document.createElement('br'));
infoSpan.appendChild(document.createTextNode(persona.Nombre || ""));
infoSpan.appendChild(document.createElement("br"));
infoSpan.appendChild(
document.createTextNode(persona.Nombre || "")
);
infoSpan.appendChild(document.createElement('br'));
const pointsSpan = document.createElement('span');
pointsSpan.style.fontSize = '17px';
infoSpan.appendChild(document.createElement("br"));
const pointsSpan = document.createElement("span");
pointsSpan.style.fontSize = "17px";
pointsSpan.textContent = (persona.Puntos || "0") + " puntos.";
infoSpan.appendChild(pointsSpan);
@@ -839,7 +870,6 @@ function TS_IndexElement(
}
ref.map().on((data, key, _msg, _ev) => {
EVENTLISTENER = _ev;
if (data != null) {
function add_row(data, key) {
if (data != null) {
data["_key"] = key;
@@ -856,13 +886,15 @@ function TS_IndexElement(
} else {
add_row(data, key);
}
}
});
}
const PAGES = {};
document.addEventListener("DOMContentLoaded", () => {
Object.keys(PAGES).forEach((key) => {
if (PAGES[key].Esconder == true) {
return;
}
var a = document.createElement("a");
a.className = "button " + PAGES[key].navcss;
a.href = "#" + key;

View File

@@ -20,3 +20,6 @@ const RELAYS = [
"https://gun.defucc.me/gun",
];
var SECRET = "";
var SUB_LOGGED_IN = false;
var SUB_LOGGED_IN_DETAILS = false;
var SUB_LOGGED_IN_ID = false;

View File

@@ -141,6 +141,7 @@
<script src="gun_init.js"></script>
<script src="app_logic.js"></script>
<script src="app_modules.js"></script>
<script src="page__login.js"></script>
<script src="page__index.js"></script>
<script src="page__importar.js"></script>
<script src="page__exportar.js"></script>

50
src/page__login.js Normal file
View File

@@ -0,0 +1,50 @@
PAGES.login = {
Esconder: true,
Title: "Login",
index: function (mid) {
var field_persona = safeuuid();
var btn_guardar = safeuuid();
var btn_reload = safeuuid();
var div_actions = safeuuid();
container.innerHTML = `
<h1>Iniciar sesión</h1>
<fieldset>
<legend>Valores</legend>
<input type="hidden" id="${field_persona}">
<div id="${div_actions}"></div>
<button class="btn5" id="${btn_guardar}">Acceder</button>
<button class="btn1" id="${btn_reload}">Recargar lista</button>
</fieldset>
<a style="color: rgb(240,240,240)">Acceso sin cuenta</a>
`;
var divact = document.getElementById(div_actions);
addCategory_Personas(
divact,
SC_Personas,
"",
(value) => {
document.getElementById(field_persona).value = value;
},
"¿Quién eres?",
true,
"- Pulsa recargar -"
);
document.getElementById("appendApps").style.display = "none"
document.getElementById(btn_guardar).onclick = () => {
if (document.getElementById(field_persona).value == "") {
alert("Tienes que elegir tu cuenta!");
return;
}
SUB_LOGGED_IN_ID = document.getElementById(field_persona).value
SUB_LOGGED_IN_DETAILS = SC_Personas[SUB_LOGGED_IN_ID]
SUB_LOGGED_IN = true
setUrlHash("index")
document.getElementById("appendApps").style.display = "unset"
};
document.getElementById(btn_reload).onclick = () => {
setUrlHash("login," + safeuuid(""))
};
},
}

View File

@@ -168,7 +168,6 @@ PAGES.materiales = {
.map()
.on((data, key, _msg, _ev) => {
EVENTLISTENER = _ev;
if (data != null) {
function add_row(data, key) {
if (data != null) {
data["_key"] = key;
@@ -185,10 +184,9 @@ PAGES.materiales = {
} else {
add_row(data, key);
}
}
});
document.getElementById(btn_new).onclick = () => {
setUrlHash("materiales," + safeuuid(""));
};
},
}
};

View File

@@ -198,7 +198,6 @@ PAGES.personas = {
.map()
.on((data, key, _msg, _ev) => {
EVENTLISTENER = _ev;
if (data != null) {
function add_row(data, key) {
if (data != null) {
data["_key"] = key;
@@ -215,7 +214,6 @@ PAGES.personas = {
} else {
add_row(data, key);
}
}
});
document.getElementById(btn_new).onclick = () => {
setUrlHash("personas," + safeuuid(""));

View File

@@ -58,7 +58,6 @@ PAGES.resumen_diario = {
.map()
.on((data, key, _msg, _ev) => {
EVENTLISTENER2 = _ev;
if (data != null) {
function add_row(data, key) {
if (data != null) {
data["_key"] = key;
@@ -75,7 +74,6 @@ PAGES.resumen_diario = {
} else {
add_row(data, key);
}
}
});
function render_personasHigh() {
function sorter(a, b) {
@@ -123,7 +121,6 @@ PAGES.resumen_diario = {
.map()
.on((data, key, _msg, _ev) => {
EVENTLISTENER = _ev;
if (data != null) {
function add_row(data, key) {
if (data != null) {
data["_key"] = key;
@@ -140,7 +137,6 @@ PAGES.resumen_diario = {
} else {
add_row(data, key);
}
}
});
},
};