function for managing points
This commit is contained in:
parent
e169396914
commit
76e46bd9b6
74
main.js
74
main.js
@ -1838,12 +1838,86 @@
|
||||
document.querySelector(`#content table table tr:nth-child(2) `).remove()
|
||||
}
|
||||
|
||||
function matchNumberFromSelect(select) {
|
||||
return [...document.querySelector(select).options].reduce(
|
||||
(res, el) => ({ ...res, [el.textContent.match(/(?<=^\s*#)\d+/g)?.[0]]: el.value }),
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
function unselectAll(select) {
|
||||
[...document.querySelector(select).selectedOptions].forEach(el => el.selected = false)
|
||||
}
|
||||
|
||||
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"))
|
||||
|
||||
let addPointsContainer = document.createElement("div")
|
||||
|
||||
let input = document.createElement("input")
|
||||
input.id = "add-point"
|
||||
input.type = "text"
|
||||
|
||||
let addButton = document.createElement("button")
|
||||
addButton.type = "button"
|
||||
addButton.textContent = "Добавить"
|
||||
addButton.addEventListener("click", () => {
|
||||
let point = document.querySelector("#add-point").value
|
||||
if (point == "") return
|
||||
|
||||
let availablePoints = matchNumberFromSelect("#cps_avail")
|
||||
let addedPoints = matchNumberFromSelect("#cps_in")
|
||||
|
||||
if (point in addedPoints) {
|
||||
alert("Точка уже добавлена")
|
||||
return
|
||||
}
|
||||
|
||||
if (!(point in availablePoints)) {
|
||||
alert("Точка не найдена")
|
||||
return
|
||||
}
|
||||
|
||||
unselectAll("#cps_avail")
|
||||
let option = document.querySelector(`#cps_avail option[value="${availablePoints[point]}"]`)
|
||||
option.selected = true
|
||||
document.querySelector(`#cps_add`).click()
|
||||
option.selected = false
|
||||
})
|
||||
|
||||
let removeButton = document.createElement("button")
|
||||
removeButton.type = "button"
|
||||
removeButton.textContent = "Убрать"
|
||||
removeButton.addEventListener("click", () => {
|
||||
let point = document.querySelector("#add-point").value
|
||||
if (point == "") return
|
||||
|
||||
let addedPoints = matchNumberFromSelect("#cps_in")
|
||||
|
||||
if (!(point in addedPoints)) return
|
||||
|
||||
unselectAll("#cps_in")
|
||||
let option = document.querySelector(`#cps_in option[value="${addedPoints[point]}"]`)
|
||||
option.selected = true
|
||||
document.querySelector(`#cps_delete`).click()
|
||||
option.selected = false
|
||||
})
|
||||
|
||||
addPointsContainer.append(addButton)
|
||||
addPointsContainer.append(input)
|
||||
addPointsContainer.append(removeButton)
|
||||
|
||||
document.querySelector("table tr:nth-child(16) td").prepend(addPointsContainer)
|
||||
|
||||
addStylesToHead(`
|
||||
#add-point {
|
||||
width: 5em;
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
function toggleStagePageRows(rows) {
|
||||
|
Loading…
Reference in New Issue
Block a user