internet-programming/1 семестр/lab2/js/lines-modal.js

37 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-02 21:33:55 +04:00
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();
2023-11-03 11:28:48 +04:00
}