Do požadavku na služební cestu byla přidána chybějící pole,

implementovaná validace formuláře.
Do BaseValidator byly přidány metody na obecnou validaci null/empty.
Do ListViewModel přidány metody pro dotažení lazy loadovaných dat.
closes #108
multitenant
Josef Rokos 10 years ago
parent b71f3a9bef
commit f2d9576a3f

@ -1,11 +1,21 @@
package info.bukova.isspst.data;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
@Entity
@Table(name = "TRIPREQUIREMENT")
public class TripRequirement extends RequirementBase {
@ -16,9 +26,20 @@ public class TripRequirement extends RequirementBase {
private String to;
@Column(name = "TRIP_DATE")
private Date tripDate;
@Column(name = "END")
private String end;
@Column(name = "END_DATE")
private Date endDate;
@ManyToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.TRUE)
@JoinTable(name="TRIPREQUIREMENT_PASSANGER", joinColumns={@JoinColumn(name="TRIPREQUIREMENT_ID")}, inverseJoinColumns={@JoinColumn(name="USER_ID")})
private List<User> passengers;
@Embedded
private Vehicle vehicle;
public TripRequirement() {
this.setOwnedBy(new User());
passengers = new ArrayList<User>();
}
public String getFrom() {
@ -45,4 +66,36 @@ public class TripRequirement extends RequirementBase {
this.tripDate = tripDate;
}
public String getEnd() {
return end;
}
public void setEnd(String end) {
this.end = end;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
public List<User> getPassengers() {
return passengers;
}
public void setPassengers(List<User> passengers) {
this.passengers = passengers;
}
public Vehicle getVehicle() {
return vehicle;
}
public void setVehicle(Vehicle vehicle) {
this.vehicle = vehicle;
}
}

@ -1,19 +1,15 @@
package info.bukova.isspst.services.requirement;
import java.util.List;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.User;
import info.bukova.isspst.services.Service;
import java.util.List;
public interface TripRequirementService extends Service<TripRequirement> {
public List<TripRequirement> getCentreReq();
public List<TripRequirement> getWorkgroupReq();
public List<TripRequirement> getFromAll();
public void loadAuthItems(TripRequirement entity);
public List<User> getNextApprover(TripRequirement entity);
public boolean canApprove(TripRequirement entity);
public void approve(TripRequirement entity);
public void loadPassangers(TripRequirement entity);
}

@ -92,5 +92,12 @@ public class TripRequirementServiceImpl extends RequirementBaseServiceImpl<TripR
return super.getAll();
}
@Override
@Transactional
public void loadPassangers(TripRequirement entity) {
TripRequirement e = dao.getById(entity.getId());
e.getPassengers().size();
entity.setPassengers(e.getPassengers());
}
}

@ -159,9 +159,14 @@ public class ListViewModel<T extends DataModel> {
selIndex = index;
}
editBean = service.getById(dataBean.getId());
loadLazyDataForEdit(editBean);
showForm();
}
protected void loadLazyDataForEdit(T data) {
}
@Command
@NotifyChange("confirmDelete")
public void delObject() {

@ -2,32 +2,82 @@ package info.bukova.isspst.ui.requirement;
import java.util.List;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zk.ui.select.annotation.WireVariable;
import info.bukova.isspst.data.SettingsData;
import info.bukova.isspst.data.TripRequirement;
import info.bukova.isspst.data.User;
import info.bukova.isspst.data.Workgroup;
import info.bukova.isspst.services.settings.GlobalSettingsService;
import info.bukova.isspst.services.users.UserService;
import info.bukova.isspst.services.workgroups.WorkgroupService;
import info.bukova.isspst.ui.FormViewModel;
import info.bukova.isspst.validators.TripRequirementFormValidator;
public class TripRequirementForm extends FormViewModel<TripRequirement> {
@WireVariable
private UserService userService;
@WireVariable
private WorkgroupService workgroupService;
@WireVariable
private GlobalSettingsService settingsService;
private List<Workgroup> centres;
private List<User> users;
private List<User> passengers;
private User selUser;
private TripRequirementFormValidator validator;
@Init(superclass = true)
public void init() {
centres = workgroupService.getUserCentres(userService.getCurrent());
users = userService.getAll();
passengers = getDataBean().getPassengers();
validator = new TripRequirementFormValidator();
}
@Command
@NotifyChange("passengers")
public void addPassanger() {
getDataBean().getPassengers().add(selUser);
}
@Command
@NotifyChange("passengers")
public void removePassanger(@BindingParam("user") User user) {
getDataBean().getPassengers().remove(user);
}
public List<Workgroup> getCentres() {
return centres;
}
public List<User> getUsers() {
return users;
}
public User getSelUser() {
return selUser;
}
public void setSelUser(User selUser) {
this.selUser = selUser;
}
public SettingsData getSettings() {
return settingsService.getSettings();
}
public TripRequirementFormValidator getValidator() {
return validator;
}
public List<User> getPassengers() {
return passengers;
}
}

@ -76,4 +76,9 @@ public class TripRequirementList extends ListViewModel<TripRequirement> {
return myCentres;
}
@Override
protected void loadLazyDataForEdit(TripRequirement data) {
tripRequirementService.loadPassangers(data);
}
}

@ -3,6 +3,7 @@ package info.bukova.isspst.validators;
import info.bukova.isspst.StringUtils;
import org.slf4j.Logger;
import org.zkoss.bind.Property;
import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.validator.AbstractValidator;
import org.zkoss.zk.ui.Component;
@ -60,8 +61,37 @@ public abstract class BaseValidator extends AbstractValidator
this.errorMsg(ctx, msg, null);
}
@Override
public void validate(ValidationContext ctx)
protected boolean validateIsNotNull(ValidationContext ctx, String property, String errMessage, String componentId)
{
Property prop = ctx.getProperties(property)[0];
Object value = prop.getValue();
if (value == null)
{
this.errorMsg(ctx, StringUtils.localize(errMessage), componentId);
return false;
}
return true;
}
protected boolean validateIsNotNullOrNotEmpty(ValidationContext ctx, String property, String errMessage, String componentId)
{
Property prop = ctx.getProperties(property)[0];
Object value = prop.getValue();
if (value == null)
{
this.errorMsg(ctx, StringUtils.localize(errMessage), componentId);
return false;
}
if ((value instanceof String) && ((String)value).isEmpty())
{
this.errorMsg(ctx, StringUtils.localize(errMessage), componentId);
return false;
}
return true;
}
}

@ -0,0 +1,52 @@
package info.bukova.isspst.validators;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zkoss.bind.ValidationContext;
public class TripRequirementFormValidator extends BaseValidator {
private final static Logger log = LoggerFactory.getLogger(TripRequirementFormValidator.class);
@Override
protected Logger getLogger()
{
return log;
}
@Override
public void validate(ValidationContext ctx) {
if (!this.validateIsNotNull(ctx, "centre", "RequirementCenterIsEmpty", null))
{
return;
}
if (!this.validateIsNotNull(ctx, "tripDate", "TripDateIsEmpty", null))
{
return;
}
if (!this.validateIsNotNull(ctx, "endDate", "EndDateIsEmpty", null))
{
return;
}
if (!this.validateIsNotNullOrNotEmpty(ctx, "from", "FromIsEmpty", null))
{
return;
}
if (!this.validateIsNotNullOrNotEmpty(ctx, "to", "ToIsEmpty", null))
{
return;
}
if (!this.validateIsNotNull(ctx, "vehicle", "VehicleIsEmpty", null))
{
return;
}
}
}

@ -4,3 +4,8 @@ DataTypeErr=Chybný datový typ...
UserPasswordIsEmpty=Uživatelské heslo musí být zadané...
UserPasswordsAreNotSame=Znovu zadané heslo není stejné...
RequirementCenterIsEmpty=Musíte zadat středisko...
TripDateIsEmpty=Musíte zadat datum cesty...
EndDateIsEmpty=Musíte zadat datum konce cesty...
FromIsEmpty=Musíte zadat místo začátku cesty...
ToIsEmpty=Musíte zadat cíl cesty...
VehicleIsEmpty=Musíte zadat dopravní prostředek...

@ -11,7 +11,7 @@
src="/img/reqact.png"
zclass="form-caption"
label="${labels.RequirementsFormTitle}" />
<vlayout>
<vlayout form="@id('fx') @load(vm.dataBean) @save(vm.dataBean, before='save') @validator(vm.validator)">
<grid hflex="min">
<columns>
<column
@ -25,9 +25,8 @@
<cell>
<textbox
id="numser"
constraint="@load(vm.constriant)"
width="200px"
value="@bind(vm.dataBean.numser)"
value="@bind(fx.numser)"
readonly="true" />
</cell>
</row>
@ -37,7 +36,7 @@
<datebox
id="reqDate"
width="200px"
value="@bind(vm.dataBean.reqDate)"
value="@bind(fx.reqDate)"
format="${labels.DateFormat}" />
</cell>
</row>
@ -47,7 +46,7 @@
<combobox
model="@load(vm.centres)"
readonly="true"
selectedItem="@bind(vm.dataBean.centre)">
selectedItem="@bind(fx.centre)">
<template name="model">
<comboitem label="@load(each.fullName)" />
</template>
@ -60,7 +59,25 @@
<textbox
id="from"
width="300px"
value="@bind(vm.dataBean.from)" />
value="@bind(fx.from)" />
</cell>
</row>
<row>
<cell sclass="row-title">${labels.RequirementsFormStartDateTime} :</cell>
<cell>
<hbox>
<datebox
id="tripDate"
width="200px"
format="medium"
value="@bind(fx.tripDate)" />
<timebox
id="tripTime"
width="90px"
format="short"
value="@bind(fx.tripDate)" />
</hbox>
</cell>
</row>
<row>
@ -69,7 +86,7 @@
<textbox
id="to"
width="300px"
value="@bind(vm.dataBean.to)" />
value="@bind(fx.to)" />
</cell>
</row>
<row>
@ -78,12 +95,72 @@
<textbox
id="description"
width="300px"
value="@bind(vm.dataBean.description)" />
value="@bind(fx.description)" />
</cell>
</row>
<row>
<cell sclass="row-title">${labels.RequirementsFormEndTravel} :</cell>
<cell>
<textbox
id="end"
width="200px"
value="@bind(fx.end)" />
</cell>
</row>
<row>
<cell sclass="row-title">${labels.RequirementsFormEndDate} :</cell>
<cell>
<datebox
id="endDate"
width="300px"
format="medium"
value="@bind(fx.endDate)" />
</cell>
</row>
</rows>
</grid>
<vbox>
<label value="${labels.RequirementsFormPassengers}"/>
<hbox>
<combobox model="@load(vm.users)"
autocomplete="true"
selectedItem="@bind(vm.selUser)">
<template name="model">
<comboitem label="@load(each)"/>
</template>
</combobox>
<button label="${labels.AddItem}"
onClick="@command('addPassanger')"
sclass="nicebutton"
disabled="@load(vm.selUser eq null)"/>
</hbox>
<grid model="@load(vm.passengers)" width="700px">
<columns>
<column/>
<column/>
</columns>
<rows>
<template name="model">
<row>
<label value="@load(each)"/>
<button label="${labels.RemoveItem}"
onClick="@command('removePassanger', user=each)"
sclass="nicebutton"/>
</row>
</template>
</rows>
</grid>
<hbox>
<label value="${labels.RequirementsFormVehicle}"/>
<combobox model="@load(vm.settings.vehicles)"
selectedItem="@bind(fx.vehicle)"
readonly="true">
<template name="model">
<comboitem label="@load(each)"/>
</template>
</combobox>
</hbox>
</vbox>
<include src="/app/formButtons.zul" />
</vlayout>
</window>

Loading…
Cancel
Save