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

Adds a abort button to editor form if autosave and autoform is true #1512

Merged
merged 2 commits into from
Apr 20, 2022
Merged
Changes from 1 commit
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
28 changes: 27 additions & 1 deletion src/controls/editor/edithandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ let allowEditAttributes;
let allowEditGeometry;
/** List that tracks the state when editing related tables */
let breadcrumbs = [];
let autoCreatedFeature = false;

function isActive() {
if (modify === undefined || select === undefined) {
Expand Down Expand Up @@ -216,6 +217,7 @@ async function addFeature(feature) {
hasDraw = false;
dispatcher.emitChangeEdit('draw', false);
if (autoForm) {
autoCreatedFeature = true;
// eslint-disable-next-line no-use-before-define
editAttributes(feature);
}
Expand Down Expand Up @@ -671,6 +673,25 @@ function attributesSaveHandler(features, formEl) {
}
}

/**
* Sets up an eventlistener on the attribute editor form abort button.
* @param {Collection} features The features that shouldn't be updated
*/
function onAttributesAbort(features) {
if (document.getElementById(`o-abort-button-${currentLayer}`) !== null) {
document.getElementById(`o-abort-button-${currentLayer}`).addEventListener('click', (e) => {
document.getElementById(`o-abort-button-${currentLayer}`).blur();
johnnyblasta marked this conversation as resolved.
Show resolved Hide resolved
features.forEach((feature) => {
deleteFeature(feature, editLayers[currentLayer]).then(() => select.getFeatures().clear());
});
modal.closeModal();
// The modal does not fire close event when it is closed externally
onModalClosed();
e.preventDefault();
});
}
}

/**
* Sets up an eventlistener on the attribute editor form save button.
* @param {Collection} features The features that should be updated
Expand Down Expand Up @@ -1075,7 +1096,11 @@ function editAttributes(feat) {
attachmentsForm = `<div id="o-attach-form-${currentLayer}"></div>`;
}

const form = `<div id="o-form">${formElement}${relatedTablesFormHTML}${attachmentsForm}<br><div class="o-form-save"><input id="o-save-button-${currentLayer}" type="button" value="Ok"></input></div></div>`;
let form = `<div id="o-form">${formElement}${relatedTablesFormHTML}${attachmentsForm}<br><div class="o-form-save"><input id="o-save-button-${currentLayer}" type="button" value="OK"></input></div></div>`;
if (autoCreatedFeature) {
form = `<div id="o-form">${formElement}${relatedTablesFormHTML}${attachmentsForm}<br><div class="o-form-save"><input id="o-save-button-${currentLayer}" type="button" value="Spara"></input><input id="o-abort-button-${currentLayer}" type="button" value="Avbryt"></input></div></div>`;
autoCreatedFeature = false;
}

modal = Modal({
title: dlgTitle,
Expand Down Expand Up @@ -1125,6 +1150,7 @@ function editAttributes(feat) {
});

onAttributesSave(features, attributeObjects);
onAttributesAbort(features);
}
}

Expand Down