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