remove global variable

This commit is contained in:
Zhora Shalyapin 2025-04-04 07:30:50 +00:00
parent 49a3d4d493
commit 34780a741a

35
main.js
View File

@ -86,8 +86,6 @@
const stageColors = ["#ff8080", "#ffc680", "#ffff80", "#80ff80", "#80ffff", "#8080ff", "#ff80ff"] const stageColors = ["#ff8080", "#ffc680", "#ffff80", "#80ff80", "#80ffff", "#8080ff", "#ff80ff"]
let removedFilesLinks = []
class Tag { class Tag {
static make(name, params = {}) { static make(name, params = {}) {
let element = document.createElement(name) let element = document.createElement(name)
@ -500,7 +498,7 @@
return Object.keys(fileInpitVariants).find(key => fileInpitVariants[key] === parsePurpose(cell)) return Object.keys(fileInpitVariants).find(key => fileInpitVariants[key] === parsePurpose(cell))
} }
function addDisplayedFile(inputName, type, file, preview, removeLink, variant = null) { function addDisplayedFile(inputName, type, file, preview, removeLink, removedFilesLinks, variant = null) {
if (!inputName || !file || !removeLink) return if (!inputName || !file || !removeLink) return
let fileListContainer let fileListContainer
@ -726,7 +724,7 @@
let prettifyFiles = (function () { let prettifyFiles = (function () {
let executed = false let executed = false
return function (insertedFileRows) { return function (insertedFileRows, removedFilesLinks) {
if (executed) return if (executed) return
executed = true executed = true
@ -746,7 +744,7 @@
element.addEventListener("change", makeHandleFilesFunc(), false) element.addEventListener("change", makeHandleFilesFunc(), false)
}) })
moveFileInputValues(insertedFileRows) moveFileInputValues(insertedFileRows, removedFilesLinks)
} }
})() })()
@ -780,7 +778,7 @@
} }
} }
function moveFileInputValues(insertedFileRows) { function moveFileInputValues(insertedFileRows, removedFilesLinks) {
for (const [inputRowIndex, rows] of insertedFileRows) { for (const [inputRowIndex, rows] of insertedFileRows) {
for (const row of rows) { for (const row of rows) {
let fileInput = null, type = null, fileUrl = null, deleteUrl = null, preview = null let fileInput = null, type = null, fileUrl = null, deleteUrl = null, preview = null
@ -818,7 +816,7 @@
let variant = parsefileInputVariant(row) let variant = parsefileInputVariant(row)
addDisplayedFile(fileInput, type, fileUrl, preview, deleteUrl, variant) addDisplayedFile(fileInput, type, fileUrl, preview, deleteUrl, removedFilesLinks, variant)
} }
} }
} }
@ -848,21 +846,21 @@
createSendButtons() createSendButtons()
} }
function prettifyEditCpForm(form, was, became, insertedFileRows) { function prettifyEditCpForm(form, was, became, insertedFileRows, removedFilesLinks) {
moveInputValues(form, was, became) moveInputValues(form, was, became)
prettifyFiles(insertedFileRows) prettifyFiles(insertedFileRows, removedFilesLinks)
moveNewFilesOnVariantChange() moveNewFilesOnVariantChange()
$("#cps_main").select2() $("#cps_main").select2()
makeCoordinatesLinks() makeCoordinatesLinks()
} }
function uglifyEditCpForm(form, was, became) { function uglifyEditCpForm(form, was, became, removedFilesLinks) {
moveInputValues(form, was, became) moveInputValues(form, was, became)
for (const removedFileLink of removedFilesLinks) { for (const removedFileLink of removedFilesLinks) {
removeDeletedFilesFromUglyVersion(removedFileLink) removeDeletedFilesFromUglyVersion(removedFileLink)
} }
removedFilesLinks = [] removedFilesLinks.length = 0
} }
function createAlwaysPrettifyInput(index) { function createAlwaysPrettifyInput(index) {
@ -1374,7 +1372,7 @@
createPseudoButton(document.querySelector(`input[name="delete_go"]`), deletePoint) createPseudoButton(document.querySelector(`input[name="delete_go"]`), deletePoint)
} }
function makeTopAndBottomButtons(rows, form, oldTable, container, insertedFileRows) { function makeTopAndBottomButtons(rows, form, oldTable, container, insertedFileRows, removedFilesLinks) {
let topButtonsContainer = createFrom(rows, "buttons", [ let topButtonsContainer = createFrom(rows, "buttons", [
{ index: 0 } { index: 0 }
]) ])
@ -1395,7 +1393,7 @@
textContent: "Сделать красиво", textContent: "Сделать красиво",
on: { on: {
click: () => { click: () => {
prettifyEditCpForm(form, oldTable, container, insertedFileRows) prettifyEditCpForm(form, oldTable, container, insertedFileRows, removedFilesLinks)
} }
} }
}) })
@ -1412,7 +1410,7 @@
textContent: "Сделать как было", textContent: "Сделать как было",
on: { on: {
"click": () => { "click": () => {
uglifyEditCpForm(form, container, oldTable) uglifyEditCpForm(form, container, oldTable, removedFilesLinks)
} }
} }
}) })
@ -1698,10 +1696,10 @@
})() })()
} }
function checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows) { function checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows, removedFilesLinks) {
if (localStorage.getItem(localStorageItems.NOT_PRETTIFY_EDIT_CP) === null) { if (localStorage.getItem(localStorageItems.NOT_PRETTIFY_EDIT_CP) === null) {
document.querySelector(`input[name^="always-prettify-0"]`).click() document.querySelector(`input[name^="always-prettify-0"]`).click()
prettifyEditCpForm(form, oldTable, container, insertedFileRows) prettifyEditCpForm(form, oldTable, container, insertedFileRows, removedFilesLinks)
} }
} }
@ -2051,6 +2049,7 @@
let form = document.querySelector('form') let form = document.querySelector('form')
let rows = getRows() let rows = getRows()
let insertedFileRows = getInsertedFileRows(rows) let insertedFileRows = getInsertedFileRows(rows)
let removedFilesLinks = []
let container = makeContainer() let container = makeContainer()
let oldTable = document.querySelector("#props") let oldTable = document.querySelector("#props")
@ -2061,7 +2060,7 @@
/* TOP BUTTONS */ /* TOP BUTTONS */
let [topButtonsContainer, bottomButtonsContainer] = makeTopAndBottomButtons(rows, form, oldTable, container, insertedFileRows) let [topButtonsContainer, bottomButtonsContainer] = makeTopAndBottomButtons(rows, form, oldTable, container, insertedFileRows, removedFilesLinks)
addUglyDeleteListener() addUglyDeleteListener()
createSendButtons() createSendButtons()
@ -2093,7 +2092,7 @@
/* PRETTIFY CHECKBOX */ /* PRETTIFY CHECKBOX */
checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows) checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows, removedFilesLinks)
} }
function isAllPointsSouthOfLat(lat) { function isAllPointsSouthOfLat(lat) {