This commit is contained in:
Zhora Shalyapin 2025-03-20 12:25:16 +00:00
parent 0f8af9b014
commit e963a3e179

219
main.js
View File

@ -90,7 +90,7 @@
desc desc
constructor(row = null) { constructor(row = null) {
if (row == null) return if (row == null) return
let columns = [...row.querySelectorAll('td, th')].map(el => el.cloneNode(true)) let columns = [...row.querySelectorAll('td, th')].map(el => el.cloneNode(true))
if (columns.length === 1) { if (columns.length === 1) {
@ -102,7 +102,7 @@
if (elementsToRemove) { if (elementsToRemove) {
columns[1].removeChild(elementsToRemove) columns[1].removeChild(elementsToRemove)
} }
this.content = columns[1].innerHTML this.content = columns[1].innerHTML
.replaceAll("<br>", "") .replaceAll("<br>", "")
.replaceAll(/\s*Перейти к легенде.*$/gs, "") .replaceAll(/\s*Перейти к легенде.*$/gs, "")
@ -121,7 +121,7 @@
toDiv(altName = null, altDesc = null) { toDiv(altName = null, altDesc = null) {
let div = document.createElement('div') let div = document.createElement('div')
let desc = altDesc ?? this.desc let desc = altDesc ?? this.desc
desc = desc ? "<div class='desc-icon-container' title='" + desc + "'>" + desc = desc ? "<div class='desc-icon-container' title='" + desc + "'>" +
"<img class='desc-icon' src='data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjwhLS0gQ3JlYXRlZCB3aXRoIElua3NjYXBlIChodHRwOi8vd3d3Lmlua3NjYXBlLm9yZy8pIC0tPgo8c3ZnIGlkPSJzdmcyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGhlaWdodD0iMjAwIiB3aWR0aD0iMjAwIiB2ZXJzaW9uPSIxLjAiPgogPHBhdGggaWQ9InBhdGgyMzgyIiBkPSJtMTY1LjMzIDExMy40NGExMDMuNjEgMTAzLjYxIDAgMSAxIC0yMDcuMjIgMCAxMDMuNjEgMTAzLjYxIDAgMSAxIDIwNy4yMiAweiIgdHJhbnNmb3JtPSJtYXRyaXgoLjkzNzM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MTktMS4wNjItOC4yMy0xLjYtMTMuMzUtMS43NS0wLjc4LTAuMDIzLTEuNTktMC4wMzYtMi4zNy0wLjAzMnptLTEwLjkwOCAxMDMuNnYyMmgyMS45OTh2LTIyaC0yMS45OTh6Ii8+CiA8L2c+Cjwvc3ZnPgo='/>" +
"</div>" : "" "</div>" : ""
div.innerHTML = "<label for=''>" + (altName ?? this.name ?? "") + "</label>" + "<div>" + (this.content ?? "") + "</div>" + div.innerHTML = "<label for=''>" + (altName ?? this.name ?? "") + "</label>" + "<div>" + (this.content ?? "") + "</div>" +
@ -240,7 +240,7 @@
function isRouteMapPage() { function isRouteMapPage() {
return isRouteManagement() && getAction() === "map" return isRouteManagement() && getAction() === "map"
} }
async function updatePoint(formData) { async function updatePoint(formData) {
return await fetch(`https://runcity.geo.rictum.ru/api/competitions/${getCompetition()}/update`, { return await fetch(`https://runcity.geo.rictum.ru/api/competitions/${getCompetition()}/update`, {
method: 'POST', method: 'POST',
@ -308,14 +308,14 @@
return ref return ref
} }
let makeCoordinatesLinks = (function() { let makeCoordinatesLinks = (function () {
var executed = false var executed = false
return function () { return function () {
if (executed) return if (executed) return
executed = true executed = true
let linksContainer = document.createElement("div") let linksContainer = document.createElement("div")
linksContainer.appendChild(copyCoordinates()) linksContainer.appendChild(copyCoordinates())
linksContainer.appendChild(makeRef(yandexMaps, "https://upload.wikimedia.org/wikipedia/commons/7/72/Yandex_Maps_icon.svg", ZOOM)) linksContainer.appendChild(makeRef(yandexMaps, "https://upload.wikimedia.org/wikipedia/commons/7/72/Yandex_Maps_icon.svg", ZOOM))
linksContainer.appendChild(makeRef(googleMaps, "https://upload.wikimedia.org/wikipedia/commons/a/aa/Google_Maps_icon_%282020%29.svg", METERS)) linksContainer.appendChild(makeRef(googleMaps, "https://upload.wikimedia.org/wikipedia/commons/a/aa/Google_Maps_icon_%282020%29.svg", METERS))
@ -443,7 +443,7 @@
while (n--) { while (n--) {
u8arr[n] = bstr.charCodeAt(n) u8arr[n] = bstr.charCodeAt(n)
} }
return new File([u8arr], filename, {type:mime}) return new File([u8arr], filename, { type: mime })
} }
function getHtmlElementByFileType(file) { function getHtmlElementByFileType(file) {
@ -474,14 +474,14 @@
let from = variant == "l" ? "history" : "legend" let from = variant == "l" ? "history" : "legend"
let to = variant == "l" ? "legend" : "history" let to = variant == "l" ? "legend" : "history"
let type = attachmentIndex == 1 ? "photo" : "files" let type = attachmentIndex == 1 ? "photo" : "files"
return [document.querySelector(`.${from}-${type}-container`), document.querySelector(`.${to}-${type}-container`)] return [document.querySelector(`.${from}-${type}-container`), document.querySelector(`.${to}-${type}-container`)]
} }
function makeHandleFilesFunc() { function makeHandleFilesFunc() {
let storedFiles = [] let storedFiles = []
return function() { return function () {
let dt = new DataTransfer() let dt = new DataTransfer()
if (storedFiles.length) { if (storedFiles.length) {
@ -532,16 +532,16 @@
let index = [...fileContainer.parentElement.children].indexOf(fileContainer) let index = [...fileContainer.parentElement.children].indexOf(fileContainer)
if (!confirm("Точно?")) return if (!confirm("Точно?")) return
storedFiles.splice(storedFiles.length - this.files.length + index, 1) storedFiles.splice(storedFiles.length - this.files.length + index, 1)
let rdt = new DataTransfer() let rdt = new DataTransfer()
for (const file of this.files) { for (const file of this.files) {
rdt.items.add(file) rdt.items.add(file)
} }
rdt.items.remove(index) rdt.items.remove(index)
this.files = rdt.files this.files = rdt.files
fileContainer.parentElement.removeChild(fileContainer) fileContainer.parentElement.removeChild(fileContainer)
}) })
fileButtonsContainer.appendChild(deleteButton) fileButtonsContainer.appendChild(deleteButton)
@ -556,7 +556,7 @@
displayedFile.src = e.target.result displayedFile.src = e.target.result
downloadLink.setAttribute("href", displayedFile.src) downloadLink.setAttribute("href", displayedFile.src)
storedFiles.push({data: displayedFile.src, name: file.name}) storedFiles.push({ data: displayedFile.src, name: file.name })
} }
reader.readAsDataURL(file) reader.readAsDataURL(file)
} }
@ -565,9 +565,9 @@
} }
} }
let prettifyFiles = (function() { let prettifyFiles = (function () {
var executed = false var executed = false
return function(insertedFileRows) { return function (insertedFileRows) {
if (executed) return if (executed) return
executed = true executed = true
@ -580,11 +580,11 @@
pseudoInput.setAttribute("for", element.id) pseudoInput.setAttribute("for", element.id)
pseudoInput.textContent = "+" pseudoInput.textContent = "+"
element.parentElement.insertBefore(pseudoInput, element) element.parentElement.insertBefore(pseudoInput, element)
let fileListContainer = document.createElement("div") let fileListContainer = document.createElement("div")
fileListContainer.classList.add("file-list-container") fileListContainer.classList.add("file-list-container")
element.parentElement.parentElement.appendChild(fileListContainer) element.parentElement.parentElement.appendChild(fileListContainer)
element.addEventListener("change", makeHandleFilesFunc(), false) element.addEventListener("change", makeHandleFilesFunc(), false)
}) })
@ -607,11 +607,11 @@
let toInputs = [...to.querySelectorAll("input, textarea")] let toInputs = [...to.querySelectorAll("input, textarea")]
for (const [fromEl, value] of values) { for (const [fromEl, value] of values) {
let currentToInput = toInputs.find(toEl => let currentToInput = toInputs.find(toEl =>
toEl.type !== 'file' && toEl.type !== 'file' &&
toEl.type === fromEl.type && toEl.type === fromEl.type &&
toEl.name === fromEl.name && toEl.name === fromEl.name &&
toEl.id === fromEl.id && toEl.id === fromEl.id &&
(toEl.type !== "radio" || toEl.value === fromEl.value) (toEl.type !== "radio" || toEl.value === fromEl.value)
) )
@ -666,9 +666,9 @@
} }
function moveNewFilesOnVariantChange() { function moveNewFilesOnVariantChange() {
document.querySelectorAll(`input[name^="new_file_type"]`).forEach(el => el.addEventListener("change", function() { document.querySelectorAll(`input[name^="new_file_type"]`).forEach(el => el.addEventListener("change", function () {
let attachmentIndex = getAttachmentIndex(this) let attachmentIndex = getAttachmentIndex(this)
let [from, to] = getContainersByVariant(this.value, attachmentIndex) let [from, to] = getContainersByVariant(this.value, attachmentIndex)
let newFiles = [...from.querySelectorAll(`.file-container-new`)] let newFiles = [...from.querySelectorAll(`.file-container-new`)]
for (const newFile of newFiles) { for (const newFile of newFiles) {
@ -693,7 +693,7 @@
function prettifyEditCpForm(form, was, became, insertedFileRows) { function prettifyEditCpForm(form, was, became, insertedFileRows) {
moveInputValues(form, was, became) moveInputValues(form, was, became)
prettifyFiles(insertedFileRows) prettifyFiles(insertedFileRows)
moveNewFilesOnVariantChange() moveNewFilesOnVariantChange()
$("#cps_main").select2() $("#cps_main").select2()
makeCoordinatesLinks() makeCoordinatesLinks()
@ -720,7 +720,7 @@
alwaysPrettifyCheckbox.type = "checkbox" alwaysPrettifyCheckbox.type = "checkbox"
alwaysPrettifyCheckbox.id = "always-prettify-" + index alwaysPrettifyCheckbox.id = "always-prettify-" + index
alwaysPrettifyCheckbox.name = "always-prettify-" + index alwaysPrettifyCheckbox.name = "always-prettify-" + index
alwaysPrettifyCheckbox.addEventListener("change", function() { alwaysPrettifyCheckbox.addEventListener("change", function () {
let otherCheckboxes = document.querySelectorAll(`input[name^="always-prettify-"]`) let otherCheckboxes = document.querySelectorAll(`input[name^="always-prettify-"]`)
for (let checkbox of otherCheckboxes) { for (let checkbox of otherCheckboxes) {
if (checkbox.id !== this.id) { if (checkbox.id !== this.id) {
@ -805,7 +805,7 @@
new Swiper('.swiper', { new Swiper('.swiper', {
initialSlide: files.findIndex(el => el.dataset.origin && el.dataset.origin === src || el.src === src), initialSlide: files.findIndex(el => el.dataset.origin && el.dataset.origin === src || el.src === src),
navigation: { navigation: {
nextEl: '.swiper-button-next', nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev', prevEl: '.swiper-button-prev',
@ -816,16 +816,16 @@
} }
function bindArrowsForGallery(leftButtonQuery, rightButtonQuery) { function bindArrowsForGallery(leftButtonQuery, rightButtonQuery) {
document.addEventListener("keydown", function(e) { document.addEventListener("keydown", function (e) {
if (!document.querySelector("dialog").open) return if (!document.querySelector("dialog").open) return
switch(e.key) { switch (e.key) {
case "ArrowLeft": case "ArrowLeft":
$(leftButtonQuery).click() $(leftButtonQuery).click()
break break
case "ArrowRight": case "ArrowRight":
$(rightButtonQuery).click() $(rightButtonQuery).click()
break break
default: return default: return
} }
@ -888,14 +888,14 @@
localStorage.setItem(localStorageItems.JUST_CREATED, cpNumber) localStorage.setItem(localStorageItems.JUST_CREATED, cpNumber)
localStorage.setItem(localStorageItems.LATTITUDE, lattitude) localStorage.setItem(localStorageItems.LATTITUDE, lattitude)
localStorage.setItem(localStorageItems.LONGITUDE, longitude) localStorage.setItem(localStorageItems.LONGITUDE, longitude)
document.querySelector(`input[name="save_go"]`).click() document.querySelector(`input[name="save_go"]`).click()
}) })
}) })
return saveAndNewButton return saveAndNewButton
} }
function createSendButtons() { function createSendButtons() {
if (document.querySelector(".pseudo-save")) return if (document.querySelector(".pseudo-save")) return
@ -917,7 +917,7 @@
if (saveButton.name == "save_exit") { if (saveButton.name == "save_exit") {
localStorage.setItem(localStorageItems.REDIRECT_EXIT, true) localStorage.setItem(localStorageItems.REDIRECT_EXIT, true)
} }
saveAndStayButtons[0].click() saveAndStayButtons[0].click()
})) }))
@ -933,7 +933,7 @@
let prevCreated = localStorage.getItem(localStorageItems.PREV_CREATED) let prevCreated = localStorage.getItem(localStorageItems.PREV_CREATED)
let needUpdateId = localStorage.getItem(localStorageItems.NEED_UPDATE_ID) let needUpdateId = localStorage.getItem(localStorageItems.NEED_UPDATE_ID)
let exit = localStorage.getItem(localStorageItems.REDIRECT_EXIT) let exit = localStorage.getItem(localStorageItems.REDIRECT_EXIT)
if (needUpdateId) { if (needUpdateId) {
let formData = new FormData() let formData = new FormData()
formData.set("cp[id]", urlParams().get("cp_id")) formData.set("cp[id]", urlParams().get("cp_id"))
@ -941,18 +941,18 @@
formData.set("update_id", true) formData.set("update_id", true)
updatePoint(formData).then(() => localStorage.removeItem(localStorageItems.NEED_UPDATE_ID)) updatePoint(formData).then(() => localStorage.removeItem(localStorageItems.NEED_UPDATE_ID))
} }
if (exit) { if (exit) {
localStorage.removeItem(localStorageItems.REDIRECT_EXIT) localStorage.removeItem(localStorageItems.REDIRECT_EXIT)
location.href = location.href.replace(location.search, '') location.href = location.href.replace(location.search, '')
return return
} }
if (justCreated !== null) { if (justCreated !== null) {
localStorage.setItem(localStorageItems.PREV_CREATED, justCreated) localStorage.setItem(localStorageItems.PREV_CREATED, justCreated)
localStorage.removeItem(localStorageItems.JUST_CREATED) localStorage.removeItem(localStorageItems.JUST_CREATED)
location.href = location.href.replace(location.search, "?action=edit") location.href = location.href.replace(location.search, "?action=edit")
return return
} }
@ -960,7 +960,7 @@
document.querySelector(`input[name="cp[number]"]`).value = parseInt(localStorage.getItem(localStorageItems.PREV_CREATED)) + 1 document.querySelector(`input[name="cp[number]"]`).value = parseInt(localStorage.getItem(localStorageItems.PREV_CREATED)) + 1
document.querySelector(`input[name="cp[lattitude]"]`).value = localStorage.getItem(localStorageItems.LATTITUDE) document.querySelector(`input[name="cp[lattitude]"]`).value = localStorage.getItem(localStorageItems.LATTITUDE)
document.querySelector(`input[name="cp[longitude]"]`).value = localStorage.getItem(localStorageItems.LONGITUDE) document.querySelector(`input[name="cp[longitude]"]`).value = localStorage.getItem(localStorageItems.LONGITUDE)
localStorage.removeItem(localStorageItems.PREV_CREATED) localStorage.removeItem(localStorageItems.PREV_CREATED)
localStorage.removeItem(localStorageItems.LATTITUDE) localStorage.removeItem(localStorageItems.LATTITUDE)
localStorage.removeItem(localStorageItems.LONGITUDE) localStorage.removeItem(localStorageItems.LONGITUDE)
@ -995,7 +995,7 @@
link.innerText = label link.innerText = label
if (blanks.includes(label)) { if (blanks.includes(label)) {
link.setAttribute("target", "_blank") link.setAttribute("target", "_blank")
} }
menuItem.appendChild(link) menuItem.appendChild(link)
@ -1017,14 +1017,14 @@
mainLinksFormatted[label] = `/${competition}/${href}` mainLinksFormatted[label] = `/${competition}/${href}`
} }
menuContainer.append(createMenuFromLinks(mainLinksFormatted, ["Легенда"])) menuContainer.append(createMenuFromLinks(mainLinksFormatted, ["Легенда"]))
let catId = urlParams().get("cat_id") let catId = urlParams().get("cat_id")
if (catId !== null) { if (catId !== null) {
let catLinksFormatted = {} let catLinksFormatted = {}
for (const [label, href] of Object.entries(catLinks)) { for (const [label, href] of Object.entries(catLinks)) {
catLinksFormatted[label] = href(catId) catLinksFormatted[label] = href(catId)
} }
menuContainer.append(createMenuFromLinks(catLinksFormatted)) menuContainer.append(createMenuFromLinks(catLinksFormatted))
} }
@ -1142,7 +1142,7 @@
function makeContainer() { function makeContainer() {
let container = document.createElement('div') let container = document.createElement('div')
container.id = "new" container.id = "new"
return container return container
} }
@ -1151,7 +1151,7 @@
{ index: 2, name: "№", desc: "" }, { index: 2, name: "№", desc: "" },
{ index: 8, name: "Название" } { index: 8, name: "Название" }
]) ])
let copyLink = document.createElement("div") let copyLink = document.createElement("div")
copyLink.innerHTML = new Property(rows[2]).desc copyLink.innerHTML = new Property(rows[2]).desc
headerContainer.append(copyLink) headerContainer.append(copyLink)
@ -1178,9 +1178,9 @@
let topButtonsContainer = createFrom(rows, "buttons", [ let topButtonsContainer = createFrom(rows, "buttons", [
{ index: 0 } { index: 0 }
]) ])
let bottomButtonsContainer = topButtonsContainer.cloneNode(true) let bottomButtonsContainer = topButtonsContainer.cloneNode(true)
document.querySelectorAll("#props tr:is(:first-child, :last-child) th").forEach((el, index) => { document.querySelectorAll("#props tr:is(:first-child, :last-child) th").forEach((el, index) => {
let rowContentWrapper = document.createElement("div") let rowContentWrapper = document.createElement("div")
rowContentWrapper.classList.add("buttons-row__content-wrapper") rowContentWrapper.classList.add("buttons-row__content-wrapper")
@ -1188,20 +1188,20 @@
let child = el.firstChild let child = el.firstChild
rowContentWrapper.appendChild(child) rowContentWrapper.appendChild(child)
} }
let prettifyButton = document.createElement("button") let prettifyButton = document.createElement("button")
prettifyButton.type = "button" prettifyButton.type = "button"
prettifyButton.textContent = "Сделать красиво" prettifyButton.textContent = "Сделать красиво"
prettifyButton.addEventListener("click", () => { prettifyButton.addEventListener("click", () => {
prettifyEditCpForm(form, oldTable, container, insertedFileRows) prettifyEditCpForm(form, oldTable, container, insertedFileRows)
}) })
rowContentWrapper.appendChild(prettifyButton) rowContentWrapper.appendChild(prettifyButton)
rowContentWrapper.appendChild(createAlwaysPrettifyInput(index)) rowContentWrapper.appendChild(createAlwaysPrettifyInput(index))
el.appendChild(rowContentWrapper) el.appendChild(rowContentWrapper)
}) })
;[topButtonsContainer, bottomButtonsContainer].forEach((el, index) => { ;[topButtonsContainer, bottomButtonsContainer].forEach((el, index) => {
let unglifyButton = document.createElement("button") let unglifyButton = document.createElement("button")
unglifyButton.type = "button" unglifyButton.type = "button"
@ -1209,7 +1209,7 @@
unglifyButton.addEventListener("click", () => { unglifyButton.addEventListener("click", () => {
uglifyEditCpForm(form, container, oldTable) uglifyEditCpForm(form, container, oldTable)
}) })
let topRowContentWrapper = el.querySelector("div > div > div") let topRowContentWrapper = el.querySelector("div > div > div")
topRowContentWrapper.appendChild(unglifyButton) topRowContentWrapper.appendChild(unglifyButton)
topRowContentWrapper.appendChild(createAlwaysPrettifyInput(index)) topRowContentWrapper.appendChild(createAlwaysPrettifyInput(index))
@ -1244,23 +1244,23 @@
function makeLegend(rows) { function makeLegend(rows) {
let legendContainer = document.createElement("div") let legendContainer = document.createElement("div")
legendContainer.classList.add("legend-container") legendContainer.classList.add("legend-container")
/* LEGEND DESC */ /* LEGEND DESC */
let legendDescContainer = document.createElement("div") let legendDescContainer = document.createElement("div")
legendDescContainer.classList.add("legend-container__desc") legendDescContainer.classList.add("legend-container__desc")
let legendDescHeader = document.createElement("div") let legendDescHeader = document.createElement("div")
legendDescHeader.classList.add("legend-container__desc-header") legendDescHeader.classList.add("legend-container__desc-header")
const LEGEND_RU_LABEL = "Русский" const LEGEND_RU_LABEL = "Русский"
const LEGEND_EN_LABEL = "Английский" const LEGEND_EN_LABEL = "Английский"
let legendLang = document.createElement("div") let legendLang = document.createElement("div")
legendLang.classList.add("legend-desc__lang") legendLang.classList.add("legend-desc__lang")
legendLang.textContent = LEGEND_RU_LABEL legendLang.textContent = LEGEND_RU_LABEL
legendDescHeader.appendChild(legendLang) legendDescHeader.appendChild(legendLang)
let legendEnSwitchContainer = createFrom(rows, "legend-switch-container", [ let legendEnSwitchContainer = createFrom(rows, "legend-switch-container", [
{ index: 48 } { index: 48 }
]) ])
@ -1280,7 +1280,7 @@
enInput.value = ruInputs[i].value enInput.value = ruInputs[i].value
} }
}) })
let legendRuSwitchContainer = createFrom(rows, "legend-switch-container hidden", [ let legendRuSwitchContainer = createFrom(rows, "legend-switch-container hidden", [
{ index: 39 } { index: 39 }
]) ])
@ -1290,37 +1290,37 @@
legendLang.textContent = LEGEND_RU_LABEL legendLang.textContent = LEGEND_RU_LABEL
}) })
legendDescHeader.appendChild(legendRuSwitchContainer) legendDescHeader.appendChild(legendRuSwitchContainer)
legendDescHeader.appendChild(copyDescButton) legendDescHeader.appendChild(copyDescButton)
let legendRuDescContainer = createFrom(rows, "legend-desc", [ let legendRuDescContainer = createFrom(rows, "legend-desc", [
{ index: 40, desc: "" }, { index: 40, desc: "" },
{ index: 41, desc: "" }, { index: 41, desc: "" },
{ index: 42, desc: "" }, { index: 42, desc: "" },
{ index: 43, desc: "" } { index: 43, desc: "" }
]) ])
let legendRuHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed", [ let legendRuHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed", [
{ index: 44, desc: "" }, { index: 44, desc: "" },
{ index: 45, desc: "" }, { index: 45, desc: "" },
{ index: 46, desc: "" }, { index: 46, desc: "" },
{ index: 47, desc: "" }, { index: 47, desc: "" },
]) ])
let legendEnDescContainer = createFrom(rows, "legend-desc hidden", [ let legendEnDescContainer = createFrom(rows, "legend-desc hidden", [
{ index: 49, desc: "" }, { index: 49, desc: "" },
{ index: 50, desc: "" }, { index: 50, desc: "" },
{ index: 51, desc: "" }, { index: 51, desc: "" },
{ index: 52, desc: "" } { index: 52, desc: "" }
]) ])
let legendEnHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed hidden", [ let legendEnHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed hidden", [
{ index: 53, desc: "" }, { index: 53, desc: "" },
{ index: 54, desc: "" }, { index: 54, desc: "" },
{ index: 55, desc: "" }, { index: 55, desc: "" },
{ index: 56, desc: "" } { index: 56, desc: "" }
]) ])
let hider = document.createElement("div") let hider = document.createElement("div")
let hiderButton = document.createElement("button") let hiderButton = document.createElement("button")
hiderButton.classList.add("collapse-button") hiderButton.classList.add("collapse-button")
@ -1332,7 +1332,7 @@
}) })
}) })
hider.appendChild(hiderButton) hider.appendChild(hiderButton)
legendDescContainer.appendChild(legendDescHeader) legendDescContainer.appendChild(legendDescHeader)
legendDescContainer.appendChild(legendRuDescContainer) legendDescContainer.appendChild(legendRuDescContainer)
legendDescContainer.appendChild(legendRuHiddenDescContainer) legendDescContainer.appendChild(legendRuHiddenDescContainer)
@ -1352,22 +1352,22 @@
function makeLegendFiles(rows) { function makeLegendFiles(rows) {
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 legend-photo-container", [
{ index: 23, name: "Фото в легенде" } { index: 23, name: "Фото в легенде" }
]) ])
legendFilesContainer.appendChild(imagesForLegendContainer) legendFilesContainer.appendChild(imagesForLegendContainer)
let imagesForHistoryContainer = createFrom(rows, "files-container history-photo-container", [ let imagesForHistoryContainer = createFrom(rows, "files-container history-photo-container", [
{ name: "Фото для ИС" } { name: "Фото для ИС" }
]) ])
legendFilesContainer.appendChild(imagesForHistoryContainer) legendFilesContainer.appendChild(imagesForHistoryContainer)
let audioForLegendContainer = createFrom(rows, "files-container legend-files-container", [ let audioForLegendContainer = createFrom(rows, "files-container legend-files-container", [
{ index: 27, name: "Файлы в легенде" } { index: 27, name: "Файлы в легенде" }
]) ])
legendFilesContainer.appendChild(audioForLegendContainer) legendFilesContainer.appendChild(audioForLegendContainer)
let audioForHistoryContainer = createFrom(rows, "files-container history-files-container", [ let audioForHistoryContainer = createFrom(rows, "files-container history-files-container", [
{ name: "Файлы для ИС" } { name: "Файлы для ИС" }
]) ])
@ -1404,13 +1404,13 @@
let dialog = document.createElement("dialog") let dialog = document.createElement("dialog")
dialog.id = "dialog" dialog.id = "dialog"
document.body.appendChild(dialog) document.body.appendChild(dialog)
dialog.addEventListener("click", e => { dialog.addEventListener("click", e => {
if (e.target == dialog) { if (e.target == dialog) {
e.target.close() e.target.close()
} }
}) })
dialog.addEventListener("close", e => { dialog.addEventListener("close", e => {
e.target.innerHTML = "" e.target.innerHTML = ""
}) })
@ -1424,7 +1424,7 @@
contentWrapper.appendChild(document.querySelector("form")) contentWrapper.appendChild(document.querySelector("form"))
contentWrapper.appendChild(document.querySelector("#map-wrapper")) contentWrapper.appendChild(document.querySelector("#map-wrapper"))
content.appendChild(contentWrapper) content.appendChild(contentWrapper)
let panToCenter = document.createElement("button") let panToCenter = document.createElement("button")
panToCenter.type = "button" panToCenter.type = "button"
panToCenter.textContent = "В центр" panToCenter.textContent = "В центр"
@ -1826,17 +1826,17 @@
formatMap() formatMap()
/* DIALOG */ /* DIALOG */
makeDialog() makeDialog()
/* PRETTIFY CHECKBOX */ /* PRETTIFY CHECKBOX */
checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows) checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows)
} }
function isAllPointsSouthOfLat(lat) { function isAllPointsSouthOfLat(lat) {
map.eachLayer(function(layer) { map.eachLayer(function (layer) {
if (layer instanceof L.Marker) { if (layer instanceof L.Marker) {
let latLng = layer.getLatLng() let latLng = layer.getLatLng()
if (latLng.lat > lat) { if (latLng.lat > lat) {
return false return false
@ -1849,7 +1849,7 @@
if (map !== undefined && L !== undefined) { if (map !== undefined && L !== undefined) {
let coords = mapsCenterByCompetition[getCompetition()] let coords = mapsCenterByCompetition[getCompetition()]
if (coords == null) return if (coords == null) return
if (isAllPointsSouthOfLat(lat)) { if (isAllPointsSouthOfLat(lat)) {
map.setView(new L.LatLng(coords.ifSouthern.lat, coords.ifSouthern.lon), 13) map.setView(new L.LatLng(coords.ifSouthern.lat, coords.ifSouthern.lon), 13)
} }
@ -1859,7 +1859,7 @@
} }
} }
function prettifyRouteBuildPage() { function changeColumnWidthForRouteBuildPage() {
let styles = ` let styles = `
#content table table { #content table table {
td:nth-child(2) { td:nth-child(2) {
@ -1884,14 +1884,25 @@
} }
` `
addStylesToHead(styles) addStylesToHead(styles)
}
function hideDescriptionFromRouteBuildPage() {
document.querySelectorAll(`#content > form > table > tbody > tr:is(:nth-child(3), :nth-child(6)) `).forEach(el => el.remove()) document.querySelectorAll(`#content > form > table > tbody > tr:is(:nth-child(3), :nth-child(6)) `).forEach(el => el.remove())
}
function hideStartRowFromRouteBuildPage() {
document.querySelector(`#content table table tr:nth-child(2) `).remove() document.querySelector(`#content table table tr:nth-child(2) `).remove()
} }
function prettifyRouteBuildPage() {
changeColumnWidthForRouteBuildPage()
hideDescriptionFromRouteBuildPage()
hideStartRowFromRouteBuildPage()
}
function matchNumberFromSelect(select) { function matchNumberFromSelect(select) {
return [...document.querySelector(select).options].reduce( return [...document.querySelector(select).options].reduce(
(res, el) => ({ ...res, [el.textContent.match(/(?<=^\s*#)\d+/g)?.[0]]: el.value }), (res, el) => ({ ...res, [el.textContent.match(/(?<=^\s*#)\d+/g)?.[0]]: el.value }),
{} {}
) )
} }
@ -1904,13 +1915,7 @@
document.querySelector(`${select} option:last-child`).scrollIntoView() document.querySelector(`${select} option:last-child`).scrollIntoView()
} }
function prettifyRouteEditPage() { function createPointsInpitForRouteEditPage() {
document.querySelectorAll(`textarea:is([name="track[comment_int]"], [name="track[comment_ext]"])`).forEach(el => {
el.rows = 1
})
document.querySelectorAll(`table tr:is(:nth-child(3), :nth-child(4), :nth-child(5))`).forEach(el => el.classList.add("hidden"))
let addPointsContainer = document.createElement("div") let addPointsContainer = document.createElement("div")
let pointInput = document.createElement("input") let pointInput = document.createElement("input")
@ -1950,7 +1955,7 @@
option.selected = false option.selected = false
scrollSelectToBottom("#cps_in") scrollSelectToBottom("#cps_in")
}) })
let removeButton = document.createElement("button") let removeButton = document.createElement("button")
removeButton.type = "button" removeButton.type = "button"
removeButton.textContent = "Убрать" removeButton.textContent = "Убрать"
@ -2001,6 +2006,16 @@
`) `)
} }
function prettifyRouteEditPage() {
document.querySelectorAll(`textarea:is([name="track[comment_int]"], [name="track[comment_ext]"])`).forEach(el => {
el.rows = 1
})
document.querySelectorAll(`table tr:is(:nth-child(3), :nth-child(4), :nth-child(5))`).forEach(el => el.classList.add("hidden"))
createPointsInpitForRouteEditPage()
}
function toggleStagePageRows(rows) { function toggleStagePageRows(rows) {
let showIndex = [0, 3] let showIndex = [0, 3]
let to = rows.findIndex(el => el.querySelector("th")?.textContent.trim() == "Бонусы") let to = rows.findIndex(el => el.querySelector("th")?.textContent.trim() == "Бонусы")
@ -2011,7 +2026,7 @@
toggleRows(rows, to, rows.length, 1, []) toggleRows(rows, to, rows.length, 1, [])
} }
function prettifyRouteStagesPage() { function hideUselessRowsFromRouteStagesPage() {
let styles = ` let styles = `
tr.collapsed { tr.collapsed {
display: block; display: block;
@ -2126,7 +2141,7 @@
pretty = false pretty = false
location.reload() location.reload()
}) })
header.querySelector("#enable-button").after(disableButton) header.querySelector("#enable-button").after(disableButton)
} }
@ -2143,7 +2158,7 @@
alwaysEnableCheckbox.type = "checkbox" alwaysEnableCheckbox.type = "checkbox"
alwaysEnableCheckbox.id = "always-enable" alwaysEnableCheckbox.id = "always-enable"
alwaysEnableCheckbox.name = "always-enable" alwaysEnableCheckbox.name = "always-enable"
alwaysEnableCheckbox.addEventListener("change", function() { alwaysEnableCheckbox.addEventListener("change", function () {
if (this.checked) if (this.checked)
removeDisabledPage() removeDisabledPage()
else else
@ -2161,7 +2176,7 @@
function prettify() { function prettify() {
if (pretty) return if (pretty) return
pretty = true pretty = true
addDisableButton() addDisableButton()
@ -2169,18 +2184,18 @@
addCommonStyles() addCommonStyles()
/* SWITCH FOR DIFFERENT PAGES */ /* SWITCH FOR DIFFERENT PAGES */
addStickyMenu() addStickyMenu()
if (isCpEditPage()) { if (isCpEditPage()) {
prettifyEditCpPage() prettifyEditCpPage()
} }
if (isRouteListPage()) { if (isRouteListPage()) {
addStageLink() addStageLink()
hideNonTesters() hideNonTesters()
} }
if (isRouteBuildPage()) { if (isRouteBuildPage()) {
prettifyRouteBuildPage() prettifyRouteBuildPage()
} }
@ -2188,15 +2203,15 @@
if (isRouteEditPage()) { if (isRouteEditPage()) {
prettifyRouteEditPage() prettifyRouteEditPage()
} }
if (isRouteStagesPage()) { if (isRouteStagesPage()) {
prettifyRouteStagesPage() hideUselessRowsFromRouteStagesPage()
} }
} }
function prettifyIfEnabled() { function prettifyIfEnabled() {
if (isPageDisabled()) return if (isPageDisabled()) return
prettify() prettify()
} }
@ -2214,11 +2229,11 @@
bindDeleteButton() bindDeleteButton()
return return
} }
prettifyIfEnabled() prettifyIfEnabled()
/* MAPS */ /* MAPS */
addClearBoth() addClearBoth()
if (hasMap()) { if (hasMap()) {