36 lines
1.5 KiB
JavaScript
36 lines
1.5 KiB
JavaScript
document.querySelectorAll('aside#actions #create')
|
|
.forEach(elt => elt.onclick = () => {
|
|
const url = `${topSection}/${uuid()}`
|
|
|
|
fetch(`${document.body.dataset.editHost}/${url}.create`, { method: 'PUT', body: topSection })
|
|
.then(() => sleep(1))
|
|
.then(() => window.location.assign('/' + url))
|
|
.catch(error => console.error(`Error creating #{topSection}`, error))
|
|
})
|
|
|
|
document.querySelectorAll('aside#actions #delete')
|
|
.forEach(elt => elt.onclick = () => {
|
|
if (confirm(elt.dataset.confirm))
|
|
fetch(document.body.dataset.editUrl.replace('/_index', '.delete'), { method: 'PUT' })
|
|
.then(() => sleep(1))
|
|
.then(() => window.location.assign('/' + topSection))
|
|
.catch(error => console.error(`Error deleting #{topSection}`, error))
|
|
})
|
|
|
|
|
|
document.querySelectorAll('aside#actions input#file')
|
|
.forEach(elt => elt.onchange = () =>
|
|
[...elt.files].forEach(file =>
|
|
fetch(document.body.dataset.editUrl.replace('_index', file.name), { method: 'PUT', body: file })
|
|
.then(() => sleep(1))
|
|
.then(() => window.location.reload())
|
|
.catch(error => console.error(`Error uploading ${elt.files[0].name}`, error))))
|
|
|
|
document.querySelectorAll('.delete_image')
|
|
.forEach(elt => elt.onclick = () => {
|
|
if (confirm(elt.dataset.confirm))
|
|
fetch(document.body.dataset.editHost + elt.dataset.target, { method: 'DELETE' })
|
|
.catch(error => console.error(error))
|
|
.finally(() => elt.parentNode.remove())
|
|
})
|