fix
This commit is contained in:
parent
c986ccca9f
commit
9fea16dfe0
@ -40,21 +40,20 @@
|
|||||||
<main class="container-fluid p-2">
|
<main class="container-fluid p-2">
|
||||||
<h1 class="text-warning text-center font-weight-bold">Панель администратора</h1>
|
<h1 class="text-warning text-center font-weight-bold">Панель администратора</h1>
|
||||||
<div class="btn-group" role="group">
|
<div class="btn-group" role="group">
|
||||||
<button id="items-add" class="btn btn-primary">Добавить товар (диалог)</button>
|
<a class="btn btn-warning" href="/page-edit.html">Добавить товар</a>
|
||||||
<a class="btn btn-danger" href="/page-edit.html">Добавить товар (страница)</a>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-warning text-center font-weight-bold" style="padding-top: 30px;">Таблица данных</h2>
|
<h2 class="text-warning text-center font-weight-bold" style="padding-top: 10px;">Таблица данных</h2>
|
||||||
<table id="items-table" class="table table-striped">
|
<table id="items-table" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<th scope="col">№</th>
|
<th scope="col">№</th>
|
||||||
<th scope="col" class="w-25">Товар</th>
|
<th scope="col" class="w-25">Товар</th>
|
||||||
<th scope="col" class="w-25">Цена</th>
|
<th scope="col" class="w-25">Цена</th>
|
||||||
|
<th scope="col" class="w-10">Акция</th>
|
||||||
<th scope="col" class="w-25">Количество</th>
|
<th scope="col" class="w-25">Количество</th>
|
||||||
<th scope="col" class="w-25">Сумма</th>
|
<th scope="col" class="w-25">Сумма</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
<th scope="col"></th>
|
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
</table>
|
</table>
|
||||||
@ -87,6 +86,11 @@
|
|||||||
<input id="price" name="price" class="form-control" type="number" value="99.00" min="99.00"
|
<input id="price" name="price" class="form-control" type="number" value="99.00" min="99.00"
|
||||||
step="1.00" required>
|
step="1.00" required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label class="form-label" for="stock">Акция</label>
|
||||||
|
<input id="stock" name="price" class="form-control" type="number" value="0" min="0"
|
||||||
|
step="100" required>
|
||||||
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="form-label" for="count">Количество</label>
|
<label class="form-label" for="count">Количество</label>
|
||||||
<input id="count" name="count" class="form-control" type="number" value="0" min="1" step="1"
|
<input id="count" name="count" class="form-control" type="number" value="0" min="1" step="1"
|
||||||
|
File diff suppressed because one or more lines are too long
@ -1,37 +0,0 @@
|
|||||||
import { Modal } from "bootstrap";
|
|
||||||
import { cntrls, imagePlaceholder } from "./lines-ui";
|
|
||||||
|
|
||||||
const modal = document.getElementById("items-update");
|
|
||||||
const myModal = modal ? new Modal(modal, {}) : null;
|
|
||||||
const modalTitle = document.getElementById("items-update-title");
|
|
||||||
|
|
||||||
function resetValues() {
|
|
||||||
cntrls.lineId.value = "";
|
|
||||||
cntrls.itemsType.value = "";
|
|
||||||
cntrls.price.value = parseFloat(0).toFixed(2);
|
|
||||||
cntrls.count.value = 0;
|
|
||||||
cntrls.image.value = "";
|
|
||||||
cntrls.imagePreview.src = imagePlaceholder;
|
|
||||||
}
|
|
||||||
export function showUpdateModal(item) {
|
|
||||||
modalTitle.innerHTML = item === null ? "Добавить" : "Изменить";
|
|
||||||
console.info(item);
|
|
||||||
|
|
||||||
if (item) {
|
|
||||||
cntrls.lineId.value = item.id;
|
|
||||||
cntrls.itemsType.value = item.itemsId;
|
|
||||||
cntrls.price.value = item.price;
|
|
||||||
cntrls.count.value = item.count;
|
|
||||||
cntrls.imagePreview.src = item.image ? item.image : imagePlaceholder;
|
|
||||||
} else {
|
|
||||||
resetValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
myModal.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function hideUpdateModal() {
|
|
||||||
resetValues();
|
|
||||||
cntrls.form.classList.remove("was-validated");
|
|
||||||
myModal.hide();
|
|
||||||
}
|
|
@ -1,11 +1,12 @@
|
|||||||
const serverUrl = "http://localhost:8081";
|
const serverUrl = "http://localhost:8081";
|
||||||
|
|
||||||
function createLineObject(item, price, count, image) {
|
function createLineObject(item, price, stock, count, image) {
|
||||||
return {
|
return {
|
||||||
itemsId: item,
|
itemsId: item,
|
||||||
price: parseFloat(price).toFixed(2),
|
price: parseFloat(price).toFixed(2),
|
||||||
|
stock,
|
||||||
count,
|
count,
|
||||||
sum: parseFloat(price * count).toFixed(2),
|
sum: parseFloat((price * ((100 - stock) / 100)) * count).toFixed(2),
|
||||||
image,
|
image,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -34,8 +35,8 @@ export async function getLine(id) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createLine(item, price, count, image) {
|
export async function createLine(item, price, stock, count, image) {
|
||||||
const itemObject = createLineObject(item, price, count, image);
|
const itemObject = createLineObject(item, price, stock, count, image);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -53,8 +54,8 @@ export async function createLine(item, price, count, image) {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateLine(id, item, price, count, image) {
|
export async function updateLine(id, item, price, stock, count, image) {
|
||||||
const itemObject = createLineObject(item, price, count, image);
|
const itemObject = createLineObject(item, price, stock, count, image);
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
@ -5,6 +5,7 @@ export const cntrls = {
|
|||||||
lineId: document.getElementById("items-line-id"),
|
lineId: document.getElementById("items-line-id"),
|
||||||
itemsType: document.getElementById("item"),
|
itemsType: document.getElementById("item"),
|
||||||
price: document.getElementById("price"),
|
price: document.getElementById("price"),
|
||||||
|
stock: document.getElementById("stock"),
|
||||||
count: document.getElementById("count"),
|
count: document.getElementById("count"),
|
||||||
image: document.getElementById("image"),
|
image: document.getElementById("image"),
|
||||||
imagePreview: document.getElementById("image-preview"),
|
imagePreview: document.getElementById("image-preview"),
|
||||||
@ -41,7 +42,7 @@ function createTableColumn(value) {
|
|||||||
return td;
|
return td;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createTableRow(item, index, editCallback, editPageCallback, deleteCallback) {
|
export function createTableRow(item, index, editCallback, deleteCallback) {
|
||||||
const rowNumber = document.createElement("th");
|
const rowNumber = document.createElement("th");
|
||||||
rowNumber.scope = "row";
|
rowNumber.scope = "row";
|
||||||
rowNumber.textContent = index + 1;
|
rowNumber.textContent = index + 1;
|
||||||
@ -50,10 +51,10 @@ export function createTableRow(item, index, editCallback, editPageCallback, dele
|
|||||||
row.appendChild(rowNumber);
|
row.appendChild(rowNumber);
|
||||||
row.appendChild(createTableColumn(item.items.name));
|
row.appendChild(createTableColumn(item.items.name));
|
||||||
row.appendChild(createTableColumn(parseFloat(item.price).toFixed(2)));
|
row.appendChild(createTableColumn(parseFloat(item.price).toFixed(2)));
|
||||||
|
row.appendChild(createTableColumn(item.stock != null ? item.stock + "%" : ""));
|
||||||
row.appendChild(createTableColumn(item.count));
|
row.appendChild(createTableColumn(item.count));
|
||||||
row.appendChild(createTableColumn(parseFloat(item.sum).toFixed(2)));
|
row.appendChild(createTableColumn(parseFloat(item.sum).toFixed(2)));
|
||||||
row.appendChild(createTableAnchor("fa-pencil", editCallback));
|
row.appendChild(createTableAnchor("fa-pencil", editCallback));
|
||||||
row.appendChild(createTableAnchor("fa-pen-to-square", editPageCallback));
|
|
||||||
row.appendChild(createTableAnchor("fa-trash", deleteCallback));
|
row.appendChild(createTableAnchor("fa-trash", deleteCallback));
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { hideUpdateModal, showUpdateModal } from "./lines-modal";
|
|
||||||
import {
|
import {
|
||||||
createLine, deleteLine, getAllItemTypes, getAllLines, getLine, updateLine,
|
createLine, deleteLine, getAllItemTypes, getAllLines, getLine, updateLine,
|
||||||
} from "./lines-rest-api";
|
} from "./lines-rest-api";
|
||||||
@ -27,7 +26,6 @@ async function drawLinesTable() {
|
|||||||
createTableRow(
|
createTableRow(
|
||||||
item,
|
item,
|
||||||
index,
|
index,
|
||||||
() => showUpdateModal(item),
|
|
||||||
() => location.assign(`page-edit.html?id=${item.id}`),
|
() => location.assign(`page-edit.html?id=${item.id}`),
|
||||||
() => removeLine(item.id),
|
() => removeLine(item.id),
|
||||||
),
|
),
|
||||||
@ -35,17 +33,17 @@ async function drawLinesTable() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addLine(item, price, count, image) {
|
async function addLine(item, price, stock, count, image) {
|
||||||
console.info("Try to add item");
|
console.info("Try to add item");
|
||||||
const data = await createLine(item, price, count, image);
|
const data = await createLine(item, price, stock, count, image);
|
||||||
console.info("Added");
|
console.info("Added");
|
||||||
console.info(data);
|
console.info(data);
|
||||||
drawLinesTable();
|
drawLinesTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function editLine(id, item, price, count, image) {
|
async function editLine(id, item, price, stock, count, image) {
|
||||||
console.info("Try to update item");
|
console.info("Try to update item");
|
||||||
const data = await updateLine(id, item, price, count, image);
|
const data = await updateLine(id, item, price, stock, count, image);
|
||||||
console.info("Updated");
|
console.info("Updated");
|
||||||
console.info(data);
|
console.info(data);
|
||||||
drawLinesTable();
|
drawLinesTable();
|
||||||
@ -88,7 +86,6 @@ export function linesForm() {
|
|||||||
drawItemsSelect();
|
drawItemsSelect();
|
||||||
drawLinesTable();
|
drawLinesTable();
|
||||||
cntrls.image.addEventListener("change", () => updateImagePreview());
|
cntrls.image.addEventListener("change", () => updateImagePreview());
|
||||||
cntrls.button.addEventListener("click", () => showUpdateModal(null));
|
|
||||||
cntrls.form.addEventListener("submit", async (event) => {
|
cntrls.form.addEventListener("submit", async (event) => {
|
||||||
console.info("Form onSubmit");
|
console.info("Form onSubmit");
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -107,6 +104,7 @@ export function linesForm() {
|
|||||||
await addLine(
|
await addLine(
|
||||||
cntrls.itemsType.value,
|
cntrls.itemsType.value,
|
||||||
cntrls.price.value,
|
cntrls.price.value,
|
||||||
|
cntrls.stock.value,
|
||||||
cntrls.count.value,
|
cntrls.count.value,
|
||||||
imageBase64,
|
imageBase64,
|
||||||
);
|
);
|
||||||
@ -115,11 +113,11 @@ export function linesForm() {
|
|||||||
currentId,
|
currentId,
|
||||||
cntrls.itemsType.value,
|
cntrls.itemsType.value,
|
||||||
cntrls.price.value,
|
cntrls.price.value,
|
||||||
|
cntrls,stock.value,
|
||||||
cntrls.count.value,
|
cntrls.count.value,
|
||||||
imageBase64,
|
imageBase64,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
hideUpdateModal();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +133,7 @@ export async function linesPageForm() {
|
|||||||
const line = await getLine(currentId);
|
const line = await getLine(currentId);
|
||||||
cntrls.itemsType.value = line.itemsId;
|
cntrls.itemsType.value = line.itemsId;
|
||||||
cntrls.price.value = line.price;
|
cntrls.price.value = line.price;
|
||||||
|
cntrls.stock.value = line.stock;
|
||||||
cntrls.count.value = line.count;
|
cntrls.count.value = line.count;
|
||||||
cntrls.imagePreview.src = line.image ? line.image : imagePlaceholder;
|
cntrls.imagePreview.src = line.image ? line.image : imagePlaceholder;
|
||||||
} catch {
|
} catch {
|
||||||
@ -159,6 +158,7 @@ export async function linesPageForm() {
|
|||||||
await addLine(
|
await addLine(
|
||||||
cntrls.itemsType.value,
|
cntrls.itemsType.value,
|
||||||
cntrls.price.value,
|
cntrls.price.value,
|
||||||
|
cntrls.stock.value,
|
||||||
cntrls.count.value,
|
cntrls.count.value,
|
||||||
imageBase64,
|
imageBase64,
|
||||||
);
|
);
|
||||||
@ -167,6 +167,7 @@ export async function linesPageForm() {
|
|||||||
currentId,
|
currentId,
|
||||||
cntrls.itemsType.value,
|
cntrls.itemsType.value,
|
||||||
cntrls.price.value,
|
cntrls.price.value,
|
||||||
|
cntrls.stock.value,
|
||||||
cntrls.count.value,
|
cntrls.count.value,
|
||||||
imageBase64,
|
imageBase64,
|
||||||
);
|
);
|
||||||
|
@ -55,6 +55,11 @@
|
|||||||
<input id="price" name="price" class="form-control" type="number" value="0.00" min="1000.00" step="0.50"
|
<input id="price" name="price" class="form-control" type="number" value="0.00" min="1000.00" step="0.50"
|
||||||
required>
|
required>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-2">
|
||||||
|
<label class="form-label" for="stock">Акция</label>
|
||||||
|
<input id="stock" name="price" class="form-control" type="number" value="0" min="0"
|
||||||
|
step="1" required>
|
||||||
|
</div>
|
||||||
<div class="mb-2">
|
<div class="mb-2">
|
||||||
<label class="form-label" for="count">Количество</label>
|
<label class="form-label" for="count">Количество</label>
|
||||||
<input id="count" name="count" class="form-control" type="number" value="0" min="1" step="1" required>
|
<input id="count" name="count" class="form-control" type="number" value="0" min="1" step="1" required>
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user