Добавление количества страниц книгам

This commit is contained in:
2026-01-23 01:31:50 +03:00
parent 1e0c3478a1
commit 7c3074e8fe
15 changed files with 152 additions and 21 deletions
+6
View File
@@ -234,6 +234,12 @@ $(document).ready(() => {
function renderBook(book) {
$("#book-title").text(book.title);
$("#book-id").text(`ID: ${book.id}`);
if (book.page_count && book.page_count > 0) {
$("#book-page-count-value").text(book.page_count);
$("#book-page-count-text").removeClass("hidden");
} else {
$("#book-page-count-text").addClass("hidden");
}
$("#book-authors-text").text(
book.authors.map((a) => a.name).join(", ") || "Автор неизвестен",
);
+5
View File
@@ -180,6 +180,11 @@ $(document).ready(() => {
clone.querySelector(".book-title").textContent = book.title;
clone.querySelector(".book-authors").textContent =
book.authors.map((a) => a.name).join(", ") || "Автор неизвестен";
if (book.page_count && book.page_count > 0) {
const pageEl = clone.querySelector(".book-page-count");
pageEl.querySelector(".page-count-value").textContent = book.page_count;
pageEl.classList.remove("hidden");
}
clone.querySelector(".book-desc").textContent = book.description || "";
const statusConfig = getStatusConfig(book.status);
@@ -235,18 +235,25 @@ $(document).ready(() => {
const title = $("#book-title").val().trim();
const description = $("#book-description").val().trim();
const pageCount = parseInt($("#book-page-count").val()) || null;
if (!title) {
Utils.showToast("Введите название книги", "error");
return;
}
if (!parseInt(pageCount)) {
Utils.showToast("Введите количество страниц", "error");
return;
}
setLoading(true);
try {
const bookPayload = {
title: title,
description: description || null,
page_count: pageCount ? parseInt(pageCount) : null,
};
const createdBook = await Api.post("/api/books/", bookPayload);
+4
View File
@@ -23,6 +23,7 @@ $(document).ready(() => {
const $titleInput = $("#book-title");
const $descInput = $("#book-description");
const $statusSelect = $("#book-status");
const $pagesInput = $("#book-page-count");
const $submitBtn = $("#submit-btn");
const $submitText = $("#submit-text");
const $loadingSpinner = $("#loading-spinner");
@@ -69,6 +70,7 @@ $(document).ready(() => {
function populateForm(book) {
$titleInput.val(book.title);
$descInput.val(book.description || "");
$pagesInput.val(book.page_count);
$statusSelect.val(book.status);
updateCounters();
}
@@ -329,6 +331,7 @@ $(document).ready(() => {
const title = $titleInput.val().trim();
const description = $descInput.val().trim();
const pages = $pagesInput.val();
const status = $statusSelect.val();
if (!title) {
@@ -340,6 +343,7 @@ $(document).ready(() => {
if (title !== originalBook.title) payload.title = title;
if (description !== (originalBook.description || ""))
payload.description = description || null;
if (pageCount !== originalBook.page_count) payload.page_count = pages;
if (status !== originalBook.status) payload.status = status;
if (Object.keys(payload).length === 0) {
+2 -2
View File
@@ -19,8 +19,8 @@ const StorageHelper = {
const Utils = {
escapeHtml: (text) => {
if (!text) return "";
return text.replace(
if (text === null || text === undefined) return "";
return String(text).replace(
/[&<>"']/g,
(m) =>
({