Skip to content

Commit

Permalink
Merge pull request #1000 from dbauszus-glx:confirm-changes
Browse files Browse the repository at this point in the history
Confirm changes on close and edit toggle
  • Loading branch information
RobAndrewHurst authored Nov 15, 2023
2 parents 9fd1106 + 3e499d5 commit 6bc6766
Showing 1 changed file with 33 additions and 10 deletions.
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

0 comments on commit 6bc6766

Please sign in to comment.