57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
import { Modal } from "bootstrap";
|
|
import { controls, imagePlaceholder } from "./admin_panel_ui";
|
|
|
|
const modal = document.getElementById("items-update");
|
|
const myModal = modal ? new Modal(modal, {}) : null;
|
|
|
|
const modalTitle = document.getElementById("items-update-title");
|
|
|
|
function resetValues() {
|
|
controls.lineId.value = "";
|
|
controls.imagePreview.src = imagePlaceholder;
|
|
|
|
controls.title.value = "";
|
|
controls.type.value = "";
|
|
controls.requiresSubscription.checked = false;
|
|
controls.image.value = "";
|
|
controls.description.value = "";
|
|
controls.releaseDate.value = "";
|
|
controls.country.value = "";
|
|
controls.tagline.value = "";
|
|
controls.director.value = "";
|
|
controls.ageRating.value = "";
|
|
controls.video.value = "";
|
|
}
|
|
|
|
export function showUpdateModal(item) {
|
|
modalTitle.innerHTML = item === null ? "Добавить" : "Изменить";
|
|
console.info(item);
|
|
|
|
if (item) {
|
|
controls.lineId.value = item.id;
|
|
controls.imagePreview.src = item.poster ? item.poster : imagePlaceholder;
|
|
|
|
controls.title.value = item.title;
|
|
controls.type.value = item.type;
|
|
controls.requiresSubscription.checked = item.requiresSubscription;
|
|
controls.description.value = item.description;
|
|
controls.releaseDate.value = item.releaseDate;
|
|
controls.country.value = item.country;
|
|
controls.tagline.value = item.tagline;
|
|
controls.director.value = item.director;
|
|
controls.ageRating.value = item.ageRating;
|
|
controls.video.value = item.video;
|
|
} else {
|
|
resetValues();
|
|
}
|
|
|
|
myModal.show();
|
|
}
|
|
|
|
export function hideUpdateModal() {
|
|
resetValues();
|
|
controls.form.classList.remove("was-validated");
|
|
|
|
myModal.hide();
|
|
}
|