From 73bf178cd0e9030d714c183091f86f9057973a8b Mon Sep 17 00:00:00 2001 From: Mihai Postelnicu Date: Mon, 14 Oct 2019 14:51:17 +0300 Subject: [PATCH] OCMAKU-360 Procurement plan items not filtering --- .../wicket/components/ListViewSectionPanel.java | 15 +++++++++++++++ .../page/edit/AbstractEditStatusEntityPage.java | 6 +++++- .../wicket/page/edit/panel/PlanItemPanel.java | 14 ++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/ListViewSectionPanel.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/ListViewSectionPanel.java index 79b35e35d..04bec557a 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/ListViewSectionPanel.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/components/ListViewSectionPanel.java @@ -6,9 +6,12 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.ladda.LaddaAjaxButton; import org.apache.wicket.AttributeModifier; import org.apache.wicket.Component; +import org.apache.wicket.Page; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.markup.html.AjaxLink; +import org.apache.wicket.event.Broadcast; import org.apache.wicket.event.IEvent; +import org.apache.wicket.event.IEventSink; import org.apache.wicket.feedback.ComponentFeedbackMessageFilter; import org.apache.wicket.markup.html.TransparentWebMarkupContainer; import org.apache.wicket.markup.html.WebMarkupContainer; @@ -24,6 +27,8 @@ import org.devgateway.toolkit.forms.wicket.components.form.BootstrapAddButton; import org.devgateway.toolkit.forms.wicket.components.form.BootstrapDeleteButton; import org.devgateway.toolkit.forms.wicket.components.util.ComponentUtil; +import org.devgateway.toolkit.forms.wicket.events.EditingDisabledEvent; +import org.devgateway.toolkit.forms.wicket.page.edit.AbstractEditStatusEntityPage; import org.devgateway.toolkit.persistence.dao.AbstractAuditableEntity; import org.devgateway.toolkit.persistence.dao.ListViewItem; import org.slf4j.Logger; @@ -61,6 +66,14 @@ public ListViewSectionPanel(final String id) { super(id); } + protected void checkAndSendEventForDisableEditing(IEventSink sink) { + Page page = getPage(); + if (page instanceof AbstractEditStatusEntityPage && ((AbstractEditStatusEntityPage) page) + .isDisableEditingEvent()) { + send(sink, Broadcast.BREADTH, new EditingDisabledEvent()); + } + } + @Override protected void onInitialize() { super.onInitialize(); @@ -145,6 +158,8 @@ protected void populateItem(final ListItem item) { populateCompoundListItem(item); addAcordion(item); + + checkAndSendEventForDisableEditing(item); } }; diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.java index 527b884ac..5e034b1b6 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/AbstractEditStatusEntityPage.java @@ -277,11 +277,15 @@ private boolean isViewMode() { } protected void checkAndSendEventForDisableEditing() { - if (!Strings.isEqual(editForm.getModelObject().getStatus(), DBConstants.Status.DRAFT) || isViewMode()) { + if (isDisableEditingEvent()) { send(getPage(), Broadcast.BREADTH, new EditingDisabledEvent()); } } + public boolean isDisableEditingEvent() { + return !Strings.isEqual(editForm.getModelObject().getStatus(), DBConstants.Status.DRAFT) || isViewMode(); + } + private void addAutosaveLabel() { autoSaveLabel = new Label("autoSaveLabel", new StringResourceModel("autoSaveLabelMessage", this).setParameters(settingsUtils.getAutosaveTime())); diff --git a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/panel/PlanItemPanel.java b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/panel/PlanItemPanel.java index ce110c65e..46068b1e9 100644 --- a/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/panel/PlanItemPanel.java +++ b/forms/src/main/java/org/devgateway/toolkit/forms/wicket/page/edit/panel/PlanItemPanel.java @@ -4,6 +4,7 @@ import org.apache.wicket.Component; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; +import org.apache.wicket.event.IEvent; import org.apache.wicket.feedback.FeedbackMessages; import org.apache.wicket.markup.html.list.ListItem; import org.apache.wicket.markup.html.panel.GenericPanel; @@ -27,6 +28,7 @@ import org.devgateway.toolkit.forms.wicket.components.form.Select2ChoiceBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.form.TextFieldBootstrapFormComponent; import org.devgateway.toolkit.forms.wicket.components.util.ComponentUtil; +import org.devgateway.toolkit.forms.wicket.providers.GenericPersistableJpaTextChoiceProvider; import org.devgateway.toolkit.persistence.dao.categories.Item; import org.devgateway.toolkit.persistence.dao.form.PlanItem; import org.devgateway.toolkit.persistence.dao.form.ProcurementPlan; @@ -306,10 +308,18 @@ private class PlanItemFilterPanel extends GenericPanel { protected void onInitialize() { super.onInitialize(); - final Select2ChoiceBootstrapFormComponent filterItem = - ComponentUtil.addSelect2ChoiceField(this, "filterItem", itemService); + final GenericPersistableJpaTextChoiceProvider choiceProvider + = new GenericPersistableJpaTextChoiceProvider<>(itemService); + + final Select2ChoiceBootstrapFormComponent filterItem = new Select2ChoiceBootstrapFormComponent( + "filterItem", choiceProvider) { + @Override + public void onEvent(IEvent event) { + } + }; filterItem.getField().add(new AjaxComponentUpdatingBehavior("change")); + this.add(filterItem); } private class AjaxComponentUpdatingBehavior extends AjaxFormComponentUpdatingBehavior {