save routes on server
This commit is contained in:
parent
07d01839d1
commit
c2e40b812a
67
main.js
67
main.js
@ -87,7 +87,7 @@
|
||||
let removedFilesLinks = []
|
||||
|
||||
class Tag {
|
||||
static make(name, params) {
|
||||
static make(name, params = {}) {
|
||||
let element = document.createElement(name)
|
||||
for (const [name, value] of Object.entries(params)) {
|
||||
if (name == "on") {
|
||||
@ -126,6 +126,10 @@
|
||||
static input(params) {
|
||||
return this.make("input", params)
|
||||
}
|
||||
|
||||
static a(params) {
|
||||
return this.make("a", params)
|
||||
}
|
||||
}
|
||||
|
||||
class Property {
|
||||
@ -308,6 +312,19 @@
|
||||
})
|
||||
}
|
||||
|
||||
async function updateRoute(formData) {
|
||||
return await fetch(`https://${adminSite}/api/competitions/${getCompetition()}/route`, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
}
|
||||
|
||||
async function getRoutes() {
|
||||
return await fetch(`https://${adminSite}/api/points/${urlParams().get("cp_id")}/routes`, {
|
||||
method: 'GET'
|
||||
})
|
||||
}
|
||||
|
||||
function relatedPointsHref() {
|
||||
return `https://${adminSite}/competitions/${getCompetition()}/relations`
|
||||
}
|
||||
@ -1595,6 +1612,29 @@
|
||||
}
|
||||
}
|
||||
|
||||
function addRoutesList() {
|
||||
(async () => {
|
||||
let routes = await (await getRoutes()).json()
|
||||
|
||||
if (routes.length == 0) return
|
||||
|
||||
let result = Tag.div()
|
||||
result.append("Маршруты: ")
|
||||
for (const [i, route] of routes.entries()) {
|
||||
if (i !== 0) {
|
||||
result.append(", ")
|
||||
}
|
||||
|
||||
result.append(Tag.a({
|
||||
href: `/${getCompetition()}/` + catLinks["Редактор маршрута"](route.cat_id),
|
||||
textContent: route.name
|
||||
}))
|
||||
}
|
||||
|
||||
document.querySelector(`#map_controls`).after(result)
|
||||
})()
|
||||
}
|
||||
|
||||
function checkIfAlwaysPrettify(form, oldTable, container, insertedFileRows) {
|
||||
if (localStorage.getItem(localStorageItems.NOT_PRETTIFY_EDIT_CP) === null) {
|
||||
document.querySelector(`input[name^="always-prettify-0"]`).click()
|
||||
@ -1982,6 +2022,7 @@
|
||||
/* MAP */
|
||||
|
||||
formatMap()
|
||||
addRoutesList()
|
||||
|
||||
/* DIALOG */
|
||||
|
||||
@ -2110,12 +2151,36 @@
|
||||
`)
|
||||
}
|
||||
|
||||
function getRouteName() {
|
||||
return document.querySelector(`#content h1`).textContent.match(/(?<=\")[^\"]+/)
|
||||
}
|
||||
|
||||
function sendRouteData() {
|
||||
let sendButton = Tag.button({
|
||||
textContent: "Отправить",
|
||||
type: "button",
|
||||
on: {
|
||||
click: async () => {
|
||||
let formData = new FormData(document.querySelector(`form[name="main_form"]`))
|
||||
|
||||
let catId = urlParams().get("cat_id")
|
||||
formData.set("cat_id", catId)
|
||||
formData.set("cat_name", getRouteName())
|
||||
await updateRoute(formData)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
document.querySelector(`.unsafe-action`).after(sendButton)
|
||||
}
|
||||
|
||||
addJs("https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js")
|
||||
changeColumnWidth()
|
||||
hideDescription()
|
||||
hideStartRow()
|
||||
useColspanForFinishWarning()
|
||||
countCp()
|
||||
sendRouteData()
|
||||
}
|
||||
|
||||
function matchNumberFromSelect(select) {
|
||||
|
Loading…
Reference in New Issue
Block a user