Project copy(Project sourceEntity) throws JsonProcessingException;
void replace(Project targetEntity, Project replacementEntity);
+
+ boolean isInvalid(Project entity);
+
+ String toString(Project entity);
}
import com.fasterxml.jackson.databind.ObjectMapper;
import hu.user.lis.db.Partner;
import hu.user.lis.db.Project;
+import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.RandomStringUtils;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
+import java.util.Objects;
@Service
+@Log4j2
public class ProjectServiceImpl implements ProjectService {
private List<Project> entities;
@Autowired
}
return result;
}
+
+ @Override
+ public boolean isInvalid(Project entity) {
+ if (StringUtils.isBlank(entity.getName())) {
+ return true;
+ }
+ if (StringUtils.isBlank(entity.getContactName())) {
+ return true;
+ }
+ if (Objects.isNull(entity.getPartner())) {
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String toString(Project entity) {
+ ObjectMapper mapper = new ObjectMapper();
+ try {
+ return mapper.writeValueAsString(entity);
+ } catch (JsonProcessingException e) {
+ log.catching(e);
+ }
+ return null;
+ }
}
@Component
@Log4j2
-public class PartnersSelectorDataModel extends CachedDataModel<Partner> {
+public class PartnerSelectorDataModel extends CachedDataModel<Partner> {
static private final int SEARCH_LIMIT = 10;
private String partialName;
@Autowired
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.zkoss.bind.BindUtils;
+import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
+import org.zkoss.bind.validator.AbstractValidator;
+import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;
import org.zkoss.zul.Window;
+import java.util.Objects;
+
@Log4j2
@Getter
@Setter
@VariableResolver(DelegatingVariableResolver.class)
-public class PartnerEditorModel {
- private Partner selectedPartner;
+public class PartnerEditorModel extends AbstractValidator {
+ private Partner formDocument;
+ private boolean formInvalid;
@Init
public void init() {
log.info("Initialized");
- selectedPartner = (Partner) Executions.getCurrent().getArg().get("formDocument");
+ formDocument = (Partner) Executions.getCurrent().getArg().get("formDocument");
}
@Command
public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("select") boolean select) {
- Event closeEvent = new Event("onClose", target, select ? selectedPartner : null);
+ if (select && formInvalid) {
+ return;
+ }
+ Event closeEvent = new Event("onClose", target, select ? formDocument : null);
Events.postEvent(closeEvent);
}
+ @Override
+ public void validate(ValidationContext ctx) {
+ Component target = ctx.getBindContext().getComponent();
+ String property = ctx.getProperty().getProperty();
+ Object value = ctx.getProperty().getValue();
+ log.info("Validating caused by {} {} {}", target.getId(), property, value);
+ boolean invalid = Objects.isNull(value) || StringUtils.isBlank(Objects.toString(value));
+ setFormInvalid(invalid);
+ BindUtils.postNotifyChange(this, "formInvalid");
+ }
}
import hu.user.lis.db.Partner;
import hu.user.lis.db.Project;
-import hu.user.lis.ui.data.PartnersSelectorDataModel;
+import hu.user.lis.ui.data.PartnerSelectorDataModel;
+import hu.user.lis.ui.data.ProjectsDataModel;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
import org.zkoss.bind.BindContext;
import org.zkoss.bind.BindUtils;
+import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.annotation.*;
+import org.zkoss.bind.validator.AbstractValidator;
+import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.spring.DelegatingVariableResolver;
import org.zkoss.zul.Window;
+import java.util.Objects;
+
@Log4j2
@Getter
@Setter
@VariableResolver(DelegatingVariableResolver.class)
-public class ProjectEditorModel {
+public class ProjectEditorModel extends AbstractValidator {
private Project formDocument;
private Partner selectedPartner;
@WireVariable
- PartnersSelectorDataModel partnersSelectorDataModel;
+ private PartnerSelectorDataModel partnerSelectorDataModel;
+ @WireVariable
+ private ProjectsDataModel projectsDataModel;
+ private boolean formInvalid;
@Init
public void init() {
log.info("Initialized");
formDocument = (Project) Executions.getCurrent().getArg().get("formDocument");
selectedPartner = formDocument.getPartner();
- partnersSelectorDataModel.clearSelection();
+ partnerSelectorDataModel.clearSelection();
}
@Command
public void onCloseWindow(@BindingParam("target") Window target, @BindingParam("select") boolean select) {
+ if (select && formInvalid) {
+ return;
+ }
Event closeEvent = new Event("onClose", target, select ? formDocument : null);
Events.postEvent(closeEvent);
}
public void onPartnerBandChanging(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
InputEvent event = (InputEvent) ctx.getTriggerEvent();
log.info("onPartnerBandChanging: {}", event.getValue());
- partnersSelectorDataModel.search(event.getValue());
+ partnerSelectorDataModel.search(event.getValue());
}
@Command
public void onPartnerBandOpen(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
OpenEvent event = (OpenEvent) ctx.getTriggerEvent();
log.info("onPartnerBandOpen: {}", event.isOpen());
- partnersSelectorDataModel.search(null);
+ partnerSelectorDataModel.search(null);
}
@Command
suppliersWindow.addEventListener("onClose", e -> {
log.info("Suppliers popup result {}", e.getData());
if (e.getData() != null) {
- partnersSelectorDataModel.clearSelection();
+ partnerSelectorDataModel.clearSelection();
//setSelectedSupplierId(((Supplier) e.getData()).getId());
BindUtils.postNotifyChange(null, null, this, "selectedSupplierId");
}
formDocument.setPartner(selectedPartner);
}
+ @Override
+ public void validate(ValidationContext ctx) {
+ Component target = ctx.getBindContext().getComponent();
+ String property = ctx.getProperty().getProperty();
+ Object value = ctx.getProperty().getValue();
+ log.info("Validating caused by {} {} {}", target.getId(), property, value);
+ boolean invalid = Objects.isNull(value) || StringUtils.isBlank(Objects.toString(value));
+ setFormInvalid(invalid);
+ BindUtils.postNotifyChange(this, "formInvalid");
+ }
}
<?component name="partners" inline="true" macroURI="~./partners.zul"?>
<?component name="projects" inline="true" macroURI="~./projects.zul"?>
<zk>
+ <style>
+ .z-window-header {
+ font-size: 18px;
+ font-weight: bolder;
+ }
+ </style>
<window vflex="true" viewModel="@id('vm') @init('hu.user.lis.ui.view.IndexViewModel')">
<caption>
<hlayout valign="middle">
</attribute>
<bandpopup>
<listbox id="bd-list" height="250px" width="450px"
- model="@bind(vm.partnersSelectorDataModel)"
- selectedItem="@bind(vm.selectedPartner)"
+ model="@bind(vm.partnerSelectorDataModel)"
+ selectedItem="@bind(vm.selectedPartner) @validator(vm)"
onClick="bd.close()"
onDoubleClick="bd.close()">
<listhead visible="false">
</listbox>
</bandpopup>
</bandbox>
- <button iconSclass="z-icon-search-plus" onClick="@command('onPopupPartners')"/>
+ <!-- <button iconSclass="z-icon-search-plus" onClick="@command('onPopupPartners')"/>-->
</hlayout>
</zk>
\ No newline at end of file
<center border="none" vflex="true" hflex="true">
<vlayout hflex="true">
<label value="Név"/>
- <textbox hflex="true" instant="true" value="@bind(vm.selectedPartner.name)"
+ <textbox hflex="true" instant="true" value="@bind(vm.formDocument.name) @validator(vm)"
forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
<label value="Adószám"/>
- <textbox hflex="true" instant="true" value="@bind(vm.selectedPartner.vatNr)"
+ <textbox hflex="true" instant="true" value="@bind(vm.formDocument.vatNr) @validator(vm)"
forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
<label value="Cím"/>
- <textbox hflex="true" instant="true" value="@bind(vm.selectedPartner.address)"
+ <textbox hflex="true" instant="true" value="@bind(vm.formDocument.address) @validator(vm)"
forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
<label value="Aktív"/>
- <checkbox mold="switch" checked="@bind(vm.selectedPartner.active)"/>
+ <checkbox mold="switch" checked="@bind(vm.formDocument.active)"/>
</vlayout>
</center>
<south flex="true" style="text-align: right; padding: 10px">
<button id="cancel" label="Bezár"
onClick="@command('onCloseWindow', target=partnerPopup, select=false)"/>
<button id="submit" label="Mentés"
- onClick="@command('onCloseWindow', target=partnerPopup, select=true)"/>
+ onClick="@command('onCloseWindow', target=partnerPopup, select=true)"
+ disabled="@bind(vm.formInvalid)"/>
</hlayout>
</south>
</borderlayout>
<center border="none" vflex="true" hflex="true">
<vlayout hflex="true">
<label value="Azonosító"/>
- <textbox hflex="true" instant="true" value="@bind(vm.formDocument.humanId)" readonly="true"
+ <textbox hflex="true" instant="true"
+ value="@bind(vm.formDocument.humanId) @validator(vm)"
+ readonly="true"
forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
<label value="Név"/>
- <textbox hflex="true" instant="true" value="@bind(vm.formDocument.name)"
+ <textbox hflex="true" instant="true"
+ value="@bind(vm.formDocument.name) @validator(vm)"
forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
<label value="Kapcsolattartó"/>
- <textbox hflex="true" instant="true" value="@bind(vm.formDocument.contactName)"
+ <textbox hflex="true" instant="true"
+ value="@bind(vm.formDocument.contactName) @validator(vm)"
forward="onOK=submit.onClick, onCancel=cancel.onClick"/>
<label value="Partner"/>
<partner-selector/>
<button id="cancel" label="Bezár"
onClick="@command('onCloseWindow', target=currentPopup, select=false)"/>
<button id="submit" label="Mentés"
- onClick="@command('onCloseWindow', target=currentPopup, select=true)"/>
+ onClick="@command('onCloseWindow', target=currentPopup, select=true)"
+ disabled="@bind(vm.formInvalid)"/>
</hlayout>
</south>
</borderlayout>