diff --git a/main.js b/main.js index ffb9ca1..754363f 100644 --- a/main.js +++ b/main.js @@ -280,6 +280,10 @@ return isRouteManagement() && getAction() === "map" } + function cpLink(cpId) { + return `/${getCompetition()}/cp_mgmt/?action=edit&cp_id=${cpId}` + } + async function updatePoint(formData) { return await fetch(`https://runcity.geo.rictum.ru/api/competitions/${getCompetition()}/update`, { method: 'POST', @@ -293,6 +297,12 @@ }) } + async function getPointIdByNumber(number) { + return await fetch(`https://runcity.geo.rictum.ru/api/competitions/${getCompetition()}/${number}`, { + method: 'GET' + }) + } + function copyCoordinates() { let copyButton = document.createElement("button") copyButton.addEventListener("click", async event => { @@ -1057,6 +1067,36 @@ } menuContainer.append(createMenuFromLinks(mainLinksFormatted, ["Легенда"])) + let goToContainer = Tag.make("li", { + classes: "go-to-container", + children: [ + Tag.input({ + type: "text", + id: "go-to-cp" + }), + Tag.span({ + textContent: "✏️ КП", + on: { + click: async function() { + let number = document.querySelector("#go-to-cp").value + let response = await getPointIdByNumber(number) + let json = await response.json() + let id = json.id + + if (id == null) { + alert("Нет КП с таким номером") + return + } + + location.href = cpLink(id) + } + } + }) + ] + }) + + ;[...menuContainer.querySelectorAll(`li`)].find(el => el.querySelector(`a`).textContent.trim() == "Контрольные пункты")?.after(goToContainer) + let catId = urlParams().get("cat_id") if (catId !== null) { let catLinksFormatted = {} @@ -1090,6 +1130,17 @@ } } } + + .go-to-container { + input { + width: 5em; + } + + span { + margin-left: .5em; + cursor: pointer; + } + } } `) }