From 09b326fdfe8cee984d0c47ae243e0d0bbd949620 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 1 Oct 2019 11:09:30 +0200 Subject: [PATCH] fixed Test And Save on LMS Setup edit view --- .../seb/sebserver/gui/content/LmsSetupForm.java | 12 +++++++----- .../sebserver/gui/service/page/PageContext.java | 1 + .../gui/service/page/impl/PageAction.java | 14 ++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java index 3b1dd9ae..1a92c70a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java @@ -202,7 +202,7 @@ public class LmsSetupForm implements TemplateComposer { .newAction(ActionDefinition.LMS_SETUP_SAVE_AND_TEST) .withEntityKey(entityKey) - .withExec(action -> this.testLmsSetup(action, formHandle)) + .withExec(action -> this.testLmsSetup(action, formHandle, true)) .ignoreMoveAwayFromEdit() .publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && !readonly) @@ -238,7 +238,7 @@ public class LmsSetupForm implements TemplateComposer { /** Save and test connection before activation */ private PageAction activate(final PageAction action, final FormHandle formHandle) { // first test the LMS Setup. If this fails the action execution will stops - final PageAction testLmsSetup = this.testLmsSetup(action, formHandle); + final PageAction testLmsSetup = this.testLmsSetup(action, formHandle, false); // if LMS Setup test was successful, the activation action applies this.resourceService.getRestService().getBuilder(ActivateLmsSetup.class) .withURIVariable( @@ -285,9 +285,11 @@ public class LmsSetupForm implements TemplateComposer { } /** LmsSetup test action implementation */ - private PageAction testLmsSetup(final PageAction action, final FormHandle formHandle) { - // If we are in edit-mode we have to save the form before testing - if (!action.pageContext().isReadonly()) { + private PageAction testLmsSetup( + final PageAction action, + final FormHandle formHandle, final boolean saveFirst) { + + if (saveFirst) { final Result postResult = formHandle.doAPIPost(); if (postResult.hasError()) { formHandle.handleError(postResult.getError()); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java index c07258fd..8253cea2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageContext.java @@ -30,6 +30,7 @@ public interface PageContext { public static final String PAGE_TEMPLATE_COMPOSER_NAME = "ATTR_PAGE_TEMPLATE_COMPOSER_NAME"; public static final String READ_ONLY = "READ_ONLY"; + public static final String READ_ONLY_FROM = "READ_ONLY_FROM"; public static final String ENTITY_ID = "ENTITY_ID"; public static final String PARENT_ENTITY_ID = "PARENT_ENTITY_ID"; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java index 7f3df45c..e8ad94bf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java @@ -59,16 +59,18 @@ public final class PageAction { this.successMessage = successMessage; this.selectionSupplier = selectionSupplier; this.noSelectionMessage = noSelectionMessage; - this.pageContext = pageContext; + this.pageContext = (pageContext != null) ? pageContext.copy() : null; this.exec = (exec != null) ? exec : Function.identity(); this.fireActionEvent = fireActionEvent; this.ignoreMoveAwayFromEdit = ignoreMoveAwayFromEdit; - this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.TRUE_STRING); - if (definition.targetState != null) { - final Type type = definition.targetState.type(); - if (type.name().equals(Type.FORM_EDIT.name())) { - this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.FALSE_STRING); + if (this.pageContext != null) { + this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.TRUE_STRING); + if (definition.targetState != null) { + final Type type = definition.targetState.type(); + if (type.name().equals(Type.FORM_EDIT.name())) { + this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.FALSE_STRING); + } } } }