clean up & insert new file in the correct place
This commit is contained in:
		
							parent
							
								
									cbbbd8e338
								
							
						
					
					
						commit
						047c1046c2
					
				
							
								
								
									
										46
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								main.js
									
									
									
									
									
								
							| @ -70,7 +70,9 @@ | ||||
|         this.content = columns[1].innerHTML | ||||
|           .replaceAll("<br>", "") | ||||
|           .replaceAll(/\s*Перейти к легенде.*$/gs, "") | ||||
|           .replaceAll("общие (\"c\")", "") | ||||
|           .replaceAll(`общие ("c")`, "") | ||||
|           .replaceAll(`("l")`, "") | ||||
|           .replaceAll(`("h")`, "") | ||||
|           .replaceAll("Получить координаты КП из картинки", "") | ||||
|           .trim() | ||||
|       } | ||||
| @ -371,6 +373,18 @@ | ||||
|     return el | ||||
|   } | ||||
| 
 | ||||
|   function getAttachmentIndex(input) { | ||||
|     return input.name.replace(/\D/g, '') | ||||
|   } | ||||
| 
 | ||||
|   function getContainersByVariant(variant, attachmentIndex) { | ||||
|     let from = variant == "l" ? "history" : "legend" | ||||
|     let to = variant == "l" ? "legend" : "history" | ||||
|     let type = attachmentIndex == 1 ? "photo" : "files" | ||||
|      | ||||
|     return [document.querySelector(`.${from}-${type}-container`), document.querySelector(`.${to}-${type}-container`)] | ||||
|   } | ||||
| 
 | ||||
|   function makeHandleFilesFunc() { | ||||
|     let storedFiles = [] | ||||
| 
 | ||||
| @ -388,7 +402,17 @@ | ||||
|         const file = this.files[i] | ||||
|         dt.items.add(file) | ||||
| 
 | ||||
|         let fileListContainer = this.parentElement.parentElement.querySelector(".file-list-container") | ||||
|         let variant = this.parentElement.querySelector('input[type="radio"]:checked')?.value | ||||
|         let fileListContainer | ||||
| 
 | ||||
|         if (variant) { | ||||
|           let [_, filesContainer] = getContainersByVariant(variant, getAttachmentIndex(this)) | ||||
|           fileListContainer = filesContainer.querySelector(".file-list-container") | ||||
|         } | ||||
|         else { | ||||
|           fileListContainer = this.parentElement.parentElement.querySelector(".file-list-container") | ||||
|         } | ||||
| 
 | ||||
|         let fileContainer = document.createElement("div") | ||||
|         fileContainer.classList.add("file-container", "file-container-new") | ||||
| 
 | ||||
| @ -412,7 +436,7 @@ | ||||
|         deleteButton.textContent = "x" | ||||
|         deleteButton.type = "button" | ||||
|         deleteButton.addEventListener("click", e => { | ||||
|           let index = [...fileListContainer.children].indexOf(fileContainer) | ||||
|           let index = [...fileContainer.parentElement.children].indexOf(fileContainer) | ||||
| 
 | ||||
|           if (!confirm("Точно?")) return | ||||
|      | ||||
| @ -425,7 +449,7 @@ | ||||
|           rdt.items.remove(index) | ||||
|           this.files = rdt.files | ||||
|      | ||||
|           fileListContainer.removeChild(fileContainer) | ||||
|           fileContainer.parentElement.removeChild(fileContainer) | ||||
|         }) | ||||
|         fileButtonsContainer.appendChild(deleteButton) | ||||
| 
 | ||||
| @ -550,14 +574,12 @@ | ||||
| 
 | ||||
|   function moveNewFilesOnVariantChange() { | ||||
|     document.querySelectorAll(`input[name^="new_file_type"]`).forEach(el => el.addEventListener("change", function() { | ||||
|       let attachmentIndex = this.name.replace(/\D/g,'') | ||||
|       let attachmentIndex = getAttachmentIndex(this) | ||||
|        | ||||
|       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`)] | ||||
|       let [from, to] = getContainersByVariant(this.value, attachmentIndex) | ||||
|       let newFiles = [...from.querySelectorAll(`.file-container-new`)] | ||||
|       for (const newFile of newFiles) { | ||||
|         document.querySelector(`.${to}-${type}-container .file-list-container`).appendChild(newFile) | ||||
|         to.querySelector(`.file-list-container`).appendChild(newFile) | ||||
|       } | ||||
|     })) | ||||
|   } | ||||
| @ -899,6 +921,10 @@ | ||||
|           margin: 0; | ||||
|         } | ||||
| 
 | ||||
|         input[type=radio] { | ||||
|           margin-right: 5px; | ||||
|         } | ||||
| 
 | ||||
|         input[type="file"] { | ||||
|           display: none; | ||||
|         } | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user