Internet_Programming_Librar.../lab3/all/js/lines-ui.js
2024-01-06 22:18:58 +04:00

81 lines
2.4 KiB
JavaScript

export const cntrls = {
button: document.getElementById("items-add"),
table: document.querySelector("#items-table tbody"),
form: document.getElementById("items-form"),
lineId: document.getElementById("items-line-id"),
itemsType: document.getElementById("item"),
author: document.getElementById("author"),
title: document.getElementById("title"),
itemsLongs: document.getElementById("long"),
image: document.getElementById("image"),
imagePreview: document.getElementById("image-preview"),
text: document.getElementById("text"),
};
export const imagePlaceholder = "https://via.placeholder.com/200";
export function createItemsOption(name, value = "", isSelected = false) {
// console.info("createItemsOption");
const option = document.createElement("option");
option.value = value || "";
option.selected = isSelected;
option.text = name;
return option;
}
function createTableAnchor(icon, callback) {
// console.info("createTableAnchor");
const i = document.createElement("i");
i.classList.add("fa-solid", icon);
i.style.color = "black";
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;
}
function createTableColumn(value) {
// console.info("createTableColumn", value);
const td = document.createElement("td");
td.textContent = value;
return td;
}
export function createTableRow(item, index, editCallback, deleteCallback) {
// console.log(item.items);
// console.log(item.longs);
// console.log("CreateTableRow");
const rowNumber = document.createElement("th");
rowNumber.scope = "row";
rowNumber.textContent = index + 1;
const row = document.createElement("tr");
console.log(row.style.backgroundColor);
row.id = `line-${item.id}`;
row.appendChild(rowNumber);
row.appendChild(createTableColumn(item.items.name));
row.appendChild(createTableColumn(item.author));
row.appendChild(createTableColumn(item.title));
row.appendChild(createTableColumn(item.longs.name));
row.appendChild(createTableAnchor("fa-pencil", editCallback));
// row.appendChild(createTableAnchor("fa-pen-to-square", editPageCallback));
row.appendChild(createTableAnchor("fa-trash", deleteCallback));
return row;
}