diff --git a/main.js b/main.js index d62083c..777d5a9 100644 --- a/main.js +++ b/main.js @@ -549,7 +549,17 @@ } function moveNewFilesOnVariantChange() { - + document.querySelectorAll(`input[name^="new_file_type"]`).forEach(el => el.addEventListener("change", function() { + let attachmentIndex = this.name.replace(/\D/g,'') + + let from = this.value == "l" ? "history" : "legend" + let to = this.value == "l" ? "legend" : "history" + let type = attachmentIndex == 1 ? "photo" : "files" + let newFiles = [...document.querySelectorAll(`.${from}-${type}-container .file-container-new`)] + for (const newFile of newFiles) { + document.querySelector(`.${to}-${type}-container .file-list-container`).appendChild(newFile) + } + })) } function removeDeletedFilesFromUglyVersion(removeLink) { @@ -568,7 +578,8 @@ function prettify(form, was, became, insertedFileRows) { moveInputValues(form, was, became) prettifyFiles(insertedFileRows) - + + moveNewFilesOnVariantChange() $("#cps_main").select2() makeCoordinatesLinks() }