66 lines
2.2 KiB
JavaScript
66 lines
2.2 KiB
JavaScript
export const controls = {
|
|
button: document.getElementById("addMovieButton"),
|
|
table: document.querySelector("#items-table tbody"),
|
|
form: document.getElementById("items-form"),
|
|
lineId: document.getElementById("items-line-id"),
|
|
imagePreview: document.getElementById("image-preview"),
|
|
|
|
title: document.querySelector('#title'),
|
|
type: document.querySelector('#type'),
|
|
requiresSubscription: document.querySelector('#requiresSubscription'),
|
|
image: document.querySelector('#image'),
|
|
description: document.querySelector('#description'),
|
|
releaseDate: document.querySelector('#releaseDate'),
|
|
country: document.querySelector('#country'),
|
|
tagline: document.querySelector('#tagline'),
|
|
director: document.querySelector('#director'),
|
|
ageRating: document.querySelector('#ageRating'),
|
|
video: document.querySelector('#video'),
|
|
};
|
|
|
|
export const imagePlaceholder = "https://via.placeholder.com/200";
|
|
|
|
export function createTableColumn(value) {
|
|
const td = document.createElement("td");
|
|
td.textContent = value;
|
|
|
|
return td;
|
|
}
|
|
|
|
export function createTableAnchor(icon, callback) {
|
|
const i = document.createElement("i");
|
|
i.classList.add("fa-solid", icon);
|
|
|
|
const a = document.createElement("a");
|
|
a.href = "#";
|
|
a.appendChild(i);
|
|
a.onclick = (event) => {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
callback();
|
|
};
|
|
|
|
const td = document.createElement("td");
|
|
td.appendChild(a);
|
|
return td;
|
|
}
|
|
|
|
export function addTableRow(movie, index, editCallback, deleteCallback) {
|
|
const rowNumber = document.createElement("th");
|
|
rowNumber.scope = "row";
|
|
rowNumber.textContent = index + 1;
|
|
|
|
const row = document.createElement("tr");
|
|
row.id = `line-${movie.id}`;
|
|
|
|
row.appendChild(rowNumber);
|
|
row.appendChild(createTableColumn(movie.title));
|
|
row.appendChild(createTableColumn(movie.type));
|
|
row.appendChild(createTableColumn(movie.requiresSubscription === true ? 'Да' : 'Нет'));
|
|
row.appendChild(createTableColumn(movie.releaseDate));
|
|
row.appendChild(createTableAnchor("fa-pencil", editCallback));
|
|
row.appendChild(createTableAnchor("fa-trash", deleteCallback));
|
|
|
|
return row;
|
|
}
|