Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm changes on close and edit toggle #1000

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions lib/ui/locations/view.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,26 @@ export default location => {
<button
title = "Enable edits"
class = ${`mask-icon edit ${location.new && 'on' || ''}`}
onclick = ${e => {
onclick = ${async e => {

// Edits are on
if (e.target.classList.contains('on')) {

// Remove on class from button.
e.target.classList.remove('on')

// Remove edits from infoj entries.
location.removeEdits()
if (location.infoj.some(entry => typeof entry.newValue !== 'undefined')) {

if (confirm(`Save your changes to this location?`)) {

await location.update()

} else {

// Remove edits from infoj entries.
location.removeEdits()
}
}

} else {

Expand Down Expand Up @@ -170,9 +180,22 @@ export default location => {
<button
title = ${mapp.dictionary.location_remove}
class = "mask-icon close no"
onclick = ${e => {
location.remove()
// location.layer.mapview.Map.updateSize()
onclick = ${async e => {

if (location.infoj.some(entry => typeof entry.newValue !== 'undefined')) {

if (confirm(`Save your changes to this location?`)) {

await location.update()

} else {

// The location will not be closed.
return;
}
}

location.remove()
}}>`)

location.view = mapp.ui.elements.drawer({
Expand Down Expand Up @@ -207,10 +230,10 @@ export default location => {
}

// Hide upload button if no other field in the infoj has a newValue.
location.view.querySelector('.btn-save')
.style.display = location.infoj
.some(entry => typeof entry.newValue !== 'undefined')
&& 'inline-block' || 'none';
location.view.querySelector('.btn-save').style.display =
location.infoj.some(entry => typeof entry.newValue !== 'undefined')
? 'inline-block'
: 'none';

})

Expand Down