From c455d287357c9d6d14ae6586541ca3f62c1d8d1b Mon Sep 17 00:00:00 2001 From: Zhora Shalyapin Date: Wed, 12 Mar 2025 13:30:07 +0000 Subject: [PATCH] add history files --- main.js | 70 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 17 deletions(-) diff --git a/main.js b/main.js index 9cc8ddc..091ae6c 100644 --- a/main.js +++ b/main.js @@ -38,13 +38,12 @@ let removedFilesLinks = [] class Property { - id; name; content; desc; - constructor(id, row) { - this.id = id + constructor(row = null) { + if (row == null) return let columns = [...row.querySelectorAll('td, th')].map(el => el.cloneNode(true)) if (columns.length === 1) { @@ -60,9 +59,7 @@ this.content = columns[1].innerHTML .replaceAll("
", "") .replaceAll(/\s*Перейти к легенде.*$/gs, "") - .replaceAll("для легенды (\"l\")", "") .replaceAll("общие (\"c\")", "") - .replaceAll("для ист. справки (\"h\")", "") .replaceAll("Получить координаты КП из картинки", "") .trim() } @@ -78,7 +75,7 @@ desc = desc ? "
" + "" + "
" : "" - div.innerHTML = "" + "
" + this.content + "
" + + div.innerHTML = "" + "
" + (this.content ?? "") + "
" + desc return div } @@ -88,8 +85,16 @@ let container = document.createElement('div') container.classList.add(...classList.split(" ")) for (const options of data) { - let prop = new Property(options.index, rows[options.index]) - container.appendChild(prop.toDiv(options.name, options.desc)) + let div + if (options.index != null) { + let prop = new Property(rows[options.index]) + div = prop.toDiv(options.name, options.desc) + } + else { + let prop = new Property() + div = prop.toDiv(options.name) + } + container.appendChild(div) } return container @@ -241,11 +246,30 @@ } } - function addDisplayedFile(inputName, type, file, preview, removeLink) { + function addDisplayedFile(inputName, type, file, preview, removeLink, purpose = null) { if (!inputName || !file || !removeLink) return + let fileListContainer + if (purpose !== null) { + if (inputName == "attachment1" || inputName == "attachment4") { + if (purpose == "для легенды") { + let fileContainerClassName = fileInputs[inputName].replace("_", "-") + fileListContainer = document.querySelector(`.${fileContainerClassName}-container .file-list-container`) + } + else if (purpose == "для ист. справки") { + let filesContainer = document.querySelector(inputName == "attachment1" ? `.history-photo-container` : `.history-files-container`) + fileListContainer = filesContainer.querySelector(`.file-list-container`) + if (fileListContainer == null) { + fileListContainer = document.createElement("div") + fileListContainer.classList.add("file-list-container") + filesContainer.appendChild(fileListContainer) + } + } + } + } + let input = document.querySelector(`input[name="${inputName}\[\]"]`) - let fileListContainer = input.parentElement.parentElement.querySelector(".file-list-container") + fileListContainer ??= input.parentElement.parentElement.querySelector(".file-list-container") let fileContainer = document.createElement("div") fileContainer.classList.add("file-container") @@ -498,7 +522,9 @@ return } - addDisplayedFile(fileInput, type, fileUrl, preview, deleteUrl) + let purpose = row.querySelector("td:nth-child(2)")?.innerHTML.match(/для[^\|]+/g)[0].trim() + + addDisplayedFile(fileInput, type, fileUrl, preview, deleteUrl, purpose) } } } @@ -1006,7 +1032,7 @@ } } - .files-container input[type=radio] { + .files-container input[type=radio][value="c"] { display: none; } @@ -1230,7 +1256,7 @@ ]) let copyLink = document.createElement("div") - copyLink.innerHTML = new Property(2, rows[2]).desc + copyLink.innerHTML = new Property(rows[2]).desc headerContainer.append(copyLink) /* TOP BUTTONS */ @@ -1403,27 +1429,37 @@ let legendFilesContainer = document.createElement("div") legendFilesContainer.classList.add("legend-container__files") - let imagesForLegendContainer = createFrom(rows, "files-container", [ + let imagesForLegendContainer = createFrom(rows, "files-container legend-photo-container", [ { index: 23, name: "Фото в легенде" } ]) legendFilesContainer.appendChild(imagesForLegendContainer) - let audioForLegendContainer = createFrom(rows, "files-container", [ + let imagesForHistoryContainer = createFrom(rows, "files-container history-photo-container", [ + { name: "Фото для ИС" } + ]) + legendFilesContainer.appendChild(imagesForHistoryContainer) + + let audioForLegendContainer = createFrom(rows, "files-container legend-files-container", [ { index: 27, name: "Файлы в легенде" } ]) legendFilesContainer.appendChild(audioForLegendContainer) + let audioForHistoryContainer = createFrom(rows, "files-container history-files-container", [ + { name: "Файлы для ИС" } + ]) + legendFilesContainer.appendChild(audioForHistoryContainer) + legendContainer.appendChild(legendFilesContainer) let adminFilesContainer = document.createElement('div') adminFilesContainer.classList.add('admin-files-container') - let imagesForAdminContainer = createFrom(rows, "files-container", [ + let imagesForAdminContainer = createFrom(rows, "files-container admin-photo-container", [ { index: 31, name: "Фото в админке" } ]) adminFilesContainer.appendChild(imagesForAdminContainer) - let audioForAdminContainer = createFrom(rows, "files-container", [ + let audioForAdminContainer = createFrom(rows, "files-container admin-files-container", [ { index: 35, name: "Файлы в админке" } ]) adminFilesContainer.appendChild(audioForAdminContainer)