From 815bc96234065500e4197082d2ad08b0dcf38fb8 Mon Sep 17 00:00:00 2001 From: Zhora Shalyapin Date: Fri, 14 Mar 2025 14:39:36 +0000 Subject: [PATCH] add links to stages --- main.js | 77 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 24 deletions(-) diff --git a/main.js b/main.js index 658b237..ee0f63e 100644 --- a/main.js +++ b/main.js @@ -15,7 +15,22 @@ (function () { 'use strict' - let fileInputs = { + const links = { + "Волонтеры": "suv_comp", + "Контрольные пункты": "cp_mgmt", + "Добавить новый КП": "cp_mgmt/?action=edit", + "Маршруты": "route_mgmt", + } + + const catLinks = { + "Редактор маршрута": (catId) => `route_mgmt?action=edit&cat_id=${catId}`, + "Конструктор маршрута": (catId) => `route_mgmt/?action=build2&cat_id=${catId}`, + "Карта": (catId) => `route_mgmt?action=map&cat_id=${catId}`, + "Этапы": (catId) => `route_mgmt/?action=stages&cat_id=${catId}`, + "Легенда": (catId) => `route_mgmt?action=preview&cat_id=${catId}&locale_id=ru`, + } + + const fileInputs = { "attachment1": { "l": "legend_photo", "h": "history_photo" @@ -28,12 +43,12 @@ "attachment3": "admin_files" } - let fileInpitVariants = { + const fileInpitVariants = { "l": "для легенды", "h": "для ист. справки" } - let mapsCenterByCompetition = { + const mapsCenterByCompetition = { "msk2025": { lat: 55.839808, ifSouthern: { @@ -187,10 +202,14 @@ return getPageType() === "route_mgmt" } - function isListCpPage() { + function isCpListPage() { return isCpManagement() && getAction() === null } + function isRouteListPage() { + return isRouteManagement() && getAction() === null + } + function isRouteBuildPage() { return isRouteManagement() && getAction() === "build2" } @@ -935,20 +954,6 @@ } function addStickyMenu() { - let links = { - "Волонтеры": "suv_comp", - "Контрольные пункты": "cp_mgmt", - "Добавить новый КП": "cp_mgmt/?action=edit", - "Маршруты": "route_mgmt", - } - let catLinks = { - "Редактор маршрута": (catId) => `route_mgmt?action=edit&cat_id=${catId}`, - "Конструктор маршрута": (catId) => `route_mgmt/?action=stages&cat_id=${catId}`, - "Карта": (catId) => `route_mgmt?action=map&cat_id=${catId}`, - "Этапы": (catId) => `route_mgmt/?action=stages&cat_id=${catId}`, - "Легенда": (catId) => `route_mgmt?action=preview&cat_id=${catId}&locale_id=ru`, - } - let menuContainer = document.createElement("nav") menuContainer.classList.add("sticky-menu") let menu = document.createElement("menu") @@ -996,6 +1001,24 @@ }) } + function addStageLink() { + let linkCells = [...document.querySelectorAll("#content table td:nth-child(2)")] + for (const linkCell of linkCells) { + let href = linkCell.querySelector("a").href + let catId = new URLSearchParams(href).get("cat_id") + let constructorLink = linkCell.querySelector(`a[href="${catLinks["Конструктор маршрута"](catId).replace("route_mgmt/", "")}"]`) + + if (constructorLink) { + let stagesLink = document.createElement("a") + stagesLink.innerText = "Этапы" + stagesLink.href = catLinks[stagesLink.innerText](catId) + + constructorLink.after(stagesLink) + constructorLink.after(", ") + } + } + } + function getRows() { return [...document.querySelectorAll('#props > tbody > tr')] } @@ -1781,16 +1804,22 @@ } addClearBoth() - initMapbox() - addFullscreenButton() + if (document.querySelector(".leaflet-container")) { + initMapbox() + addFullscreenButton() + + if (isRouteBuildPage() || isRouteMapPage()) { + centerMap() + } + } addStickyMenu() - if (isRouteBuildPage() || isRouteMapPage()) { - centerMap() - } - if (isEditCpPage()) { prettifyEditCpPage() } + + if (isRouteListPage()) { + addStageLink() + } })(); \ No newline at end of file