separate functions
This commit is contained in:
parent
047c1046c2
commit
52bcc73b25
803
main.js
803
main.js
@ -136,6 +136,12 @@
|
||||
document.head.appendChild(script)
|
||||
}
|
||||
|
||||
function addStylesToHead(styles) {
|
||||
let styleSheet = document.createElement("style")
|
||||
styleSheet.textContent = styles
|
||||
document.head.appendChild(styleSheet)
|
||||
}
|
||||
|
||||
const sleep = ms => new Promise(res => setTimeout(res, ms));
|
||||
|
||||
function isEditCpPage() {
|
||||
@ -642,8 +648,6 @@
|
||||
|
||||
alwaysPrettify.appendChild(alwaysPrettifyCheckbox)
|
||||
|
||||
i++
|
||||
|
||||
return alwaysPrettify
|
||||
}
|
||||
|
||||
@ -820,6 +824,45 @@
|
||||
saveAndStayButtons.forEach(el => el.after(createSaveAndNewButton()))
|
||||
}
|
||||
|
||||
function redirectIfNeeded() {
|
||||
let justCreated = localStorage.getItem(localStorageItems.JUST_CREATED)
|
||||
let prevCreated = localStorage.getItem(localStorageItems.PREV_CREATED)
|
||||
let needUpdateId = localStorage.getItem(localStorageItems.NEED_UPDATE_ID)
|
||||
let exit = localStorage.getItem(localStorageItems.REDIRECT_EXIT)
|
||||
|
||||
if (needUpdateId) {
|
||||
let formData = new FormData()
|
||||
formData.set("cp[id]", new URLSearchParams(document.location.search).get("cp_id"))
|
||||
formData.set("cp[number]", document.querySelector(`input[name="cp[number]"]`).value)
|
||||
formData.set("update_id", true)
|
||||
updatePoint(formData).then(() => localStorage.removeItem(localStorageItems.NEED_UPDATE_ID))
|
||||
}
|
||||
|
||||
if (exit) {
|
||||
localStorage.removeItem(localStorageItems.REDIRECT_EXIT)
|
||||
|
||||
location.href = location.href.replace(location.search, '')
|
||||
return
|
||||
}
|
||||
|
||||
if (justCreated !== null) {
|
||||
localStorage.setItem(localStorageItems.PREV_CREATED, justCreated)
|
||||
localStorage.removeItem(localStorageItems.JUST_CREATED)
|
||||
|
||||
location.href = location.href.replace(location.search, "?action=edit")
|
||||
return
|
||||
}
|
||||
if (prevCreated !== null) {
|
||||
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[longitude]"]`).value = localStorage.getItem(localStorageItems.LONGITUDE)
|
||||
|
||||
localStorage.removeItem(localStorageItems.PREV_CREATED)
|
||||
localStorage.removeItem(localStorageItems.LATTITUDE)
|
||||
localStorage.removeItem(localStorageItems.LONGITUDE)
|
||||
}
|
||||
}
|
||||
|
||||
function addUglyDeleteListener() {
|
||||
let links = [...document.querySelectorAll("a[href*='del_stored']")]
|
||||
|
||||
@ -859,6 +902,394 @@
|
||||
})
|
||||
}
|
||||
|
||||
function getRows() {
|
||||
return [...document.querySelectorAll('#props > tbody > tr')]
|
||||
}
|
||||
|
||||
function getInsertedFileRows(rows) {
|
||||
let insertedFileRows = new Map()
|
||||
let i = 0
|
||||
while (i < rows.length) {
|
||||
if ([23, 27, 31, 35].includes(i) && rows[i].querySelector(`input[type="file"]`) == null) {
|
||||
if (!insertedFileRows.has(i)) {
|
||||
insertedFileRows.set(i, [rows[i]])
|
||||
}
|
||||
else {
|
||||
let savedRows = insertedFileRows.get(i)
|
||||
savedRows.push(rows[i])
|
||||
insertedFileRows.set(i, savedRows)
|
||||
}
|
||||
rows.splice(i, 1)
|
||||
}
|
||||
else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
return insertedFileRows
|
||||
}
|
||||
|
||||
function makeContainer() {
|
||||
let container = document.createElement('div')
|
||||
container.id = "new"
|
||||
|
||||
return container
|
||||
}
|
||||
|
||||
function makeHeader(rows) {
|
||||
let headerContainer = createFrom(rows, "header", [
|
||||
{ index: 2, name: "№", desc: "" },
|
||||
{ index: 8, name: "Название" }
|
||||
])
|
||||
|
||||
let copyLink = document.createElement("div")
|
||||
copyLink.innerHTML = new Property(rows[2]).desc
|
||||
headerContainer.append(copyLink)
|
||||
|
||||
return headerContainer
|
||||
}
|
||||
|
||||
function bindDeleteButton() {
|
||||
let deleteButton = document.querySelector(`input[name="delete_go"]`)
|
||||
let pseudoDeleteButton = document.createElement("button")
|
||||
pseudoDeleteButton.type = "button"
|
||||
pseudoDeleteButton.textContent = deleteButton.value
|
||||
pseudoDeleteButton.classList.add("unsafe-action", "pseudo-save")
|
||||
pseudoDeleteButton.addEventListener("click", async () => {
|
||||
await deletePoint()
|
||||
deleteButton.click()
|
||||
})
|
||||
|
||||
deleteButton.style.display = "none"
|
||||
deleteButton.parentElement.insertBefore(pseudoDeleteButton, deleteButton)
|
||||
}
|
||||
|
||||
function makeTopAndBottomButtons(rows, form, oldTable, container, insertedFileRows) {
|
||||
let topButtonsContainer = createFrom(rows, "buttons", [
|
||||
{ index: 0 }
|
||||
])
|
||||
|
||||
let bottomButtonsContainer = topButtonsContainer.cloneNode(true)
|
||||
|
||||
document.querySelectorAll("#props tr:is(:first-child, :last-child) th").forEach((el, index) => {
|
||||
let rowContentWrapper = document.createElement("div")
|
||||
rowContentWrapper.classList.add("buttons-row__content-wrapper")
|
||||
while ([...el.children].length > 0) {
|
||||
let child = el.firstChild
|
||||
rowContentWrapper.appendChild(child)
|
||||
}
|
||||
|
||||
let prettifyButton = document.createElement("button")
|
||||
prettifyButton.type = "button"
|
||||
prettifyButton.textContent = "Сделать красиво"
|
||||
prettifyButton.addEventListener("click", () => {
|
||||
prettify(form, oldTable, container, insertedFileRows)
|
||||
})
|
||||
|
||||
rowContentWrapper.appendChild(prettifyButton)
|
||||
rowContentWrapper.appendChild(createAlwaysPrettifyInput(index))
|
||||
|
||||
el.appendChild(rowContentWrapper)
|
||||
})
|
||||
|
||||
;[topButtonsContainer, bottomButtonsContainer].forEach((el, index) => {
|
||||
let unglifyButton = document.createElement("button")
|
||||
unglifyButton.type = "button"
|
||||
unglifyButton.textContent = "Сделать некрасиво"
|
||||
unglifyButton.addEventListener("click", () => {
|
||||
uglify(form, container, oldTable)
|
||||
})
|
||||
|
||||
let topRowContentWrapper = el.querySelector("div > div > div")
|
||||
topRowContentWrapper.appendChild(unglifyButton)
|
||||
topRowContentWrapper.appendChild(createAlwaysPrettifyInput(index))
|
||||
})
|
||||
|
||||
return [topButtonsContainer, bottomButtonsContainer]
|
||||
}
|
||||
|
||||
function makeTopOptions(rows) {
|
||||
return createFrom(rows, "options", [
|
||||
{ index: 3 },
|
||||
{ index: 4, name: "КП-загадка" },
|
||||
{ index: 16, name: "Этапник" },
|
||||
{ index: 7, name: "Пиктограмма" },
|
||||
{ index: 12, name: "Нужна ИС" },
|
||||
{ index: 17, name: "Спрятать ИС" },
|
||||
{ index: 14, name: "Основной КП" },
|
||||
{ index: 10, name: "Широта" },
|
||||
{ index: 11, name: "Долгота" },
|
||||
{ index: 5, name: "Старт" },
|
||||
{ index: 6, name: "Финиш" },
|
||||
{ index: 15, name: "Знак" }
|
||||
])
|
||||
}
|
||||
|
||||
function makeComment(rows) {
|
||||
return createFrom(rows, "comment", [
|
||||
{ index: 9, desc: "" }
|
||||
])
|
||||
}
|
||||
|
||||
function makeLegend(rows) {
|
||||
let legendContainer = document.createElement("div")
|
||||
legendContainer.classList.add("legend-container")
|
||||
|
||||
/* LEGEND DESC */
|
||||
|
||||
let legendDescContainer = document.createElement("div")
|
||||
legendDescContainer.classList.add("legend-container__desc")
|
||||
|
||||
let legendDescHeader = document.createElement("div")
|
||||
legendDescHeader.classList.add("legend-container__desc-header")
|
||||
|
||||
|
||||
const LEGEND_RU_LABEL = "Русский"
|
||||
const LEGEND_EN_LABEL = "Английский"
|
||||
let legendLang = document.createElement("div")
|
||||
legendLang.classList.add("legend-desc__lang")
|
||||
legendLang.textContent = LEGEND_RU_LABEL
|
||||
legendDescHeader.appendChild(legendLang)
|
||||
|
||||
let legendEnSwitchContainer = createFrom(rows, "legend-switch-container", [
|
||||
{ index: 48 }
|
||||
])
|
||||
legendEnSwitchContainer.addEventListener("click", event => {
|
||||
hide([legendRuDescContainer, legendRuHiddenDescContainer, legendEnSwitchContainer])
|
||||
show([legendEnDescContainer, legendEnHiddenDescContainer, legendRuSwitchContainer])
|
||||
legendLang.textContent = LEGEND_EN_LABEL
|
||||
})
|
||||
legendDescHeader.appendChild(legendEnSwitchContainer)
|
||||
let copyDescButton = document.createElement("button")
|
||||
copyDescButton.type = "button"
|
||||
copyDescButton.textContent = "Копировать"
|
||||
copyDescButton.addEventListener("click", () => {
|
||||
let ruInputs = [...container.querySelectorAll(":is(input, textarea)[name^=\"cp_strings\[ru\]\"]")]
|
||||
let enInputs = [...container.querySelectorAll(":is(input, textarea)[name^=\"cp_strings\[en\]\"]")]
|
||||
for (const [i, enInput] of enInputs.entries()) {
|
||||
enInput.value = ruInputs[i].value
|
||||
}
|
||||
})
|
||||
|
||||
let legendRuSwitchContainer = createFrom(rows, "legend-switch-container hidden", [
|
||||
{ index: 39 }
|
||||
])
|
||||
legendRuSwitchContainer.addEventListener("click", event => {
|
||||
hide([legendEnDescContainer, legendEnHiddenDescContainer, legendRuSwitchContainer])
|
||||
show([legendRuDescContainer, legendRuHiddenDescContainer, legendEnSwitchContainer])
|
||||
legendLang.textContent = LEGEND_RU_LABEL
|
||||
})
|
||||
legendDescHeader.appendChild(legendRuSwitchContainer)
|
||||
|
||||
legendDescHeader.appendChild(copyDescButton)
|
||||
|
||||
let legendRuDescContainer = createFrom(rows, "legend-desc", [
|
||||
{ index: 40, desc: "" },
|
||||
{ index: 41, desc: "" },
|
||||
{ index: 42, desc: "" },
|
||||
{ index: 43, desc: "" }
|
||||
])
|
||||
|
||||
let legendRuHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed", [
|
||||
{ index: 44, desc: "" },
|
||||
{ index: 45, desc: "" },
|
||||
{ index: 46, desc: "" },
|
||||
{ index: 47, desc: "" },
|
||||
])
|
||||
|
||||
let legendEnDescContainer = createFrom(rows, "legend-desc hidden", [
|
||||
{ index: 49, desc: "" },
|
||||
{ index: 50, desc: "" },
|
||||
{ index: 51, desc: "" },
|
||||
{ index: 52, desc: "" }
|
||||
])
|
||||
|
||||
let legendEnHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed hidden", [
|
||||
{ index: 53, desc: "" },
|
||||
{ index: 54, desc: "" },
|
||||
{ index: 55, desc: "" },
|
||||
{ index: 56, desc: "" }
|
||||
])
|
||||
|
||||
let hider = document.createElement("div")
|
||||
let hiderButton = document.createElement("button")
|
||||
hiderButton.classList.add("collapse-button")
|
||||
hiderButton.setAttribute("type", "button")
|
||||
hiderButton.addEventListener("click", event => {
|
||||
container.querySelectorAll(".legend-desc.collapsible").forEach(element => {
|
||||
element.classList.toggle("collapsed")
|
||||
})
|
||||
})
|
||||
hider.appendChild(hiderButton)
|
||||
|
||||
legendDescContainer.appendChild(legendDescHeader)
|
||||
legendDescContainer.appendChild(legendRuDescContainer)
|
||||
legendDescContainer.appendChild(legendRuHiddenDescContainer)
|
||||
legendDescContainer.appendChild(legendEnDescContainer)
|
||||
legendDescContainer.appendChild(legendEnHiddenDescContainer)
|
||||
legendDescContainer.appendChild(hider)
|
||||
legendContainer.appendChild(legendDescContainer)
|
||||
|
||||
return legendContainer
|
||||
}
|
||||
|
||||
function chooseLegendAsDefaultVariant() {
|
||||
document.querySelector(`#props input[name="new_file_type1"][value="l"]`).click()
|
||||
document.querySelector(`#props input[name="new_file_type4"][value="l"]`).click()
|
||||
}
|
||||
|
||||
function makeLegendFiles(rows) {
|
||||
let legendFilesContainer = document.createElement("div")
|
||||
legendFilesContainer.classList.add("legend-container__files")
|
||||
|
||||
let imagesForLegendContainer = createFrom(rows, "files-container legend-photo-container", [
|
||||
{ index: 23, name: "Фото в легенде" }
|
||||
])
|
||||
legendFilesContainer.appendChild(imagesForLegendContainer)
|
||||
|
||||
let imagesForHistoryContainer = createFrom(rows, "files-container history-photo-container", [
|
||||
{ name: "Фото для ИС" }
|
||||
])
|
||||
legendFilesContainer.appendChild(imagesForHistoryContainer)
|
||||
|
||||
let audioForLegendContainer = createFrom(rows, "files-container legend-files-container", [
|
||||
{ index: 27, name: "Файлы в легенде" }
|
||||
])
|
||||
legendFilesContainer.appendChild(audioForLegendContainer)
|
||||
|
||||
let audioForHistoryContainer = createFrom(rows, "files-container history-files-container", [
|
||||
{ name: "Файлы для ИС" }
|
||||
])
|
||||
legendFilesContainer.appendChild(audioForHistoryContainer)
|
||||
|
||||
return legendFilesContainer
|
||||
}
|
||||
|
||||
function makeAdminFiles(rows) {
|
||||
let adminFilesContainer = document.createElement('div')
|
||||
adminFilesContainer.classList.add('admin-files-container')
|
||||
|
||||
let imagesForAdminContainer = createFrom(rows, "files-container admin-photo-container", [
|
||||
{ index: 31, name: "Фото в админке" }
|
||||
])
|
||||
adminFilesContainer.appendChild(imagesForAdminContainer)
|
||||
|
||||
let audioForAdminContainer = createFrom(rows, "files-container admin-files-container", [
|
||||
{ index: 35, name: "Файлы в админке" }
|
||||
])
|
||||
adminFilesContainer.appendChild(audioForAdminContainer)
|
||||
|
||||
return adminFilesContainer
|
||||
}
|
||||
|
||||
function makeBottomOptions(rows) {
|
||||
return createFromMulti(rows, "options bottom-options", {
|
||||
from: 59,
|
||||
to: rows.length - 3
|
||||
})
|
||||
}
|
||||
|
||||
function makeDialog() {
|
||||
let dialog = document.createElement("dialog")
|
||||
dialog.id = "dialog"
|
||||
document.body.appendChild(dialog)
|
||||
|
||||
dialog.addEventListener("click", e => {
|
||||
if (e.target == dialog) {
|
||||
e.target.close()
|
||||
}
|
||||
})
|
||||
|
||||
dialog.addEventListener("close", e => {
|
||||
e.target.innerHTML = ""
|
||||
})
|
||||
}
|
||||
|
||||
function formatMap() {
|
||||
if (map !== undefined && L !== undefined) {
|
||||
let content = document.querySelector("#content")
|
||||
let contentWrapper = document.createElement("div")
|
||||
contentWrapper.id = "content-wrapper"
|
||||
contentWrapper.appendChild(document.querySelector("form"))
|
||||
contentWrapper.appendChild(document.querySelector("#map-wrapper"))
|
||||
content.appendChild(contentWrapper)
|
||||
|
||||
let panToCenter = document.createElement("button")
|
||||
panToCenter.type = "button"
|
||||
panToCenter.textContent = "В центр"
|
||||
panToCenter.addEventListener("click", () => {
|
||||
let lat = document.querySelector("input[name=\"cp\[lattitude\]\"").value
|
||||
let lon = document.querySelector("input[name=\"cp\[longitude\]\"").value
|
||||
map.setView(new L.LatLng(parseFloat(lat), parseFloat(lon)), 16)
|
||||
})
|
||||
document.querySelector("#map_controls").appendChild(panToCenter)
|
||||
}
|
||||
}
|
||||
|
||||
function checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows) {
|
||||
if (localStorage.getItem(localStorageItems.ALWAYS_PRETTIFY)) {
|
||||
document.querySelector(`input[name^="always-prettify-0"]`).click()
|
||||
prettify(form, oldTable, container, insertedFileRows)
|
||||
}
|
||||
}
|
||||
|
||||
function prettifyEditCpPage() {
|
||||
addCss("https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css")
|
||||
addCss("https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css")
|
||||
|
||||
/* NEW DEFALUT VALUES */
|
||||
|
||||
chooseLegendAsDefaultVariant()
|
||||
|
||||
/* CONTAINER */
|
||||
|
||||
let form = document.querySelector('form')
|
||||
let rows = getRows()
|
||||
let insertedFileRows = getInsertedFileRows(rows)
|
||||
|
||||
let container = makeContainer()
|
||||
let oldTable = document.querySelector("#props")
|
||||
|
||||
/* HEADER */
|
||||
|
||||
let headerContainer = makeHeader(rows)
|
||||
|
||||
/* TOP BUTTONS */
|
||||
|
||||
let [topButtonsContainer, bottomButtonsContainer] = makeTopAndBottomButtons(rows, form, oldTable, container, insertedFileRows)
|
||||
|
||||
addUglyDeleteListener()
|
||||
createSendButtons()
|
||||
|
||||
/* LEGEND */
|
||||
|
||||
let legendContainer = makeLegend(rows)
|
||||
legendContainer.appendChild(makeLegendFiles(rows))
|
||||
|
||||
/* APPEND ALL */
|
||||
|
||||
container.appendChild(topButtonsContainer)
|
||||
container.appendChild(headerContainer)
|
||||
container.appendChild(makeTopOptions(rows))
|
||||
container.appendChild(makeComment(rows))
|
||||
container.appendChild(legendContainer)
|
||||
container.appendChild(makeAdminFiles(rows))
|
||||
container.appendChild(makeBottomOptions(rows))
|
||||
container.appendChild(bottomButtonsContainer)
|
||||
|
||||
/* MAP */
|
||||
|
||||
formatMap()
|
||||
|
||||
/* DIALOG */
|
||||
|
||||
makeDialog()
|
||||
|
||||
/* PRETTIFY CHECKBOX */
|
||||
|
||||
checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows)
|
||||
}
|
||||
|
||||
let styles = `
|
||||
#props caption {
|
||||
position: sticky;
|
||||
@ -1200,64 +1631,16 @@
|
||||
|
||||
/* REDIRECTS */
|
||||
|
||||
let justCreated = localStorage.getItem(localStorageItems.JUST_CREATED)
|
||||
let prevCreated = localStorage.getItem(localStorageItems.PREV_CREATED)
|
||||
let needUpdateId = localStorage.getItem(localStorageItems.NEED_UPDATE_ID)
|
||||
let exit = localStorage.getItem(localStorageItems.REDIRECT_EXIT)
|
||||
|
||||
if (needUpdateId) {
|
||||
let formData = new FormData()
|
||||
formData.set("cp[id]", new URLSearchParams(document.location.search).get("cp_id"))
|
||||
formData.set("cp[number]", document.querySelector(`input[name="cp[number]"]`).value)
|
||||
formData.set("update_id", true)
|
||||
updatePoint(formData).then(() => localStorage.removeItem(localStorageItems.NEED_UPDATE_ID))
|
||||
}
|
||||
|
||||
if (exit) {
|
||||
localStorage.removeItem(localStorageItems.REDIRECT_EXIT)
|
||||
|
||||
location.href = location.href.replace(location.search, '')
|
||||
return
|
||||
}
|
||||
|
||||
if (justCreated !== null) {
|
||||
localStorage.setItem(localStorageItems.PREV_CREATED, justCreated)
|
||||
localStorage.removeItem(localStorageItems.JUST_CREATED)
|
||||
|
||||
location.href = location.href.replace(location.search, "?action=edit")
|
||||
return
|
||||
}
|
||||
if (prevCreated !== null) {
|
||||
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[longitude]"]`).value = localStorage.getItem(localStorageItems.LONGITUDE)
|
||||
|
||||
localStorage.removeItem(localStorageItems.PREV_CREATED)
|
||||
localStorage.removeItem(localStorageItems.LATTITUDE)
|
||||
localStorage.removeItem(localStorageItems.LONGITUDE)
|
||||
}
|
||||
redirectIfNeeded()
|
||||
|
||||
/* HEAD */
|
||||
|
||||
let styleSheet = document.createElement("style")
|
||||
styleSheet.textContent = styles
|
||||
document.head.appendChild(styleSheet)
|
||||
addStylesToHead(styles)
|
||||
|
||||
/* SWITCH FOR DIFFERENT PAGES */
|
||||
|
||||
if (isDeleteCpPage()) {
|
||||
let deleteButton = document.querySelector(`input[name="delete_go"]`)
|
||||
let pseudoDeleteButton = document.createElement("button")
|
||||
pseudoDeleteButton.type = "button"
|
||||
pseudoDeleteButton.textContent = deleteButton.value
|
||||
pseudoDeleteButton.classList.add("unsafe-action", "pseudo-save")
|
||||
pseudoDeleteButton.addEventListener("click", async () => {
|
||||
await deletePoint()
|
||||
deleteButton.click()
|
||||
})
|
||||
|
||||
deleteButton.style.display = "none"
|
||||
deleteButton.parentElement.insertBefore(pseudoDeleteButton, deleteButton)
|
||||
bindDeleteButton()
|
||||
|
||||
return
|
||||
}
|
||||
@ -1272,317 +1655,5 @@
|
||||
return
|
||||
}
|
||||
|
||||
/* action=edit HEAD */
|
||||
|
||||
addCss("https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css")
|
||||
addCss("https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css")
|
||||
|
||||
/* NEW DEFALUT VALUES */
|
||||
|
||||
document.querySelector(`#props input[name="new_file_type1"][value="l"]`).click()
|
||||
document.querySelector(`#props input[name="new_file_type4"][value="l"]`).click()
|
||||
|
||||
/* CONTAINER */
|
||||
|
||||
let form = document.querySelector('form')
|
||||
let rows = [...document.querySelectorAll('#props > tbody > tr')]
|
||||
let insertedFileRows = new Map()
|
||||
let i = 0
|
||||
while (i < rows.length) {
|
||||
if ([23, 27, 31, 35].includes(i) && rows[i].querySelector(`input[type="file"]`) == null) {
|
||||
if (!insertedFileRows.has(i)) {
|
||||
insertedFileRows.set(i, [rows[i]])
|
||||
}
|
||||
else {
|
||||
let savedRows = insertedFileRows.get(i)
|
||||
savedRows.push(rows[i])
|
||||
insertedFileRows.set(i, savedRows)
|
||||
}
|
||||
rows.splice(i, 1)
|
||||
}
|
||||
else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
|
||||
let container = document.createElement('div')
|
||||
container.id = "new"
|
||||
let oldTable = document.querySelector("#props")
|
||||
|
||||
/* HEADER */
|
||||
|
||||
let headerContainer = createFrom(rows, "header", [
|
||||
{ index: 2, name: "№", desc: "" },
|
||||
{ index: 8, name: "Название" }
|
||||
])
|
||||
|
||||
let copyLink = document.createElement("div")
|
||||
copyLink.innerHTML = new Property(rows[2]).desc
|
||||
headerContainer.append(copyLink)
|
||||
|
||||
/* TOP BUTTONS */
|
||||
|
||||
let topButtonsContainer = createFrom(rows, "buttons", [
|
||||
{ index: 0 }
|
||||
])
|
||||
|
||||
let bottomButtonsContainer = topButtonsContainer.cloneNode(true)
|
||||
|
||||
document.querySelectorAll("#props tr:is(:first-child, :last-child) th").forEach((el, index) => {
|
||||
let rowContentWrapper = document.createElement("div")
|
||||
rowContentWrapper.classList.add("buttons-row__content-wrapper")
|
||||
while ([...el.children].length > 0) {
|
||||
let child = el.firstChild
|
||||
rowContentWrapper.appendChild(child)
|
||||
}
|
||||
|
||||
let prettifyButton = document.createElement("button")
|
||||
prettifyButton.type = "button"
|
||||
prettifyButton.textContent = "Сделать красиво"
|
||||
prettifyButton.addEventListener("click", () => {
|
||||
prettify(form, oldTable, container, insertedFileRows)
|
||||
})
|
||||
|
||||
rowContentWrapper.appendChild(prettifyButton)
|
||||
rowContentWrapper.appendChild(createAlwaysPrettifyInput(index))
|
||||
|
||||
el.appendChild(rowContentWrapper)
|
||||
})
|
||||
|
||||
;[topButtonsContainer, bottomButtonsContainer].forEach((el, index) => {
|
||||
let unglifyButton = document.createElement("button")
|
||||
unglifyButton.type = "button"
|
||||
unglifyButton.textContent = "Сделать некрасиво"
|
||||
unglifyButton.addEventListener("click", () => {
|
||||
uglify(form, container, oldTable)
|
||||
})
|
||||
|
||||
let topRowContentWrapper = el.querySelector("div > div > div")
|
||||
topRowContentWrapper.appendChild(unglifyButton)
|
||||
topRowContentWrapper.appendChild(createAlwaysPrettifyInput(index))
|
||||
})
|
||||
|
||||
addUglyDeleteListener()
|
||||
createSendButtons()
|
||||
|
||||
/* OPTIONS */
|
||||
|
||||
let firstContainer = createFrom(rows, "options", [
|
||||
{ index: 3 },
|
||||
{ index: 4, name: "КП-загадка" },
|
||||
{ index: 16, name: "Этапник" },
|
||||
{ index: 7, name: "Пиктограмма" },
|
||||
{ index: 12, name: "Нужна ИС" },
|
||||
{ index: 17, name: "Спрятать ИС" },
|
||||
{ index: 14, name: "Основной КП" },
|
||||
{ index: 10, name: "Широта" },
|
||||
{ index: 11, name: "Долгота" },
|
||||
{ index: 5, name: "Старт" },
|
||||
{ index: 6, name: "Финиш" },
|
||||
{ index: 15, name: "Знак" }
|
||||
])
|
||||
|
||||
let commentContainer = createFrom(rows, "comment", [
|
||||
{ index: 9, desc: "" }
|
||||
])
|
||||
|
||||
/* LEGEND */
|
||||
|
||||
let legendContainer = document.createElement("div")
|
||||
legendContainer.classList.add("legend-container")
|
||||
|
||||
/* LEGEND DESC */
|
||||
|
||||
let legendDescContainer = document.createElement("div")
|
||||
legendDescContainer.classList.add("legend-container__desc")
|
||||
|
||||
let legendDescHeader = document.createElement("div")
|
||||
legendDescHeader.classList.add("legend-container__desc-header")
|
||||
|
||||
|
||||
const LEGEND_RU_LABEL = "Русский"
|
||||
const LEGEND_EN_LABEL = "Английский"
|
||||
let legendLang = document.createElement("div")
|
||||
legendLang.classList.add("legend-desc__lang")
|
||||
legendLang.textContent = LEGEND_RU_LABEL
|
||||
legendDescHeader.appendChild(legendLang)
|
||||
|
||||
let legendEnSwitchContainer = createFrom(rows, "legend-switch-container", [
|
||||
{ index: 48 }
|
||||
])
|
||||
legendEnSwitchContainer.addEventListener("click", event => {
|
||||
hide([legendRuDescContainer, legendRuHiddenDescContainer, legendEnSwitchContainer])
|
||||
show([legendEnDescContainer, legendEnHiddenDescContainer, legendRuSwitchContainer])
|
||||
legendLang.textContent = LEGEND_EN_LABEL
|
||||
})
|
||||
legendDescHeader.appendChild(legendEnSwitchContainer)
|
||||
let copyDescButton = document.createElement("button")
|
||||
copyDescButton.type = "button"
|
||||
copyDescButton.textContent = "Копировать"
|
||||
copyDescButton.addEventListener("click", () => {
|
||||
let ruInputs = [...container.querySelectorAll(":is(input, textarea)[name^=\"cp_strings\[ru\]\"]")]
|
||||
let enInputs = [...container.querySelectorAll(":is(input, textarea)[name^=\"cp_strings\[en\]\"]")]
|
||||
for (const [i, enInput] of enInputs.entries()) {
|
||||
enInput.value = ruInputs[i].value
|
||||
}
|
||||
})
|
||||
|
||||
let legendRuSwitchContainer = createFrom(rows, "legend-switch-container hidden", [
|
||||
{ index: 39 }
|
||||
])
|
||||
legendRuSwitchContainer.addEventListener("click", event => {
|
||||
hide([legendEnDescContainer, legendEnHiddenDescContainer, legendRuSwitchContainer])
|
||||
show([legendRuDescContainer, legendRuHiddenDescContainer, legendEnSwitchContainer])
|
||||
legendLang.textContent = LEGEND_RU_LABEL
|
||||
})
|
||||
legendDescHeader.appendChild(legendRuSwitchContainer)
|
||||
|
||||
legendDescHeader.appendChild(copyDescButton)
|
||||
|
||||
let legendRuDescContainer = createFrom(rows, "legend-desc", [
|
||||
{ index: 40, desc: "" },
|
||||
{ index: 41, desc: "" },
|
||||
{ index: 42, desc: "" },
|
||||
{ index: 43, desc: "" }
|
||||
])
|
||||
|
||||
let legendRuHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed", [
|
||||
{ index: 44, desc: "" },
|
||||
{ index: 45, desc: "" },
|
||||
{ index: 46, desc: "" },
|
||||
{ index: 47, desc: "" },
|
||||
])
|
||||
|
||||
let legendEnDescContainer = createFrom(rows, "legend-desc hidden", [
|
||||
{ index: 49, desc: "" },
|
||||
{ index: 50, desc: "" },
|
||||
{ index: 51, desc: "" },
|
||||
{ index: 52, desc: "" }
|
||||
])
|
||||
|
||||
let legendEnHiddenDescContainer = createFrom(rows, "legend-desc collapsible collapsed hidden", [
|
||||
{ index: 53, desc: "" },
|
||||
{ index: 54, desc: "" },
|
||||
{ index: 55, desc: "" },
|
||||
{ index: 56, desc: "" }
|
||||
])
|
||||
|
||||
let hider = document.createElement("div")
|
||||
let hiderButton = document.createElement("button")
|
||||
hiderButton.classList.add("collapse-button")
|
||||
hiderButton.setAttribute("type", "button")
|
||||
hiderButton.addEventListener("click", event => {
|
||||
container.querySelectorAll(".legend-desc.collapsible").forEach(element => {
|
||||
element.classList.toggle("collapsed")
|
||||
})
|
||||
})
|
||||
hider.appendChild(hiderButton)
|
||||
|
||||
legendDescContainer.appendChild(legendDescHeader)
|
||||
legendDescContainer.appendChild(legendRuDescContainer)
|
||||
legendDescContainer.appendChild(legendRuHiddenDescContainer)
|
||||
legendDescContainer.appendChild(legendEnDescContainer)
|
||||
legendDescContainer.appendChild(legendEnHiddenDescContainer)
|
||||
legendDescContainer.appendChild(hider)
|
||||
legendContainer.appendChild(legendDescContainer)
|
||||
|
||||
/* LEGEND FILES */
|
||||
let legendFilesContainer = document.createElement("div")
|
||||
legendFilesContainer.classList.add("legend-container__files")
|
||||
|
||||
let imagesForLegendContainer = createFrom(rows, "files-container legend-photo-container", [
|
||||
{ index: 23, name: "Фото в легенде" }
|
||||
])
|
||||
legendFilesContainer.appendChild(imagesForLegendContainer)
|
||||
|
||||
let imagesForHistoryContainer = createFrom(rows, "files-container history-photo-container", [
|
||||
{ name: "Фото для ИС" }
|
||||
])
|
||||
legendFilesContainer.appendChild(imagesForHistoryContainer)
|
||||
|
||||
let audioForLegendContainer = createFrom(rows, "files-container legend-files-container", [
|
||||
{ index: 27, name: "Файлы в легенде" }
|
||||
])
|
||||
legendFilesContainer.appendChild(audioForLegendContainer)
|
||||
|
||||
let audioForHistoryContainer = createFrom(rows, "files-container history-files-container", [
|
||||
{ name: "Файлы для ИС" }
|
||||
])
|
||||
legendFilesContainer.appendChild(audioForHistoryContainer)
|
||||
|
||||
legendContainer.appendChild(legendFilesContainer)
|
||||
|
||||
let adminFilesContainer = document.createElement('div')
|
||||
adminFilesContainer.classList.add('admin-files-container')
|
||||
|
||||
let imagesForAdminContainer = createFrom(rows, "files-container admin-photo-container", [
|
||||
{ index: 31, name: "Фото в админке" }
|
||||
])
|
||||
adminFilesContainer.appendChild(imagesForAdminContainer)
|
||||
|
||||
let audioForAdminContainer = createFrom(rows, "files-container admin-files-container", [
|
||||
{ index: 35, name: "Файлы в админке" }
|
||||
])
|
||||
adminFilesContainer.appendChild(audioForAdminContainer)
|
||||
|
||||
/* BOTTOM OPTIONS */
|
||||
|
||||
let bottomOptionsContainer = createFromMulti(rows, "options bottom-options", {
|
||||
from: 59,
|
||||
to: rows.length - 3
|
||||
})
|
||||
|
||||
/* APPEND ALL */
|
||||
|
||||
container.appendChild(topButtonsContainer)
|
||||
container.appendChild(headerContainer)
|
||||
container.appendChild(firstContainer)
|
||||
container.appendChild(commentContainer)
|
||||
container.appendChild(legendContainer)
|
||||
container.appendChild(adminFilesContainer)
|
||||
container.appendChild(bottomOptionsContainer)
|
||||
container.appendChild(bottomButtonsContainer)
|
||||
|
||||
/* MAP */
|
||||
if (map !== undefined && L !== undefined) {
|
||||
let content = document.querySelector("#content")
|
||||
let contentWrapper = document.createElement("div")
|
||||
contentWrapper.id = "content-wrapper"
|
||||
contentWrapper.appendChild(document.querySelector("form"))
|
||||
contentWrapper.appendChild(document.querySelector("#map-wrapper"))
|
||||
content.appendChild(contentWrapper)
|
||||
|
||||
let panToCenter = document.createElement("button")
|
||||
panToCenter.type = "button"
|
||||
panToCenter.textContent = "В центр"
|
||||
panToCenter.addEventListener("click", () => {
|
||||
let lat = document.querySelector("input[name=\"cp\[lattitude\]\"").value
|
||||
let lon = document.querySelector("input[name=\"cp\[longitude\]\"").value
|
||||
map.setView(new L.LatLng(parseFloat(lat), parseFloat(lon)), 16)
|
||||
})
|
||||
document.querySelector("#map_controls").appendChild(panToCenter)
|
||||
}
|
||||
|
||||
/* DIALOG */
|
||||
let dialog = document.createElement("dialog")
|
||||
dialog.id = "dialog"
|
||||
document.body.appendChild(dialog)
|
||||
|
||||
dialog.addEventListener("click", e => {
|
||||
if (e.target == dialog) {
|
||||
e.target.close()
|
||||
}
|
||||
})
|
||||
|
||||
dialog.addEventListener("close", e => {
|
||||
e.target.innerHTML = ""
|
||||
})
|
||||
|
||||
/* PRETTIFY CHECKBOX */
|
||||
|
||||
if (localStorage.getItem(localStorageItems.ALWAYS_PRETTIFY)) {
|
||||
document.querySelector(`input[name^="always-prettify-0"]`).click()
|
||||
prettify(form, oldTable, container, insertedFileRows)
|
||||
}
|
||||
|
||||
prettifyEditCpPage()
|
||||
})();
|
Loading…
Reference in New Issue
Block a user