fixed Test And Save on LMS Setup edit view
This commit is contained in:
parent
db29818ecd
commit
09b326fdfe
3 changed files with 16 additions and 11 deletions
|
@ -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<LmsSetup> 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<LmsSetup> 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<LmsSetup> formHandle, final boolean saveFirst) {
|
||||
|
||||
if (saveFirst) {
|
||||
final Result<LmsSetup> postResult = formHandle.doAPIPost();
|
||||
if (postResult.hasError()) {
|
||||
formHandle.handleError(postResult.getError());
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue