Skip to content

Commit

Permalink
Editing - Show the previous form when the user cancel current editing
Browse files Browse the repository at this point in the history
  • Loading branch information
mdouchin committed Dec 12, 2024
1 parent 7f53e87 commit f1aac1e
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions assets/src/legacy/edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,16 @@ var lizEdition = function() {
return false;
}

/**
* Sleep function
* @param {number} sleepDuration Duration to wait (milliseconds)
* @returns {Promise}
*/
const editingDelay = sleepDuration => new Promise((resolve, reject) => {
setTimeout(_ => resolve(), sleepDuration)
});


/**
*
*/
Expand Down Expand Up @@ -909,14 +919,23 @@ var lizEdition = function() {
}
});

$('#edition-draw').click(function(){
$('#edition-draw').click(async function(){
// Do nothing if not enabled
if ( $(this).hasClass('disabled') )
return false;
// Deactivate previous edition
if( lizMap.editionPending){
if ( !confirm( lizDict['edition.confirm.cancel'] ) )
// Show editing dock
document.querySelector('li.edition:not(.active) #button-edition')?.click();

// Display a confirmation message
// We need to add a delay in order to show the editing dock
// If not the confirm message is displayed before the editing dock is shown
await editingDelay(10);
if ( !confirm( lizDict['edition.confirm.cancel'] ) ) {
return false;
}

finishEdition();
editionLayer.clear();
}
Expand Down Expand Up @@ -1327,20 +1346,31 @@ var lizEdition = function() {
return internalLaunchEdition(parentInfo, parentFeat.id.split('.').pop());
}


/**
*
* @param {FeatureEditionData} editedFeature
* @param aFid
* @param {Function} aCallback
* @returns {boolean}
*/
function internalLaunchEdition(editedFeature, aFid, aCallback) {
async function internalLaunchEdition(editedFeature, aFid, aCallback) {

// Deactivate previous edition when the feature to edit has no
// relation to the current edited feature
if (lizMap.editionPending) {
if ( !confirm( lizDict['edition.confirm.cancel'] ) )
// Show editing dock
document.querySelector('li.edition:not(.active) #button-edition')?.click();

// Display a confirmation message
// We need to add a delay in order to show the editing dock
// If not the confirm message is displayed before the editing dock is shown
await editingDelay(10);
if ( !confirm( lizDict['edition.confirm.cancel'] ) ) {
return false;
}

// Finish editing
finishEdition();
}

Expand Down

0 comments on commit f1aac1e

Please sign in to comment.