General fixes
This commit is contained in:
114
src/page/comedor.js
Normal file
114
src/page/comedor.js
Normal file
@@ -0,0 +1,114 @@
|
||||
PAGES.comedor = {
|
||||
navcss: "btn7",
|
||||
Title: "Menú comedor",
|
||||
edit: function (mid) {
|
||||
var nameh1 = safeuuid();
|
||||
var field_fecha = safeuuid();
|
||||
var field_platos = safeuuid();
|
||||
var btn_guardar = safeuuid();
|
||||
var btn_borrar = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Menú del Comedor <code id="${nameh1}"></code></h1>
|
||||
<fieldset style="float: left;">
|
||||
<legend>Valores</legend>
|
||||
<label>
|
||||
Fecha<br>
|
||||
<input type="date" id="${field_fecha}" value="${CurrentISODate()}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Platos<br>
|
||||
<textarea id="${field_platos}"></textarea><br><br>
|
||||
</label>
|
||||
<button class="btn5" id="${btn_guardar}">Guardar</button>
|
||||
<button class="rojo" id="${btn_borrar}">Borrar</button>
|
||||
</fieldset>
|
||||
`;
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("comedor")
|
||||
.get(mid)
|
||||
.once((data, key) => {
|
||||
function load_data(data, ENC = "") {
|
||||
document.getElementById(nameh1).innerText = key;
|
||||
document.getElementById(field_fecha).value = data["Fecha"];
|
||||
document.getElementById(field_platos).value =
|
||||
data["Platos"] || "";
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
load_data(data, "%E");
|
||||
});
|
||||
} else {
|
||||
load_data(data);
|
||||
}
|
||||
});
|
||||
document.getElementById(btn_guardar).onclick = () => {
|
||||
const newDate = document.getElementById(field_fecha).value;
|
||||
var data = {
|
||||
Fecha: newDate,
|
||||
Platos: document.getElementById(field_platos).value,
|
||||
};
|
||||
|
||||
// If the date has changed, we need to delete the old entry
|
||||
if (mid !== newDate && mid !== "") {
|
||||
betterGunPut(gun.get(TABLE).get("comedor").get(mid), null);
|
||||
}
|
||||
|
||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
||||
document.getElementById("actionStatus").style.display = "block";
|
||||
betterGunPut(gun.get(TABLE).get("comedor").get(newDate), encrypted);
|
||||
toastr.success("Guardado!");
|
||||
setTimeout(() => {
|
||||
document.getElementById("actionStatus").style.display = "none";
|
||||
setUrlHash("comedor");
|
||||
}, 1500);
|
||||
});
|
||||
};
|
||||
document.getElementById(btn_borrar).onclick = () => {
|
||||
if (confirm("¿Quieres borrar esta entrada?") == true) {
|
||||
betterGunPut(gun.get(TABLE).get("comedor").get(mid), null);
|
||||
toastr.error("Borrado!");
|
||||
setTimeout(() => {
|
||||
setUrlHash("comedor");
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
},
|
||||
index: function () {
|
||||
const tablebody = safeuuid();
|
||||
var btn_new = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Menú del comedor</h1>
|
||||
<button id="${btn_new}">Nueva entrada</button>
|
||||
<div id="cont">
|
||||
`;
|
||||
TS_IndexElement(
|
||||
"comedor",
|
||||
[
|
||||
{
|
||||
key: "Fecha",
|
||||
type: "raw",
|
||||
default: "",
|
||||
label: "Fecha",
|
||||
},
|
||||
{
|
||||
key: "Platos",
|
||||
type: "raw",
|
||||
default: "",
|
||||
label: "Platos",
|
||||
}
|
||||
],
|
||||
gun.get(TABLE).get("comedor"),
|
||||
document.querySelector("#cont"),
|
||||
(data, new_tr) => {
|
||||
// new_tr.style.backgroundColor = "#FFCCCB";
|
||||
if (data.Fecha == CurrentISODate()) {
|
||||
new_tr.style.backgroundColor = "lightgreen";
|
||||
}
|
||||
}
|
||||
);
|
||||
document.getElementById(btn_new).onclick = () => {
|
||||
setUrlHash("comedor," + safeuuid(""));
|
||||
};
|
||||
},
|
||||
};
|
||||
89
src/page/exportar.js
Normal file
89
src/page/exportar.js
Normal file
@@ -0,0 +1,89 @@
|
||||
PAGES.exportar = {
|
||||
navcss: "btn1",
|
||||
Title: "Exportar",
|
||||
index: function () {
|
||||
var select_type = safeuuid();
|
||||
var textarea_content = safeuuid();
|
||||
var button_export_local = safeuuid();
|
||||
var button_export_safe = safeuuid();
|
||||
var button_export_safe_cloud = safeuuid();
|
||||
var button_clear = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Exportar Datos</h1>
|
||||
<fieldset>
|
||||
<legend>Exportar datos</legend>
|
||||
<em>Al pulsar, Espera hasta que salga una notificacion verde.</em>
|
||||
<br>
|
||||
<br>
|
||||
<button id="${button_export_local}" type="button">Exportar sin cifrar</button>
|
||||
<button id="${button_export_safe}" type="button">Exportar con cifrado</button>
|
||||
<button id="${button_export_safe_cloud}" style="display: none;" type="button">Exportar a EuskadiTech - cifrado</button>
|
||||
<!--<br><br><em>Para descargar envia un correo a telesec@tech.eus con el asunto "TSBK %${GROUPID}".</em>-->
|
||||
</fieldset>
|
||||
`;
|
||||
document.getElementById(button_export_local).onclick = () => {
|
||||
var data_export = {};
|
||||
var output = {
|
||||
materiales: {},
|
||||
personas: {},
|
||||
};
|
||||
var download_data = (DATA) => {
|
||||
Object.keys(DATA).forEach((modul) => {
|
||||
Object.entries(DATA[modul] || {}).forEach((entry) => {
|
||||
var key = entry[0];
|
||||
var value = entry[1];
|
||||
if (value != null) {
|
||||
if (typeof value == "string") {
|
||||
SEA.decrypt(value, SECRET, (data) => {
|
||||
output[modul][key] = data;
|
||||
});
|
||||
} else {
|
||||
output[modul][key] = value;
|
||||
}
|
||||
}
|
||||
});
|
||||
toastr.success("Exportado todo, descargando!");
|
||||
console.error(output);
|
||||
download(
|
||||
`Export TeleSec ${GROUPID}.json.txt`,
|
||||
JSON.stringify(output)
|
||||
);
|
||||
//setUrlHash(sel);
|
||||
}, 2500);
|
||||
};
|
||||
gun.get(TABLE).load(download_data);
|
||||
};
|
||||
document.getElementById(button_export_safe).onclick = () => {
|
||||
var download_data = (DATA) => {
|
||||
toastr.success("Exportado todo, descargado!");
|
||||
console.error(DATA);
|
||||
download(
|
||||
`Export TeleSec Encriptado ${GROUPID}.json.txt`,
|
||||
JSON.stringify(DATA)
|
||||
);
|
||||
//setUrlHash(sel);
|
||||
};
|
||||
gun.get(TABLE).load(download_data);
|
||||
};
|
||||
document.getElementById(button_export_safe_cloud).onclick = () => {
|
||||
var download_data = (DATA) => {
|
||||
toastr.info("Exportado todo, subiendo!");
|
||||
console.error(DATA);
|
||||
fetch(
|
||||
"https://telesec-sync.tech.eus/upload_backup.php?table=" + GROUPID,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(DATA),
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
toastr.success("Subido correctamente!");
|
||||
})
|
||||
.catch(() => {
|
||||
toastr.error("Ha ocurrido un error en la subida.");
|
||||
});
|
||||
};
|
||||
gun.get(TABLE).load(download_data);
|
||||
};
|
||||
},
|
||||
};
|
||||
54
src/page/importar.js
Normal file
54
src/page/importar.js
Normal file
@@ -0,0 +1,54 @@
|
||||
PAGES.importar = {
|
||||
navcss: "btn1",
|
||||
Title: "Importar",
|
||||
index: function () {
|
||||
var select_type = safeuuid();
|
||||
var textarea_content = safeuuid();
|
||||
var button_import = safeuuid();
|
||||
var button_clear = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Importar Datos</h1>
|
||||
<fieldset>
|
||||
<legend>Importar datos</legend>
|
||||
<em>Espera hasta que se vacien todas las notificaciones.</em>
|
||||
<select id="${select_type}">
|
||||
<option value="" disabled selected>Tipo de archivo...</option>
|
||||
<option value="comedor">Galileo - db.comedor.axd</option>
|
||||
<option value="recetas">Galileo - db.recetas.axd</option>
|
||||
<option value="materiales">Galileo - db.materiales.axd</option>
|
||||
<option value="personas">Galileo - db.personas.axd</option>
|
||||
<option value="comandas">Galileo - db.cafe.comandas.axd</option>
|
||||
<option value="%telesec">TeleSec Exportado (encriptado o no)</option>
|
||||
</select>
|
||||
<textarea id="${textarea_content}" style="height: 100px;" placeholder="Introduce el contenido del archivo"></textarea>
|
||||
<button id="${button_import}" type="button">Importar</button>
|
||||
<button id="${button_clear}" type="button">Vaciar</button>
|
||||
</fieldset>
|
||||
`;
|
||||
document.getElementById(button_import).onclick = () => {
|
||||
toastr.info("Importando datos...");
|
||||
var val = document.getElementById(textarea_content).value;
|
||||
var sel = document.getElementById(select_type).value;
|
||||
if (sel == "%telesec") {
|
||||
gun.get(TABLE).put(JSON.parse(val), (ack) => {
|
||||
toastr.info("Importado " + entry[0] + ".");
|
||||
});
|
||||
} else {
|
||||
Object.entries(JSON.parse(val)["data"]).forEach((entry) => {
|
||||
var enc = SEA.encrypt(entry[1], SECRET, (encrypted) => {
|
||||
betterGunPut(gun.get(TABLE).get(sel).get(entry[0]), encrypted);
|
||||
});
|
||||
});
|
||||
}
|
||||
setTimeout(() => {
|
||||
toastr.info("Importado todo!");
|
||||
|
||||
if (sel == "%telesec") {
|
||||
setUrlHash("inicio");
|
||||
} else {
|
||||
setUrlHash(sel);
|
||||
}
|
||||
}, 5000);
|
||||
};
|
||||
},
|
||||
};
|
||||
11
src/page/index.js
Normal file
11
src/page/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
PAGES.index = {
|
||||
//navcss: "btn1",
|
||||
Title: "Inicio",
|
||||
index: function () {
|
||||
container.innerHTML = `
|
||||
<h1>Inicio</h1>
|
||||
<em>Utiliza el menú superior para abrir un modulo</em>
|
||||
<br><br>
|
||||
`;
|
||||
},
|
||||
};
|
||||
50
src/page/login.js
Normal file
50
src/page/login.js
Normal 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(""))
|
||||
};
|
||||
|
||||
},
|
||||
}
|
||||
192
src/page/materiales.js
Normal file
192
src/page/materiales.js
Normal file
@@ -0,0 +1,192 @@
|
||||
PAGES.materiales = {
|
||||
navcss: "btn2",
|
||||
Title: "Materiales",
|
||||
edit: function (mid) {
|
||||
var nameh1 = safeuuid();
|
||||
var field_nombre = safeuuid();
|
||||
var field_cantidad = safeuuid();
|
||||
var field_unidad = safeuuid();
|
||||
var field_cantidad_min = safeuuid();
|
||||
var field_abierto = safeuuid();
|
||||
var field_ubicacion = safeuuid();
|
||||
var field_referencia = safeuuid();
|
||||
var field_notas = safeuuid();
|
||||
var btn_guardar = safeuuid();
|
||||
var btn_borrar = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Material <code id="${nameh1}"></code></h1>
|
||||
<fieldset>
|
||||
<label>
|
||||
Referencia<br>
|
||||
<input type="text" id="${field_referencia}" value="?"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Nombre<br>
|
||||
<input type="text" id="${field_nombre}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Unidad<br>
|
||||
<input type="text" id="${field_unidad}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Cantidad Actual<br>
|
||||
<input type="number" step="0.5" id="${field_cantidad}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Cantidad Minima<br>
|
||||
<input type="number" step="0.5" id="${field_cantidad_min}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Ubicación<br>
|
||||
<input type="text" id="${field_ubicacion}" value="-"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Notas<br>
|
||||
<textarea id="${field_notas}"></textarea><br><br>
|
||||
</label><hr>
|
||||
<button class="btn5" id="${btn_guardar}">Guardar</button>
|
||||
<button class="rojo" id="${btn_borrar}">Borrar</button>
|
||||
</fieldset>
|
||||
`;
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("materiales")
|
||||
.get(mid)
|
||||
.once((data, key) => {
|
||||
function load_data(data, ENC = "") {
|
||||
document.getElementById(nameh1).innerText = key;
|
||||
document.getElementById(field_nombre).value = data["Nombre"] || "";
|
||||
document.getElementById(field_unidad).value = data["Unidad"] || "";
|
||||
document.getElementById(field_cantidad).value =
|
||||
data["Cantidad"] || "";
|
||||
document.getElementById(field_cantidad_min).value =
|
||||
data["Cantidad_Minima"] || "";
|
||||
document.getElementById(field_ubicacion).value =
|
||||
data["Ubicacion"] || "-";
|
||||
document.getElementById(field_referencia).value =
|
||||
data["Referencia"] || "?";
|
||||
document.getElementById(field_notas).value = data["Notas"] || "";
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
load_data(data, "%E");
|
||||
});
|
||||
} else {
|
||||
load_data(data);
|
||||
}
|
||||
});
|
||||
document.getElementById(btn_guardar).onclick = () => {
|
||||
var data = {
|
||||
Nombre: document.getElementById(field_nombre).value,
|
||||
Unidad: document.getElementById(field_unidad).value,
|
||||
Cantidad: document.getElementById(field_cantidad).value,
|
||||
Cantidad_Minima: document.getElementById(field_cantidad_min).value,
|
||||
Ubicacion: document.getElementById(field_ubicacion).value,
|
||||
Referencia: document.getElementById(field_referencia).value,
|
||||
Notas: document.getElementById(field_notas).value,
|
||||
};
|
||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
||||
document.getElementById("actionStatus").style.display = "block";
|
||||
betterGunPut(gun.get(TABLE).get("materiales").get(mid), encrypted);
|
||||
toastr.success("Guardado!");
|
||||
setTimeout(() => {
|
||||
document.getElementById("actionStatus").style.display = "none";
|
||||
setUrlHash("materiales");
|
||||
}, 1500);
|
||||
});
|
||||
};
|
||||
document.getElementById(btn_borrar).onclick = () => {
|
||||
if (confirm("¿Quieres borrar este material?") == true) {
|
||||
betterGunPut(gun.get(TABLE).get("materiales").get(mid), null);
|
||||
toastr.error("Borrado!");
|
||||
setTimeout(() => {
|
||||
setUrlHash("materiales");
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
},
|
||||
index: function () {
|
||||
const tablebody = safeuuid();
|
||||
var btn_new = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Materiales</h1>
|
||||
<button id="${btn_new}">Nuevo Material</button>
|
||||
<div id="scrolltable"><table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Referencia</th>
|
||||
<th>Nombre</th>
|
||||
<th>Ubicación</th>
|
||||
<th>Cantidad</th>
|
||||
<th>Notas</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="${tablebody}">
|
||||
</tbody>
|
||||
</table></div>
|
||||
`;
|
||||
tableScroll("#scrolltable");
|
||||
var tablebody_EL = document.getElementById(tablebody);
|
||||
var rows = {};
|
||||
function render() {
|
||||
function sorter(a, b) {
|
||||
if (a.Nombre < b.Nombre) {
|
||||
return -1;
|
||||
}
|
||||
if (a.Nombre > b.Nombre) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var tablebody_EL = document.getElementById(tablebody);
|
||||
tablebody_EL.innerHTML = "";
|
||||
Object.values(rows)
|
||||
.sort(sorter)
|
||||
.forEach((data) => {
|
||||
var new_tr = document.createElement("tr");
|
||||
new_tr.innerHTML = `
|
||||
<td>${data.Referencia || "?"}</td>
|
||||
<td>${data.Nombre || "?"}</td>
|
||||
<td>${data.Ubicacion || "?"}</td>
|
||||
<td>${data.Cantidad || "?"} ${data.Unidad || "?"}</td>
|
||||
<td>${data.Notas || "?"}</td>
|
||||
`;
|
||||
var min = parseFloat(data.Cantidad_Minima);
|
||||
var act = parseFloat(data.Cantidad);
|
||||
if (act < min) {
|
||||
new_tr.style.backgroundColor = "lightcoral";
|
||||
}
|
||||
new_tr.onclick = () => {
|
||||
setUrlHash("materiales," + data._key);
|
||||
};
|
||||
tablebody_EL.append(new_tr);
|
||||
});
|
||||
}
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("materiales")
|
||||
.map()
|
||||
.on((data, key, _msg, _ev) => {
|
||||
EVENTLISTENER = _ev;
|
||||
function add_row(data, key) {
|
||||
if (data != null) {
|
||||
data["_key"] = key;
|
||||
rows[key] = data;
|
||||
} else {
|
||||
delete rows[key];
|
||||
}
|
||||
render();
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
add_row(data, key);
|
||||
});
|
||||
} else {
|
||||
add_row(data, key);
|
||||
}
|
||||
});
|
||||
document.getElementById(btn_new).onclick = () => {
|
||||
setUrlHash("materiales," + safeuuid(""));
|
||||
};
|
||||
},
|
||||
};
|
||||
217
src/page/notificaciones.js
Normal file
217
src/page/notificaciones.js
Normal file
@@ -0,0 +1,217 @@
|
||||
PAGES.notificaciones = {
|
||||
navcss: "btn6",
|
||||
Title: "Notificaciones",
|
||||
edit: function (mid) {
|
||||
var nameh1 = safeuuid();
|
||||
var field_fecha = safeuuid();
|
||||
var field_asunto = safeuuid();
|
||||
var field_origen = safeuuid();
|
||||
var field_destino = safeuuid();
|
||||
var field_estado = safeuuid();
|
||||
var field_mensaje = safeuuid();
|
||||
var field_respuesta = safeuuid();
|
||||
var btn_leer = safeuuid();
|
||||
var btn_desleer = safeuuid();
|
||||
var btn_guardar = safeuuid();
|
||||
var btn_borrar = safeuuid();
|
||||
var div_actions = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Notificación <code id="${nameh1}"></code></h1>
|
||||
<fieldset style="float: left;">
|
||||
<legend>Valores</legend>
|
||||
<label>
|
||||
Fecha<br>
|
||||
<input readonly disabled type="text" id="${field_fecha}" value="${CurrentISODate()}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Asunto<br>
|
||||
<input type="text" id="${field_asunto}" value=""><br><br>
|
||||
</label>
|
||||
<input type="hidden" id="${field_origen}">
|
||||
<input type="hidden" id="${field_destino}">
|
||||
<div id="${div_actions}"></div>
|
||||
<label>
|
||||
Mensaje<br>
|
||||
<textarea id="${field_mensaje}"></textarea><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Respuesta<br>
|
||||
<textarea id="${field_respuesta}"></textarea><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Estado<br>
|
||||
<input readonly disabled type="text" id="${field_estado}" value="%%">
|
||||
<br>
|
||||
<button id="${btn_leer}">Leido</button>
|
||||
<button id="${btn_desleer}">No leido</button>
|
||||
<br>
|
||||
</label><hr>
|
||||
<button class="btn5" id="${btn_guardar}">Guardar</button>
|
||||
<button class="rojo" id="${btn_borrar}">Borrar</button>
|
||||
</fieldset>
|
||||
`;
|
||||
document.getElementById(btn_leer).onclick = () => {
|
||||
document.getElementById(field_estado).value = "leido";
|
||||
};
|
||||
document.getElementById(btn_desleer).onclick = () => {
|
||||
document.getElementById(field_estado).value = "por_leer";
|
||||
};
|
||||
var divact = document.getElementById(div_actions);
|
||||
addCategory_Personas(
|
||||
divact,
|
||||
SC_Personas,
|
||||
"",
|
||||
(value) => {
|
||||
document.getElementById(field_origen).value = value;
|
||||
},
|
||||
"Origen"
|
||||
);
|
||||
addCategory_Personas(
|
||||
divact,
|
||||
SC_Personas,
|
||||
"",
|
||||
(value) => {
|
||||
document.getElementById(field_destino).value = value;
|
||||
},
|
||||
"Destino"
|
||||
);
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("notificaciones")
|
||||
.get(mid)
|
||||
.once((data, key) => {
|
||||
function load_data(data, ENC = "") {
|
||||
document.getElementById(nameh1).innerText = key;
|
||||
document.getElementById(field_fecha).value = data["Fecha"];
|
||||
document.getElementById(field_asunto).value = data["Asunto"] || "";
|
||||
document.getElementById(field_mensaje).value =
|
||||
data["Mensaje"] || "";
|
||||
document.getElementById(field_origen).value = data["Origen"] || "";
|
||||
document.getElementById(field_destino).value =
|
||||
data["Destino"] || "";
|
||||
document.getElementById(field_estado).value = data["Estado"] || "";
|
||||
document.getElementById(field_respuesta).value =
|
||||
data["Respuesta"] || "";
|
||||
|
||||
// Persona select
|
||||
divact.innerHTML = "";
|
||||
addCategory_Personas(
|
||||
divact,
|
||||
SC_Personas,
|
||||
data["Origen"] || "",
|
||||
(value) => {
|
||||
document.getElementById(field_origen).value = value;
|
||||
},
|
||||
"Origen"
|
||||
);
|
||||
addCategory_Personas(
|
||||
divact,
|
||||
SC_Personas,
|
||||
data["Destino"] || "",
|
||||
(value) => {
|
||||
document.getElementById(field_destino).value = value;
|
||||
},
|
||||
"Destino"
|
||||
);
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
load_data(data, "%E");
|
||||
});
|
||||
} else {
|
||||
load_data(data);
|
||||
}
|
||||
});
|
||||
document.getElementById(btn_guardar).onclick = () => {
|
||||
if (document.getElementById(field_origen).value == "") {
|
||||
alert("¡Hay que elegir una persona de origen!");
|
||||
return;
|
||||
}
|
||||
if (document.getElementById(field_destino).value == "") {
|
||||
alert("¡Hay que elegir una persona de origen!");
|
||||
return;
|
||||
}
|
||||
var data = {
|
||||
Fecha: document.getElementById(field_fecha).value,
|
||||
Origen: document.getElementById(field_origen).value,
|
||||
Destino: document.getElementById(field_destino).value,
|
||||
Mensaje: document.getElementById(field_mensaje).value,
|
||||
Respuesta: document.getElementById(field_respuesta).value,
|
||||
Asunto: document.getElementById(field_asunto).value,
|
||||
Estado: document
|
||||
.getElementById(field_estado)
|
||||
.value.replace("%%", "por_leer"),
|
||||
};
|
||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
||||
document.getElementById("actionStatus").style.display = "block";
|
||||
betterGunPut(
|
||||
gun.get(TABLE).get("notificaciones").get(mid),
|
||||
encrypted
|
||||
);
|
||||
toastr.success("Guardado!");
|
||||
setTimeout(() => {
|
||||
document.getElementById("actionStatus").style.display = "none";
|
||||
setUrlHash("notificaciones");
|
||||
}, 1500);
|
||||
});
|
||||
};
|
||||
document.getElementById(btn_borrar).onclick = () => {
|
||||
if (confirm("¿Quieres borrar esta notificación?") == true) {
|
||||
betterGunPut(gun.get(TABLE).get("notificaciones").get(mid), null);
|
||||
toastr.error("Borrado!");
|
||||
setTimeout(() => {
|
||||
setUrlHash("notificaciones");
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
},
|
||||
index: function () {
|
||||
const tablebody = safeuuid();
|
||||
var btn_new = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Notificaciones</h1>
|
||||
<button id="${btn_new}">Nueva notificación</button>
|
||||
<div id="cont">
|
||||
`;
|
||||
TS_IndexElement(
|
||||
"notificaciones",
|
||||
[
|
||||
{
|
||||
key: "Origen",
|
||||
type: "persona",
|
||||
default: "",
|
||||
label: "Origen",
|
||||
},
|
||||
{
|
||||
key: "Destino",
|
||||
type: "persona",
|
||||
default: "",
|
||||
label: "Destino",
|
||||
},
|
||||
{
|
||||
key: "Asunto",
|
||||
type: "raw",
|
||||
default: "",
|
||||
label: "Asunto",
|
||||
},
|
||||
{
|
||||
key: "Estado",
|
||||
type: "raw",
|
||||
default: "",
|
||||
label: "Estado",
|
||||
},
|
||||
],
|
||||
gun.get(TABLE).get("notificaciones"),
|
||||
document.querySelector("#cont"),
|
||||
(data, new_tr) => {
|
||||
new_tr.style.backgroundColor = "#FFCCCB";
|
||||
if (data.Estado == "leido") {
|
||||
new_tr.style.backgroundColor = "lightgreen";
|
||||
}
|
||||
}
|
||||
);
|
||||
document.getElementById(btn_new).onclick = () => {
|
||||
setUrlHash("notificaciones," + safeuuid(""));
|
||||
};
|
||||
},
|
||||
}
|
||||
222
src/page/personas.js
Normal file
222
src/page/personas.js
Normal file
@@ -0,0 +1,222 @@
|
||||
PAGES.personas = {
|
||||
navcss: "btn4",
|
||||
Title: "Personas",
|
||||
edit: function (mid) {
|
||||
var nameh1 = safeuuid();
|
||||
var field_nombre = safeuuid();
|
||||
var field_zona = safeuuid();
|
||||
var field_roles = safeuuid();
|
||||
var field_puntos = safeuuid();
|
||||
var field_notas = safeuuid();
|
||||
var field_anilla = safeuuid();
|
||||
var field_foto = safeuuid();
|
||||
var render_foto = safeuuid();
|
||||
var btn_guardar = safeuuid();
|
||||
var btn_borrar = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Persona <code id="${nameh1}"></code></h1>
|
||||
<fieldset>
|
||||
<label>
|
||||
Nombre<br>
|
||||
<input type="text" id="${field_nombre}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Zona<br>
|
||||
<input type="text" id="${field_zona}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Permisos<br>
|
||||
<input type="text" id="${field_roles}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Puntos<br>
|
||||
<input type="number" id="${field_puntos}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Anilla<br>
|
||||
<input type="color" id="${field_anilla}"><br><br>
|
||||
</label>
|
||||
<label>
|
||||
Foto (PNG o JPG)<br>
|
||||
<img id="${render_foto}" height="100px" style="border: 3px inset; min-width: 7px;" src="static/camera2.png">
|
||||
<input type="file" accept="image/*" id="${field_foto}" style="display: none;"><br><br>
|
||||
</label>
|
||||
|
||||
|
||||
<label>
|
||||
Notas<br>
|
||||
<textarea id="${field_notas}"></textarea><br><br>
|
||||
</label><hr>
|
||||
<button class="btn5" id="${btn_guardar}">Guardar</button>
|
||||
<button class="rojo" id="${btn_borrar}">Borrar</button>
|
||||
</fieldset>
|
||||
`;
|
||||
var resized = "";
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("personas")
|
||||
.get(mid)
|
||||
.once((data, key) => {
|
||||
function load_data(data, ENC = "") {
|
||||
document.getElementById(nameh1).innerText = key;
|
||||
document.getElementById(field_nombre).value = data["Nombre"] || "";
|
||||
document.getElementById(field_zona).value = data["Region"] || "";
|
||||
document.getElementById(field_roles).value = data["Roles"] || "";
|
||||
document.getElementById(field_puntos).value = data["Puntos"] || 0;
|
||||
document.getElementById(field_anilla).value = data["SC_Anilla"] || "";
|
||||
// document.getElementById(field_foto).value = "";
|
||||
document.getElementById(render_foto).src =
|
||||
data["Foto"] || "static/ico/user_generic.png";
|
||||
resized = data["Foto"] || "static/ico/user_generic.png";
|
||||
document.getElementById(field_notas).value = data["markdown"] || "";
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
load_data(data, "%E");
|
||||
});
|
||||
} else {
|
||||
load_data(data);
|
||||
}
|
||||
});
|
||||
document
|
||||
.getElementById(field_foto)
|
||||
.addEventListener("change", function (e) {
|
||||
const file = e.target.files[0];
|
||||
if (!file) return;
|
||||
|
||||
resizeInputImage(
|
||||
file,
|
||||
function (url) {
|
||||
document.getElementById(render_foto).src = url;
|
||||
resized = url;
|
||||
},
|
||||
125,
|
||||
0.7
|
||||
);
|
||||
});
|
||||
document.getElementById(btn_guardar).onclick = () => {
|
||||
var data = {
|
||||
Nombre: document.getElementById(field_nombre).value,
|
||||
Region: document.getElementById(field_zona).value,
|
||||
Roles: document.getElementById(field_roles).value,
|
||||
Puntos: document.getElementById(field_puntos).value,
|
||||
SC_Anilla: document.getElementById(field_anilla).value,
|
||||
Foto: resized,
|
||||
markdown: document.getElementById(field_notas).value,
|
||||
};
|
||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
||||
document.getElementById("actionStatus").style.display = "block";
|
||||
betterGunPut(gun.get(TABLE).get("personas").get(mid), encrypted);
|
||||
toastr.success("Guardado!");
|
||||
setTimeout(() => {
|
||||
document.getElementById("actionStatus").style.display = "none";
|
||||
setUrlHash("personas");
|
||||
}, 1500);
|
||||
});
|
||||
};
|
||||
document.getElementById(btn_borrar).onclick = () => {
|
||||
if (confirm("¿Quieres borrar esta persona?") == true) {
|
||||
betterGunPut(gun.get(TABLE).get("personas").get(mid), null);
|
||||
toastr.error("Borrado!");
|
||||
setTimeout(() => {
|
||||
setUrlHash("personas");
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
},
|
||||
index: function () {
|
||||
const tablebody = safeuuid();
|
||||
var btn_new = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Personas</h1>
|
||||
<button id="${btn_new}">Nueva Persona</button>
|
||||
<div id="scrolltable"><table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nombre</th>
|
||||
<th>Zona</th>
|
||||
<th>Puntos</th>
|
||||
<th>Permisos</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="${tablebody}">
|
||||
</tbody>
|
||||
</table></div>
|
||||
`;
|
||||
tableScroll("#scrolltable"); // id="scrolltable"
|
||||
var tablebody_EL = document.getElementById(tablebody);
|
||||
var rows = {};
|
||||
function render() {
|
||||
function sorter(a, b) {
|
||||
if (a.Region.toUpperCase() < b.Region.toUpperCase()) {
|
||||
return -1;
|
||||
}
|
||||
if (a.Region.toUpperCase() > b.Region.toUpperCase()) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var tablebody_EL = document.getElementById(tablebody);
|
||||
tablebody_EL.innerHTML = "";
|
||||
// SC_Personas = rows
|
||||
Object.values(rows)
|
||||
.sort(sorter)
|
||||
.forEach((data) => {
|
||||
var btn_comanda = safeuuid();
|
||||
var new_tr = document.createElement("tr");
|
||||
new_tr.innerHTML = `
|
||||
<td class="TextBorder" style="background-color: ${
|
||||
data.SC_Anilla
|
||||
}; text-align: center"><img src="${
|
||||
data.Foto || "static/ico/user_generic.png"
|
||||
}" height="50"> <br> ${data.Nombre || ""}</td>
|
||||
<td>${data.Region || "?"}</td>
|
||||
<td>${data.Puntos || 0}</td>
|
||||
<td>${data.Roles || ""}</td>
|
||||
`;
|
||||
|
||||
// <button id="${btn_comanda}" class="${PAGES.ventas.navcss}">Nueva venta</button>
|
||||
var act = parseFloat(data.Puntos);
|
||||
if (act >= 10) {
|
||||
new_tr.style.backgroundColor = "gold";
|
||||
}
|
||||
new_tr.onclick = () => {
|
||||
setUrlHash("personas," + data._key);
|
||||
};
|
||||
tablebody_EL.append(new_tr);
|
||||
// document.getElementById(btn_comanda).onclick = (e) => {
|
||||
// setUrlHash("ventas," + data._key);
|
||||
// if (!e) var e = window.event;
|
||||
// e.cancelBubble = true;
|
||||
// if (e.stopPropagation) e.stopPropagation();
|
||||
// };
|
||||
});
|
||||
}
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("personas")
|
||||
.map()
|
||||
.on((data, key, _msg, _ev) => {
|
||||
EVENTLISTENER = _ev;
|
||||
function add_row(data, key) {
|
||||
if (data != null) {
|
||||
data["_key"] = key;
|
||||
rows[key] = data;
|
||||
} else {
|
||||
delete rows[key];
|
||||
}
|
||||
render();
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
add_row(data, key);
|
||||
});
|
||||
} else {
|
||||
add_row(data, key);
|
||||
}
|
||||
});
|
||||
document.getElementById(btn_new).onclick = () => {
|
||||
setUrlHash("personas," + safeuuid(""));
|
||||
};
|
||||
},
|
||||
};
|
||||
142
src/page/resumen_diario.js
Normal file
142
src/page/resumen_diario.js
Normal file
@@ -0,0 +1,142 @@
|
||||
PAGES.resumen_diario = {
|
||||
navcss: "btn3",
|
||||
Title: "Resumen Semanal",
|
||||
index: function () {
|
||||
var table_materialesLow = safeuuid();
|
||||
var table_personasHigh = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Resumen Semanal</h1>
|
||||
<h2>Personas con café gratis (para el Viernes)</h2>
|
||||
<div id="${table_personasHigh}"></div>
|
||||
<h2>Materiales faltantes (o por llegar)</h2>
|
||||
<div id="${table_materialesLow}"></div>
|
||||
`;
|
||||
var materiales_low = {};
|
||||
var personas_high = {};
|
||||
function render_materialesLow() {
|
||||
function sorter(a, b) {
|
||||
if (a.Nombre < b.Nombre) {
|
||||
return -1;
|
||||
}
|
||||
if (a.Nombre > b.Nombre) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var tablebody_EL = document.getElementById(table_materialesLow);
|
||||
tablebody_EL.innerHTML = "";
|
||||
Object.values(materiales_low)
|
||||
.sort(sorter)
|
||||
.forEach((data) => {
|
||||
var min = parseFloat(data.Cantidad_Minima);
|
||||
var act = parseFloat(data.Cantidad);
|
||||
var falta = min - act;
|
||||
if (act < min) {
|
||||
var new_tr = document.createElement("span");
|
||||
new_tr.innerHTML = `<b>${data.Nombre || "?"}</b><br>Faltan ${
|
||||
falta || "?"
|
||||
} ${data.Unidad || "?"} <br><i style="font-size: 75%">${
|
||||
data.Ubicacion || "?"
|
||||
}</i>`;
|
||||
new_tr.className = PAGES["materiales"].navcss;
|
||||
new_tr.style.display = "inline-block";
|
||||
new_tr.style.margin = "5px";
|
||||
new_tr.style.padding = "5px";
|
||||
new_tr.style.borderRadius = "5px";
|
||||
new_tr.style.border = "2px solid black";
|
||||
new_tr.style.cursor = "pointer";
|
||||
new_tr.onclick = () => {
|
||||
setUrlHash("materiales," + data._key);
|
||||
};
|
||||
tablebody_EL.append(new_tr);
|
||||
}
|
||||
});
|
||||
}
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("materiales")
|
||||
.map()
|
||||
.on((data, key, _msg, _ev) => {
|
||||
EVENTLISTENER2 = _ev;
|
||||
function add_row(data, key) {
|
||||
if (data != null) {
|
||||
data["_key"] = key;
|
||||
materiales_low[key] = data;
|
||||
} else {
|
||||
delete materiales_low[key];
|
||||
}
|
||||
render_materialesLow();
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
add_row(data, key);
|
||||
});
|
||||
} else {
|
||||
add_row(data, key);
|
||||
}
|
||||
});
|
||||
function render_personasHigh() {
|
||||
function sorter(a, b) {
|
||||
if (a.Nombre < b.Nombre) {
|
||||
return -1;
|
||||
}
|
||||
if (a.Nombre > b.Nombre) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
var tablebody_EL = document.getElementById(table_personasHigh);
|
||||
tablebody_EL.innerHTML = "";
|
||||
Object.values(personas_high)
|
||||
.sort(sorter)
|
||||
.forEach((data) => {
|
||||
if (data.Puntos >= 10) {
|
||||
var new_tr = document.createElement("span");
|
||||
new_tr.innerHTML = `<img src="${
|
||||
data.Foto || ""
|
||||
}" alt="" height="55" style="float: left; margin-right: 5px;"><b>${
|
||||
data.Nombre || "?"
|
||||
}</b><br>Tiene ${
|
||||
data.Puntos || "?"
|
||||
} puntos <br><i style="font-size: 75%">${data.Region || "?"}</i>`;
|
||||
new_tr.className = PAGES["personas"].navcss;
|
||||
new_tr.style.display = "inline-block";
|
||||
new_tr.style.margin = "5px";
|
||||
new_tr.style.padding = "5px";
|
||||
new_tr.style.borderRadius = "5px";
|
||||
new_tr.style.border = "2px solid black";
|
||||
new_tr.style.cursor = "pointer";
|
||||
new_tr.style.width = "200px";
|
||||
|
||||
new_tr.onclick = () => {
|
||||
setUrlHash("personas," + data._key);
|
||||
};
|
||||
tablebody_EL.append(new_tr);
|
||||
}
|
||||
});
|
||||
}
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("personas")
|
||||
.map()
|
||||
.on((data, key, _msg, _ev) => {
|
||||
EVENTLISTENER = _ev;
|
||||
function add_row(data, key) {
|
||||
if (data != null) {
|
||||
data["_key"] = key;
|
||||
personas_high[key] = data;
|
||||
} else {
|
||||
delete personas_high[key];
|
||||
}
|
||||
render_personasHigh();
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
add_row(data, key);
|
||||
});
|
||||
} else {
|
||||
add_row(data, key);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
314
src/page/supercafe.js
Normal file
314
src/page/supercafe.js
Normal file
@@ -0,0 +1,314 @@
|
||||
PAGES.supercafe = {
|
||||
navcss: "btn5",
|
||||
Title: "SuperCafé",
|
||||
edit: function (mid) {
|
||||
var nameh1 = safeuuid();
|
||||
var field_fecha = safeuuid();
|
||||
var field_persona = safeuuid();
|
||||
var field_comanda = safeuuid();
|
||||
var field_notas = safeuuid();
|
||||
var field_estado = safeuuid();
|
||||
var div_actions = safeuuid();
|
||||
var btn_pagos = safeuuid();
|
||||
var btn_cocina = safeuuid();
|
||||
var btn_guardar = safeuuid();
|
||||
var btn_guardar2 = safeuuid();
|
||||
var btn_borrar = safeuuid();
|
||||
container.innerHTML = `
|
||||
<h1>Comanda <code id="${nameh1}"></code></h1>
|
||||
<button onclick="setUrlHash('supercafe');">Salir</button>
|
||||
<fieldset style="text-align: center;">
|
||||
<legend>Rellenar comanda</legend>
|
||||
<label style="display: none;">
|
||||
Fecha<br>
|
||||
<input readonly disabled type="text" id="${field_fecha}" value="${CurrentISODate()}"><br><br>
|
||||
</label>
|
||||
<label style="display: none;">
|
||||
Persona<br>
|
||||
<input type="hidden" id="${field_persona}">
|
||||
<br><br>
|
||||
</label>
|
||||
<label style="display: none;">
|
||||
Comanda (utiliza el panel de relleno)<br>
|
||||
<textarea readonly disabled id="${field_comanda}"></textarea><br><br>
|
||||
</label>
|
||||
<div id="${div_actions}" open>
|
||||
<!--<summary>Mostrar botones de relleno</summary>-->
|
||||
</div>
|
||||
<label>
|
||||
Notas<br>
|
||||
<textarea id="${field_notas}"></textarea><br><br>
|
||||
</label>
|
||||
<label style="display: none;">
|
||||
Estado<br>
|
||||
<input readonly disabled type="text" id="${field_estado}" value="%%">
|
||||
<br>Modificar en el listado de comandas<br>
|
||||
</label>
|
||||
<button id=${btn_guardar} class="btn5">Guardar</button>
|
||||
<button id=${btn_borrar} class="rojo">Borrar</button>
|
||||
</fieldset>
|
||||
`;
|
||||
var currentData = {};
|
||||
var currentPersonaID = "";
|
||||
var divact = document.getElementById(div_actions);
|
||||
|
||||
function loadActions() {
|
||||
divact.innerHTML = "";
|
||||
addCategory_Personas(divact, SC_Personas, currentPersonaID, (value) => {
|
||||
document.getElementById(field_persona).value = value;
|
||||
});
|
||||
Object.entries(SC_actions).forEach((category) => {
|
||||
addCategory(
|
||||
divact,
|
||||
category[0],
|
||||
SC_actions_icons[category[0]],
|
||||
category[1],
|
||||
currentData,
|
||||
(values) => {
|
||||
document.getElementById(field_comanda).value = SC_parse(values);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
loadActions();
|
||||
gun
|
||||
.get(TABLE)
|
||||
.get("supercafe")
|
||||
.get(mid)
|
||||
.once((data, key) => {
|
||||
function load_data(data, ENC = "") {
|
||||
document.getElementById(nameh1).innerText = key;
|
||||
document.getElementById(field_fecha).value = data["Fecha"];
|
||||
document.getElementById(field_persona).value =
|
||||
data["Persona"] || "";
|
||||
currentPersonaID = data["Persona"] || "";
|
||||
document.getElementById(field_comanda).value =
|
||||
SC_parse(JSON.parse(data["Comanda"] || "{}")) || "";
|
||||
document.getElementById(field_notas).value = data["Notas"] || "";
|
||||
document.getElementById(field_estado).value = data["Estado"] || "";
|
||||
currentData = JSON.parse(data["Comanda"] || "{}");
|
||||
|
||||
loadActions();
|
||||
}
|
||||
if (typeof data == "string") {
|
||||
SEA.decrypt(data, SECRET, (data) => {
|
||||
load_data(data, "%E");
|
||||
});
|
||||
} else {
|
||||
load_data(data);
|
||||
}
|
||||
});
|
||||
document.getElementById(btn_guardar).onclick = () => {
|
||||
if (document.getElementById(field_persona).value == "") {
|
||||
alert("¡Hay que elegir una persona!");
|
||||
return;
|
||||
}
|
||||
var data = {
|
||||
Fecha: document.getElementById(field_fecha).value,
|
||||
Persona: document.getElementById(field_persona).value,
|
||||
Comanda: JSON.stringify(currentData),
|
||||
Notas: document.getElementById(field_notas).value,
|
||||
Estado: document
|
||||
.getElementById(field_estado)
|
||||
.value.replace("%%", "Pedido"),
|
||||
};
|
||||
var enc = SEA.encrypt(data, SECRET, (encrypted) => {
|
||||
document.getElementById("actionStatus").style.display = "block";
|
||||
betterGunPut(gun.get(TABLE).get("supercafe").get(mid), encrypted);
|
||||
toastr.success("Guardado!");
|
||||
setTimeout(() => {
|
||||
document.getElementById("actionStatus").style.display = "none";
|
||||
setUrlHash("supercafe");
|
||||
}, 1500);
|
||||
});
|
||||
};
|
||||
document.getElementById(btn_borrar).onclick = () => {
|
||||
if (
|
||||
confirm(
|
||||
"¿Quieres borrar esta comanda? - NO se actualizaran los puntos de la persona asignada."
|
||||
) == true
|
||||
) {
|
||||
betterGunPut(gun.get(TABLE).get("supercafe").get(mid), null);
|
||||
setTimeout(() => {
|
||||
setUrlHash("supercafe");
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
},
|
||||
index: function () {
|
||||
var tts = false;
|
||||
var sc_nobtn = "";
|
||||
if (urlParams.get("sc_nobtn") == "yes") {
|
||||
sc_nobtn = "pointer-events: none; opacity: 0.5";
|
||||
}
|
||||
setTimeout(() => {
|
||||
tts = true;
|
||||
console.log("TTS Enabled");
|
||||
toastr.info("Texto a voz disponible");
|
||||
}, 6500);
|
||||
const tablebody = safeuuid();
|
||||
const tablebody2 = safeuuid();
|
||||
var btn_new = safeuuid();
|
||||
var tts_check = safeuuid();
|
||||
var old = {};
|
||||
container.innerHTML = `
|
||||
<h1>SuperCafé</h1>
|
||||
<button id="${btn_new}" style="${sc_nobtn};">Nueva comanda</button>
|
||||
<br>
|
||||
<label>
|
||||
<b>Habilitar avisos:</b>
|
||||
<input type="checkbox" id="${tts_check}" style="height: 25px;width: 25px;">
|
||||
</label>
|
||||
|
||||
<details style="background: beige; padding: 15px; border-radius: 15px; border: 2px solid black" open>
|
||||
<summary>Todas las comandas</summary>
|
||||
<div id="cont1"></div>
|
||||
</details>
|
||||
<br>
|
||||
<details style="background: lightpink; padding: 15px; border-radius: 15px; border: 2px solid black" open>
|
||||
<summary>Deudas</summary>
|
||||
<div id="cont2"></div>
|
||||
</details>
|
||||
`;
|
||||
|
||||
//Todas las comandas
|
||||
TS_IndexElement(
|
||||
"supercafe",
|
||||
[
|
||||
{
|
||||
key: "Persona",
|
||||
type: "persona",
|
||||
default: "",
|
||||
label: "Persona",
|
||||
},
|
||||
{
|
||||
key: "Estado",
|
||||
type: "comanda-status",
|
||||
default: "",
|
||||
label: "Estado",
|
||||
},
|
||||
{
|
||||
key: "Comanda",
|
||||
type: "comanda",
|
||||
default: "",
|
||||
label: "Comanda",
|
||||
},
|
||||
],
|
||||
gun.get(TABLE).get("supercafe"),
|
||||
document.querySelector("#cont1"),
|
||||
(data, new_tr) => {
|
||||
// new_tr.style.backgroundColor = "#FFCCCB";
|
||||
|
||||
if (data.Estado == "Pedido") {
|
||||
new_tr.style.backgroundColor = "#FFFFFF";
|
||||
}
|
||||
if (data.Estado == "En preparación") {
|
||||
new_tr.style.backgroundColor = "#FFCCCB";
|
||||
}
|
||||
if (data.Estado == "Listo") {
|
||||
new_tr.style.backgroundColor = "gold";
|
||||
}
|
||||
if (data.Estado == "Entregado") {
|
||||
new_tr.style.backgroundColor = "lightgreen";
|
||||
}
|
||||
if (data.Estado == "Deuda") {
|
||||
new_tr.style.backgroundColor = "#f5d3ff";
|
||||
}
|
||||
},
|
||||
(data) => {
|
||||
if (data.Estado == "Deuda") {
|
||||
return true;
|
||||
}
|
||||
var key = data._key;
|
||||
if (old[key] == undefined) {
|
||||
old[key] = "";
|
||||
}
|
||||
if (old[key] != data.Estado) {
|
||||
if (tts && document.getElementById(tts_check).checked) {
|
||||
var msg = `Comanda de ${SC_Personas[data.Persona].Region}. - ${
|
||||
JSON.parse(data.Comanda)["Selección"]
|
||||
}. - ${SC_Personas[data.Persona].Nombre}. - ${data.Estado}`;
|
||||
console.log("TTS: " + msg);
|
||||
let utterance = new SpeechSynthesisUtterance(msg);
|
||||
utterance.rate = 0.9;
|
||||
// utterance.voice = speechSynthesis.getVoices()[7]
|
||||
speechSynthesis.speak(utterance);
|
||||
}
|
||||
}
|
||||
old[key] = data.Estado;
|
||||
}
|
||||
);
|
||||
|
||||
//Deudas
|
||||
TS_IndexElement(
|
||||
"supercafe",
|
||||
[
|
||||
{
|
||||
key: "Persona",
|
||||
type: "persona",
|
||||
default: "",
|
||||
label: "Persona",
|
||||
},
|
||||
{
|
||||
key: "Estado",
|
||||
type: "comanda-status",
|
||||
default: "",
|
||||
label: "Estado",
|
||||
},
|
||||
{
|
||||
key: "Comanda",
|
||||
type: "comanda",
|
||||
default: "",
|
||||
label: "Comanda",
|
||||
},
|
||||
],
|
||||
gun.get(TABLE).get("supercafe"),
|
||||
document.querySelector("#cont2"),
|
||||
(data, new_tr) => {
|
||||
// new_tr.style.backgroundColor = "#FFCCCB";
|
||||
|
||||
if (data.Estado == "Pedido") {
|
||||
new_tr.style.backgroundColor = "#FFFFFF";
|
||||
}
|
||||
if (data.Estado == "En preparación") {
|
||||
new_tr.style.backgroundColor = "#FFCCCB";
|
||||
}
|
||||
if (data.Estado == "Listo") {
|
||||
new_tr.style.backgroundColor = "gold";
|
||||
}
|
||||
if (data.Estado == "Entregado") {
|
||||
new_tr.style.backgroundColor = "lightgreen";
|
||||
}
|
||||
if (data.Estado == "Deuda") {
|
||||
new_tr.style.backgroundColor = "#f5d3ff";
|
||||
}
|
||||
},
|
||||
(data) => {
|
||||
if (data.Estado != "Deuda") {
|
||||
return true;
|
||||
}
|
||||
var key = data._key;
|
||||
if (old[key] == undefined) {
|
||||
old[key] = "";
|
||||
}
|
||||
if (old[key] != data.Estado) {
|
||||
if (tts && document.getElementById(tts_check).checked) {
|
||||
var msg = `Comanda de ${SC_Personas[data.Persona].Region}. - ${
|
||||
JSON.parse(data.Comanda)["Selección"]
|
||||
}. - ${SC_Personas[data.Persona].Nombre}. - ${data.Estado}`;
|
||||
console.log("TTS: " + msg);
|
||||
let utterance = new SpeechSynthesisUtterance(msg);
|
||||
utterance.rate = 0.9;
|
||||
// utterance.voice = speechSynthesis.getVoices()[7]
|
||||
speechSynthesis.speak(utterance);
|
||||
}
|
||||
}
|
||||
old[key] = data.Estado;
|
||||
}
|
||||
);
|
||||
|
||||
document.getElementById(btn_new).onclick = () => {
|
||||
setUrlHash("supercafe," + safeuuid(""));
|
||||
};
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user