Skip to content

Commit

Permalink
MID-7976 custom validity handling, validation, submitting. seems working
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jul 15, 2022
1 parent 0c368a6 commit 19a671d
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,47 @@ <h3 class="card-title">
</h3>
</div>
<div class="card-body d-flex flex-column gap-3 pb-1">
<wicket:enclosure child="validity">
<div class="form-group mb-0">
<label>
<wicket:message key="ShoppingCartPanel.validity"/>
<i class="fas fa-info-circle fa-xs text-primary" wicket:id="validityInfo" wicket:message="title:CartSummaryPanel.validityTitle"></i>
</label>
<select class="form-control" wicket:id="validity"/>
<form wicket:id="form">
<wicket:enclosure child="validity">
<div class="form-group">
<label>
<wicket:message key="ShoppingCartPanel.validity"/>
<i class="fas fa-info-circle fa-xs text-primary" wicket:id="validityInfo" wicket:message="title:CartSummaryPanel.validityTitle"></i>
</label>
<select class="form-control" wicket:id="validity"/>
</div>
</wicket:enclosure>
<div class="form-group" wicket:id="customValidity">
<div class="form-group">
<label class="col-form-label-sm"><wicket:message key="ActivationType.validFrom"/></label>
<div wicket:id="customValidityFrom"/>
</div>
<div class="form-group">
<label class="col-form-label-sm"><wicket:message key="ActivationType.validTo"/></label>
<div wicket:id="customValidityTo"/>
</div>
</div>
</wicket:enclosure>
<div class="form-group mb-0" wicket:id="customValidity">
<div class="form-group">
<label class="col-form-label-sm"><wicket:message key="ActivationType.validFrom"/></label>
<div wicket:id="customValidityFrom"/>
</div>
<div class="form-group">
<label class="col-form-label-sm"><wicket:message key="ActivationType.validTo"/></label>
<div wicket:id="customValidityTo"/>
</div>
</div>
<wicket:enclosure child="comment">
<div class="form-group mb-0">
<label>
<wicket:message key="ShoppingCartPanel.comment"/>
<i class="fas fa-info-circle fa-xs text-primary" wicket:id="commentInfo" wicket:message="title:CartSummaryPanel.commentTitle"></i>
</label>
<textarea class="form-control" rows="4" wicket:id="comment"></textarea>
</div>
</wicket:enclosure>
<a class="btn btn-outline-danger" wicket:id="openConflict">
<i class="fas fa-triangle-exclamation mr-1"></i>
<wicket:message key="ShoppingCartPanel.openConflict"/>
</a>
<a class="btn btn-success" wicket:id="submit">
<i class="fas fa-credit-card mr-1"></i>
<wicket:message key="ShoppingCartPanel.submit"/>
</a>
<wicket:enclosure child="comment">
<div class="form-group">
<label>
<wicket:message key="ShoppingCartPanel.comment"/>
<i class="fas fa-info-circle fa-xs text-primary" wicket:id="commentInfo" wicket:message="title:CartSummaryPanel.commentTitle"></i>
</label>
<textarea class="form-control" rows="4" wicket:id="comment"></textarea>
</div>
</wicket:enclosure>
<a class="btn btn-outline-danger" wicket:id="openConflict">
<i class="fas fa-triangle-exclamation mr-1"></i>
<wicket:message key="ShoppingCartPanel.openConflict"/>
</a>

<div class="text-danger" wicket:id="messages"/>

<a class="btn btn-success" wicket:id="submit">
<i class="fas fa-credit-card mr-1"></i>
<wicket:message key="ShoppingCartPanel.submit"/>
</a>
</form>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,24 @@
import java.util.Date;
import java.util.List;

import com.evolveum.midpoint.gui.api.component.form.DateRange;
import com.evolveum.midpoint.gui.api.component.form.DateRangePicker;

import com.evolveum.midpoint.web.component.DateInput;
import com.evolveum.midpoint.web.component.input.DatePanel;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;

import org.apache.commons.lang3.BooleanUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.markup.html.form.validation.AbstractFormValidator;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.model.IModel;
Expand All @@ -54,16 +51,21 @@
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.web.component.DateInput;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.column.RoundedIconColumn;
import com.evolveum.midpoint.web.component.dialog.ConfirmationPanel;
import com.evolveum.midpoint.web.component.dialog.Popupable;
import com.evolveum.midpoint.web.component.form.MidpointForm;
import com.evolveum.midpoint.web.component.util.EnableBehaviour;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
import com.evolveum.midpoint.web.util.DateValidator;
import com.evolveum.midpoint.web.util.TooltipBehavior;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import javax.xml.datatype.XMLGregorianCalendar;

/**
* Created by Viliam Repan (lazyman).
*/
Expand All @@ -88,6 +90,8 @@ public class CartSummaryPanel extends BasePanel<RequestAccess> {
private static final String ID_CUSTOM_VALIDITY_INFO = "customValidityInfo";
private static final String ID_CUSTOM_VALIDITY_FROM = "customValidityFrom";
private static final String ID_CUSTOM_VALIDITY_TO = "customValidityTo";
private static final String ID_FORM = "form";
private static final String ID_MESSAGES = "messages";

private WizardModel wizard;

Expand All @@ -103,10 +107,10 @@ public CartSummaryPanel(String id, WizardModel wizard, IModel<RequestAccess> mod
protected void onConfigure() {
super.onConfigure();

DropDownChoice validity = (DropDownChoice) get(ID_VALIDITY);
DropDownChoice validity = (DropDownChoice) get(ID_FORM + ":" + ID_VALIDITY);
validity.setRequired(isValidityRequired());

TextArea comment = (TextArea) get(ID_COMMENT);
TextArea comment = (TextArea) get(ID_FORM + ":" + ID_COMMENT);
comment.setRequired(isCommentRequired());
}

Expand Down Expand Up @@ -154,25 +158,54 @@ public void setObject(Object object) {
}
};

IModel<Date> customFrom = Model.of((Date) null);
IModel<Date> customTo = Model.of((Date) null);

MidpointForm form = new MidpointForm(ID_FORM);
add(form);

WebMarkupContainer customValidity = new WebMarkupContainer(ID_CUSTOM_VALIDITY);
customValidity.add(new VisibleBehaviour(() -> RequestAccess.VALIDITY_CUSTOM_LENGTH.equals(validityModel.getObject())));
customValidity.setOutputMarkupId(true);
customValidity.setOutputMarkupPlaceholderTag(true);
add(customValidity);
form.add(customValidity);

Label customValidityInfo = new Label(ID_CUSTOM_VALIDITY_INFO);
customValidityInfo.add(new TooltipBehavior());
customValidity.add(customValidityInfo);

DateInput customValidFrom = new DateInput(ID_CUSTOM_VALIDITY_FROM, Model.of(new Date()));
DateInput customValidFrom = new DateInput(ID_CUSTOM_VALIDITY_FROM, customFrom);
customValidFrom.setOutputMarkupId(true);
customValidity.add(customValidFrom);

DateInput customValidTo = new DateInput(ID_CUSTOM_VALIDITY_TO, Model.of(new Date()));
DateInput customValidTo = new DateInput(ID_CUSTOM_VALIDITY_TO, customTo);
customValidTo.setOutputMarkupId(true);
customValidity.add(customValidTo);

form.add(new DateValidator(customValidFrom, customValidTo));
form.add(new AbstractFormValidator() {
@Override
public FormComponent<?>[] getDependentFormComponents() {
return new FormComponent[]{customValidFrom, customValidTo};
}

@Override
public void validate(Form<?> form) {
if (!isValidityRequired()) {
return;
}

Date from = customValidFrom.getConvertedInput();
Date to = customValidTo.getConvertedInput();
if (from == null && to == null) {
form.error(getString("CartSummaryPanel.validityEmpty"));
}
}
});

Label validityInfo = new Label(ID_VALIDITY_INFO);
validityInfo.add(new TooltipBehavior());
add(validityInfo);
form.add(validityInfo);

DropDownChoice validity = new DropDownChoice(ID_VALIDITY, validityModel, createValidityOptions(), (IChoiceRenderer) object -> {
if (RequestAccess.VALIDITY_CUSTOM_LENGTH.equals(object) || RequestAccess.VALIDITY_CUSTOM_FOR_EACH.equals(object)) {
Expand All @@ -191,22 +224,25 @@ public void setObject(Object object) {

return value.getDuration().toString();
});
validity.setNullValid(true);
validity.setLabel(createStringResource("ShoppingCartPanel.validity"));
validity.add(new VisibleBehaviour(() -> isValidityVisible()));
validity.add(new AjaxFormComponentUpdatingBehavior("change") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
target.add(customValidity);
}
});
add(validity);
form.add(validity);

Label commentInfo = new Label(ID_COMMENT_INFO);
commentInfo.add(new TooltipBehavior());
add(commentInfo);
form.add(commentInfo);

TextArea comment = new TextArea(ID_COMMENT, new PropertyModel(getModel(), "comment"));
comment.setLabel(createStringResource("ShoppingCartPanel.comment"));
comment.add(new VisibleBehaviour(() -> isCommentVisible()));
add(comment);
form.add(comment);

AjaxLink openConflict = new AjaxLink<>(ID_OPEN_CONFLICT) {
@Override
Expand All @@ -215,22 +251,49 @@ public void onClick(AjaxRequestTarget target) {
}
};
openConflict.add(new VisibleBehaviour(() -> getModelObject().getWarningCount() > 0 || getModelObject().getErrorCount() > 0));
add(openConflict);
form.add(openConflict);

FeedbackPanel messages = new FeedbackPanel(ID_MESSAGES);
messages.setOutputMarkupId(true);
messages.setOutputMarkupPlaceholderTag(true);
form.add(messages);

AjaxSubmitLink submit = new AjaxSubmitLink(ID_SUBMIT) {

AjaxLink submit = new AjaxLink<>(ID_SUBMIT) {
@Override
public void onClick(AjaxRequestTarget target) {
submitPerformed(target);
protected void onSubmit(AjaxRequestTarget target) {
submitPerformed(target, customFrom, customTo);
}

@Override
protected void onError(AjaxRequestTarget target) {
target.add(messages);
}
};
submit.add(new EnableBehaviour(() -> getModelObject().canSubmit()));
WebComponentUtil.addDisabledClassBehavior(submit);
add(submit);
form.add(submit);
}

protected void openConflictPerformed(AjaxRequestTarget target) {
}

private void submitPerformed(AjaxRequestTarget target, IModel<Date> customFrom, IModel<Date> customTo) {
RequestAccess access = getModelObject();

if (!RequestAccess.VALIDITY_CUSTOM_LENGTH.equals(access.getSelectedValidity())) {
submitPerformed(target);
return;
}

XMLGregorianCalendar from = XmlTypeConverter.createXMLGregorianCalendar(customFrom.getObject());
XMLGregorianCalendar to = XmlTypeConverter.createXMLGregorianCalendar(customTo.getObject());

access.setValidity(from, to);

submitPerformed(target);
}

protected void submitPerformed(AjaxRequestTarget target) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ public void clearCart() {
selectedAssignments.clear();
relation = null;

selectedValidity = null;
validity = null;

comment = null;

conflictsDirty = false;
Expand Down Expand Up @@ -622,7 +625,7 @@ public void setValidity(Duration validity) {
setValidity(from, to);
}

private void setValidity(XMLGregorianCalendar from, XMLGregorianCalendar to) {
public void setValidity(XMLGregorianCalendar from, XMLGregorianCalendar to) {
for (List<AssignmentType> list : requestItems.values()) {
list.forEach(a -> {
if (from == null && to == null) {
Expand Down

0 comments on commit 19a671d

Please sign in to comment.