fixed Test And Save on LMS Setup edit view

This commit is contained in:
anhefti 2019-10-01 11:09:30 +02:00
parent db29818ecd
commit 09b326fdfe
3 changed files with 16 additions and 11 deletions

View file

@ -202,7 +202,7 @@ public class LmsSetupForm implements TemplateComposer {
.newAction(ActionDefinition.LMS_SETUP_SAVE_AND_TEST) .newAction(ActionDefinition.LMS_SETUP_SAVE_AND_TEST)
.withEntityKey(entityKey) .withEntityKey(entityKey)
.withExec(action -> this.testLmsSetup(action, formHandle)) .withExec(action -> this.testLmsSetup(action, formHandle, true))
.ignoreMoveAwayFromEdit() .ignoreMoveAwayFromEdit()
.publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && !readonly) .publishIf(() -> modifyGrant && isNotNew.getAsBoolean() && !readonly)
@ -238,7 +238,7 @@ public class LmsSetupForm implements TemplateComposer {
/** Save and test connection before activation */ /** Save and test connection before activation */
private PageAction activate(final PageAction action, final FormHandle<LmsSetup> formHandle) { private PageAction activate(final PageAction action, final FormHandle<LmsSetup> formHandle) {
// first test the LMS Setup. If this fails the action execution will stops // 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 // if LMS Setup test was successful, the activation action applies
this.resourceService.getRestService().getBuilder(ActivateLmsSetup.class) this.resourceService.getRestService().getBuilder(ActivateLmsSetup.class)
.withURIVariable( .withURIVariable(
@ -285,9 +285,11 @@ public class LmsSetupForm implements TemplateComposer {
} }
/** LmsSetup test action implementation */ /** LmsSetup test action implementation */
private PageAction testLmsSetup(final PageAction action, final FormHandle<LmsSetup> formHandle) { private PageAction testLmsSetup(
// If we are in edit-mode we have to save the form before testing final PageAction action,
if (!action.pageContext().isReadonly()) { final FormHandle<LmsSetup> formHandle, final boolean saveFirst) {
if (saveFirst) {
final Result<LmsSetup> postResult = formHandle.doAPIPost(); final Result<LmsSetup> postResult = formHandle.doAPIPost();
if (postResult.hasError()) { if (postResult.hasError()) {
formHandle.handleError(postResult.getError()); formHandle.handleError(postResult.getError());

View file

@ -30,6 +30,7 @@ public interface PageContext {
public static final String PAGE_TEMPLATE_COMPOSER_NAME = "ATTR_PAGE_TEMPLATE_COMPOSER_NAME"; 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 = "READ_ONLY";
public static final String READ_ONLY_FROM = "READ_ONLY_FROM";
public static final String ENTITY_ID = "ENTITY_ID"; public static final String ENTITY_ID = "ENTITY_ID";
public static final String PARENT_ENTITY_ID = "PARENT_ENTITY_ID"; public static final String PARENT_ENTITY_ID = "PARENT_ENTITY_ID";

View file

@ -59,16 +59,18 @@ public final class PageAction {
this.successMessage = successMessage; this.successMessage = successMessage;
this.selectionSupplier = selectionSupplier; this.selectionSupplier = selectionSupplier;
this.noSelectionMessage = noSelectionMessage; this.noSelectionMessage = noSelectionMessage;
this.pageContext = pageContext; this.pageContext = (pageContext != null) ? pageContext.copy() : null;
this.exec = (exec != null) ? exec : Function.identity(); this.exec = (exec != null) ? exec : Function.identity();
this.fireActionEvent = fireActionEvent; this.fireActionEvent = fireActionEvent;
this.ignoreMoveAwayFromEdit = ignoreMoveAwayFromEdit; this.ignoreMoveAwayFromEdit = ignoreMoveAwayFromEdit;
this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.TRUE_STRING); if (this.pageContext != null) {
if (definition.targetState != null) { this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.TRUE_STRING);
final Type type = definition.targetState.type(); if (definition.targetState != null) {
if (type.name().equals(Type.FORM_EDIT.name())) { final Type type = definition.targetState.type();
this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.FALSE_STRING); if (type.name().equals(Type.FORM_EDIT.name())) {
this.pageContext = pageContext.withAttribute(AttributeKeys.READ_ONLY, Constants.FALSE_STRING);
}
} }
} }
} }