Rewrite materiales
This commit is contained in:
@@ -757,6 +757,12 @@ function TS_IndexElement(
|
|||||||
tdRaw.innerHTML = rawContent;
|
tdRaw.innerHTML = rawContent;
|
||||||
new_tr.appendChild(tdRaw);
|
new_tr.appendChild(tdRaw);
|
||||||
break;
|
break;
|
||||||
|
case "template":
|
||||||
|
const tdCustomTemplate = document.createElement("td");
|
||||||
|
tdCustomTemplate.style.verticalAlign = "top";
|
||||||
|
tdCustomTemplate.innerHTML = key.format(data);
|
||||||
|
new_tr.appendChild(tdCustomTemplate);
|
||||||
|
break;
|
||||||
case "comanda":
|
case "comanda":
|
||||||
const tdComanda = document.createElement("td");
|
const tdComanda = document.createElement("td");
|
||||||
tdComanda.style.verticalAlign = "top";
|
tdComanda.style.verticalAlign = "top";
|
||||||
|
|||||||
@@ -106,85 +106,42 @@ PAGES.materiales = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
index: function () {
|
index: function () {
|
||||||
const tablebody = safeuuid();
|
|
||||||
var btn_new = safeuuid();
|
var btn_new = safeuuid();
|
||||||
container.innerHTML = `
|
container.innerHTML = `
|
||||||
<h1>Materiales</h1>
|
<h1>Materiales</h1>
|
||||||
<button id="${btn_new}">Nuevo Material</button>
|
<button id="${btn_new}">Nuevo Material</button>
|
||||||
<div id="scrolltable"><table>
|
<div id="tableContainer"></div>
|
||||||
<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);
|
const config = [
|
||||||
var rows = {};
|
{ key: "Referencia", label: "Referencia", type: "text", default: "?" },
|
||||||
function render() {
|
{ key: "Nombre", label: "Nombre", type: "text", default: "?" },
|
||||||
function sorter(a, b) {
|
{ key: "Ubicacion", label: "Ubicación", type: "text", default: "?" },
|
||||||
if (a.Nombre < b.Nombre) {
|
{
|
||||||
return -1;
|
key: "Cantidad",
|
||||||
}
|
label: "Cantidad",
|
||||||
if (a.Nombre > b.Nombre) {
|
type: "template",
|
||||||
return 1;
|
template: (data) => {
|
||||||
}
|
const min = parseFloat(data.Cantidad_Minima);
|
||||||
return 0;
|
const act = parseFloat(data.Cantidad);
|
||||||
}
|
const style = act < min ? 'style="background-color: lightcoral;"' : '';
|
||||||
var tablebody_EL = document.getElementById(tablebody);
|
return `<td ${style}>${data.Cantidad || "?"} ${data.Unidad || "?"} - (min. ${data.Cantidad_Minima || "?"})</td>`;
|
||||||
tablebody_EL.innerHTML = "";
|
},
|
||||||
Object.values(rows)
|
default: "?"
|
||||||
.sort(sorter)
|
},
|
||||||
.forEach((data) => {
|
{ key: "Notas", label: "Notas", type: "text", default: "?" }
|
||||||
var new_tr = document.createElement("tr");
|
];
|
||||||
new_tr.innerHTML = `
|
|
||||||
<td>${data.Referencia || "?"}</td>
|
TS_IndexElement(
|
||||||
<td>${data.Nombre || "?"}</td>
|
PAGES.materiales,
|
||||||
<td>${data.Ubicacion || "?"}</td>
|
config,
|
||||||
<td>${data.Cantidad || "?"} ${data.Unidad || "?"}</td>
|
gun.get(TABLE).get("materiales"),
|
||||||
<td>${data.Notas || "?"}</td>
|
document.getElementById("tableContainer"),
|
||||||
`;
|
undefined,
|
||||||
var min = parseFloat(data.Cantidad_Minima);
|
undefined,
|
||||||
var act = parseFloat(data.Cantidad);
|
true // Enable global search bar
|
||||||
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 = () => {
|
document.getElementById(btn_new).onclick = () => {
|
||||||
setUrlHash("materiales," + safeuuid(""));
|
setUrlHash("materiales," + safeuuid(""));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user