fix history files
This commit is contained in:
parent
eeca874d35
commit
ce50b1cecd
56
main.js
56
main.js
@ -422,16 +422,13 @@
|
||||
if (variant !== null) {
|
||||
if (inputName == "attachment1" || inputName == "attachment4") {
|
||||
if (variant == "l") {
|
||||
let fileContainerClassName = fileInputs[inputName][variant].replace("_", "-")
|
||||
fileListContainer = document.querySelector(`.${fileContainerClassName}-container .file-list-container`)
|
||||
fileListContainer = document.querySelector(`[data-container="${fileInputs[inputName][variant]}"] .file-list-container`)
|
||||
}
|
||||
else if (variant == "h") {
|
||||
let filesContainer = document.querySelector(inputName == "attachment1" ? `.history-photo-container` : `.history-files-container`)
|
||||
let filesContainer = document.querySelector(`[data-container="${fileInputs[inputName].h}"]`)
|
||||
fileListContainer = filesContainer.querySelector(`.file-list-container`)
|
||||
if (fileListContainer == null) {
|
||||
fileListContainer = document.createElement("div")
|
||||
fileListContainer.classList.add("file-list-container")
|
||||
filesContainer.append(fileListContainer)
|
||||
filesContainer.append(makeFileListContainer())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -530,11 +527,16 @@
|
||||
}
|
||||
|
||||
function getContainersByVariant(variant, attachmentIndex) {
|
||||
let from = variant == "l" ? "history" : "legend"
|
||||
let to = variant == "l" ? "legend" : "history"
|
||||
let type = attachmentIndex == 1 ? "photo" : "files"
|
||||
let invertedVariant = variant == "l" ? "h" : "l"
|
||||
let variants = fileInputs[`attachment${attachmentIndex}`]
|
||||
|
||||
return [document.querySelector(`.${from}-${type}-container`), document.querySelector(`.${to}-${type}-container`)]
|
||||
return [document.querySelector(`[data-container="${variants[invertedVariant]}"]`), document.querySelector(`[data-container="${variants[variant]}"]`)]
|
||||
}
|
||||
|
||||
function makeFileListContainer() {
|
||||
return Tag.div({
|
||||
classes: "file-list-container"
|
||||
})
|
||||
}
|
||||
|
||||
function makeHandleFilesFunc() {
|
||||
@ -560,6 +562,10 @@
|
||||
if (variant) {
|
||||
let [_, filesContainer] = getContainersByVariant(variant, getAttachmentIndex(this))
|
||||
fileListContainer = filesContainer.querySelector(".file-list-container")
|
||||
if (fileListContainer == null) {
|
||||
fileListContainer = makeFileListContainer()
|
||||
filesContainer.append(fileListContainer)
|
||||
}
|
||||
}
|
||||
else {
|
||||
fileListContainer = this.parentElement.parentElement.querySelector(".file-list-container")
|
||||
@ -645,10 +651,7 @@
|
||||
})
|
||||
element.parentElement.insertBefore(pseudoInput, element)
|
||||
|
||||
let fileListContainer = Tag.div({
|
||||
classes: "file-list-container"
|
||||
})
|
||||
element.parentElement.parentElement.append(fileListContainer)
|
||||
element.parentElement.parentElement.append(makeFileListContainer())
|
||||
|
||||
element.addEventListener("change", makeHandleFilesFunc(), false)
|
||||
})
|
||||
@ -907,10 +910,13 @@
|
||||
async function sendForm(onSend) {
|
||||
let formData = new FormData(document.querySelector("form"))
|
||||
|
||||
let fileListContainers = [...document.querySelectorAll(".file-list-container")]
|
||||
let fileInputNames = ["legend_photo", "history_photo", "legend_files", "history_files", "admin_photo", "admin_files"]
|
||||
for (let [i, fileListContainer] of fileListContainers.entries()) {
|
||||
formData.set(`cp[${fileInputNames[i]}]`, [...fileListContainer.children].filter(el => !el.classList.contains("file-container-new")).length)
|
||||
let fileInputNames = Object.values(fileInputs).reduce((res, el) => typeof el == "string" ? [...res, el] : [...res, ...Object.values(el)], [])
|
||||
for (const fileInput of fileInputNames) {
|
||||
let fileListContainer = document.querySelector(`[data-container=${fileInput}] .file-list-container`)
|
||||
if (fileListContainer) {
|
||||
let count = [...fileListContainer.children].filter(el => !el.classList.contains("file-container-new")).length
|
||||
formData.set(`cp[${fileInput}]`, count)
|
||||
}
|
||||
}
|
||||
|
||||
if (formData.get("cp[id]") == '') {
|
||||
@ -1489,24 +1495,28 @@
|
||||
let legendFilesContainer = document.createElement("div")
|
||||
legendFilesContainer.classList.add("legend-container__files")
|
||||
|
||||
let imagesForLegendContainer = createFrom(rows, "files-container legend-photo-container", [
|
||||
let imagesForLegendContainer = createFrom(rows, "files-container", [
|
||||
{ index: 23, name: "Фото в легенде" }
|
||||
])
|
||||
imagesForLegendContainer.dataset.container = fileInputs.attachment1.l
|
||||
legendFilesContainer.append(imagesForLegendContainer)
|
||||
|
||||
let imagesForHistoryContainer = createFrom(rows, "files-container history-photo-container", [
|
||||
let imagesForHistoryContainer = createFrom(rows, "files-container", [
|
||||
{ name: "Фото для ИС" }
|
||||
])
|
||||
imagesForHistoryContainer.dataset.container = fileInputs.attachment1.h
|
||||
legendFilesContainer.append(imagesForHistoryContainer)
|
||||
|
||||
let audioForLegendContainer = createFrom(rows, "files-container legend-files-container", [
|
||||
let audioForLegendContainer = createFrom(rows, "files-container", [
|
||||
{ index: 27, name: "Файлы в легенде" }
|
||||
])
|
||||
audioForLegendContainer.dataset.container = fileInputs.attachment4.l
|
||||
legendFilesContainer.append(audioForLegendContainer)
|
||||
|
||||
let audioForHistoryContainer = createFrom(rows, "files-container history-files-container", [
|
||||
let audioForHistoryContainer = createFrom(rows, "files-container", [
|
||||
{ name: "Файлы для ИС" }
|
||||
])
|
||||
audioForHistoryContainer.dataset.container = fileInputs.attachment4.h
|
||||
legendFilesContainer.append(audioForHistoryContainer)
|
||||
|
||||
return legendFilesContainer
|
||||
@ -1519,11 +1529,13 @@
|
||||
let imagesForAdminContainer = createFrom(rows, "files-container admin-photo-container", [
|
||||
{ index: 31, name: "Фото в админке" }
|
||||
])
|
||||
imagesForAdminContainer.dataset.container = fileInputs.attachment2
|
||||
adminFilesContainer.append(imagesForAdminContainer)
|
||||
|
||||
let audioForAdminContainer = createFrom(rows, "files-container admin-files-container", [
|
||||
{ index: 35, name: "Файлы в админке" }
|
||||
])
|
||||
audioForAdminContainer.dataset.container = fileInputs.attachment3
|
||||
adminFilesContainer.append(audioForAdminContainer)
|
||||
|
||||
return adminFilesContainer
|
||||
|
Loading…
Reference in New Issue
Block a user