diff --git a/src/main/java/info/bukova/isspst/data/RequirementType.java b/src/main/java/info/bukova/isspst/data/RequirementType.java index ce5b3a88..af399193 100644 --- a/src/main/java/info/bukova/isspst/data/RequirementType.java +++ b/src/main/java/info/bukova/isspst/data/RequirementType.java @@ -6,6 +6,9 @@ import java.util.List; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.JoinTable; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; import javax.persistence.OneToMany; import javax.persistence.OrderBy; import javax.persistence.Table; @@ -25,9 +28,16 @@ public class RequirementType extends BaseData { @LazyCollection(LazyCollectionOption.FALSE) @OrderBy("CENTRE, WORDER") private List workflow; + @Column(name = "LIMIT_CENTRES") + private Boolean limitCentres; + @ManyToMany + @LazyCollection(LazyCollectionOption.FALSE) + @JoinTable(name="REQUIREMENTTYPE_WORKGROUP", joinColumns={@JoinColumn(name="REQUIREMENTTYPE_ID")}, inverseJoinColumns={@JoinColumn(name="WORKGROUP_ID")}) + private List offeredCentres; public RequirementType() { workflow = new ArrayList(); + offeredCentres = new ArrayList(); } public RequirementType(String type, String description) { @@ -68,4 +78,20 @@ public class RequirementType extends BaseData { return false; } + public Boolean getLimitCentres() { + return limitCentres; + } + + public void setLimitCentres(Boolean limitCentres) { + this.limitCentres = limitCentres; + } + + public List getOfferedCentres() { + return offeredCentres; + } + + public void setOfferedCentres(List offeredCentres) { + this.offeredCentres = offeredCentres; + } + } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java index cfbf4104..1db54348 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeService.java @@ -1,10 +1,14 @@ package info.bukova.isspst.services.requirement; import info.bukova.isspst.data.RequirementType; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.Service; +import java.util.List; + public interface RequirementTypeService extends Service { public RequirementType getTypeById(String id); + public List filterCentres(RequirementType reqType, List source); } diff --git a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java index c48d6501..62de731d 100644 --- a/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java +++ b/src/main/java/info/bukova/isspst/services/requirement/RequirementTypeServiceImpl.java @@ -1,8 +1,12 @@ package info.bukova.isspst.services.requirement; +import java.util.ArrayList; +import java.util.List; + import org.springframework.transaction.annotation.Transactional; import info.bukova.isspst.data.RequirementType; +import info.bukova.isspst.data.Workgroup; import info.bukova.isspst.services.AbstractOwnedService; public class RequirementTypeServiceImpl extends AbstractOwnedService implements RequirementTypeService { @@ -13,4 +17,23 @@ public class RequirementTypeServiceImpl extends AbstractOwnedService filterCentres(RequirementType reqType, + List source) { + + if (!reqType.getLimitCentres()) { + return source; + } + + List filtered = new ArrayList(); + + for (Workgroup wg : source) { + if (reqType.getOfferedCentres().contains(wg)) { + filtered.add(wg); + } + } + + return filtered; + } + } diff --git a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java index 7b353114..794d0d7b 100644 --- a/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/main/orders/requirements/RequirementForm.java @@ -5,6 +5,7 @@ import info.bukova.isspst.data.Requirement; import info.bukova.isspst.data.RequirementItem; import info.bukova.isspst.data.RequirementSubject; import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.requirement.RequirementTypeService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; import info.bukova.isspst.ui.BigDecimalConverter; @@ -36,6 +37,9 @@ public class RequirementForm extends FormViewModel @WireVariable private WorkgroupService workgroupService; + + @WireVariable + private RequirementTypeService reqTypeService; private RequirementItem selectedItem; @@ -46,10 +50,12 @@ public class RequirementForm extends FormViewModel private RequirementFormValidator requirementFormValidator; private List syncItems; + + private List centres; public List getCentres() { - return workgroupService.getUserCentres(userService.getCurrent()); + return centres; } public RequirementItem getSelectedItem() @@ -91,7 +97,7 @@ public class RequirementForm extends FormViewModel { this.requirementFormValidator = requirementFormValidator; } - + @Init(superclass = true) public void init() { @@ -99,6 +105,7 @@ public class RequirementForm extends FormViewModel this.setBigDecimalConverter(new BigDecimalConverter()); this.setRequirementFormValidator(new RequirementFormValidator()); this.setSyncItems(this.getDataBean().getItems()); + this.centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); } public List getSyncItems() diff --git a/src/main/java/info/bukova/isspst/ui/requirement/OfferedCentresVM.java b/src/main/java/info/bukova/isspst/ui/requirement/OfferedCentresVM.java new file mode 100644 index 00000000..0d6de93c --- /dev/null +++ b/src/main/java/info/bukova/isspst/ui/requirement/OfferedCentresVM.java @@ -0,0 +1,49 @@ +package info.bukova.isspst.ui.requirement; + +import org.zkoss.bind.annotation.BindingParam; +import org.zkoss.bind.annotation.Command; +import org.zkoss.bind.annotation.ExecutionArgParam; +import org.zkoss.bind.annotation.Init; +import org.zkoss.zk.ui.select.annotation.WireVariable; +import org.zkoss.zul.Window; + +import info.bukova.isspst.data.RequirementType; +import info.bukova.isspst.data.Workgroup; +import info.bukova.isspst.services.workgroups.WorkgroupService; +import info.bukova.isspst.ui.ListChecks; + +public class OfferedCentresVM { + + private RequirementType selectedType; + @WireVariable + private WorkgroupService workgroupService; + private ListChecks wgChecks; + + @Init + public void init(@ExecutionArgParam("type") RequirementType type) { + this.selectedType = type; + wgChecks = new ListChecks(selectedType.getOfferedCentres(), workgroupService.getCentres()); + } + + @Command + public void save(@BindingParam("window") Window window) { + window.detach(); + } + + public boolean isCanSave() { + return true; + } + + public RequirementType getSelectedType() { + return selectedType; + } + + public void setSelectedType(RequirementType selectedType) { + this.selectedType = selectedType; + } + + public ListChecks getWgChecks() { + return wgChecks; + } + +} diff --git a/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java b/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java index 597ecdd8..279b8e7d 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/RequirementTypesVM.java @@ -242,6 +242,23 @@ public class RequirementTypesVM { public void refresh() { reqTypeService.update(selected); } + + @Command + public void centresDialog() { + Map param = new HashMap(); + param.put("type", selected); + Window win = (Window) Executions.createComponents("/settings/workflow/offeredCentres.zul", null, param); + win.doModal(); + } + + @Command + @NotifyChange("selected") + public void clearCentres() { + if (!selected.getLimitCentres()) { + selected.getOfferedCentres().clear(); + refresh(); + } + } public Workflow getWgSelWorkflow() { return wgSelWorkflow; diff --git a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java index 49eb8deb..872a9cc1 100644 --- a/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java +++ b/src/main/java/info/bukova/isspst/ui/requirement/TripRequirementForm.java @@ -12,6 +12,7 @@ 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.requirement.RequirementTypeService; import info.bukova.isspst.services.settings.GlobalSettingsService; import info.bukova.isspst.services.users.UserService; import info.bukova.isspst.services.workgroups.WorkgroupService; @@ -26,6 +27,8 @@ public class TripRequirementForm extends FormViewModel { private WorkgroupService workgroupService; @WireVariable private GlobalSettingsService settingsService; + @WireVariable + private RequirementTypeService reqTypeService; private List centres; private List users; private List passengers; @@ -34,7 +37,7 @@ public class TripRequirementForm extends FormViewModel { @Init(superclass = true) public void init() { - centres = workgroupService.getUserCentres(userService.getCurrent()); + centres = reqTypeService.filterCentres(getDataBean().getType(), workgroupService.getUserCentres(userService.getCurrent())); users = userService.getAll(); passengers = getDataBean().getPassengers(); validator = new TripRequirementFormValidator(); diff --git a/src/main/webapp/WEB-INF/locales/zk-label.properties b/src/main/webapp/WEB-INF/locales/zk-label.properties index 18a249c0..0dcbb8ae 100644 --- a/src/main/webapp/WEB-INF/locales/zk-label.properties +++ b/src/main/webapp/WEB-INF/locales/zk-label.properties @@ -137,6 +137,10 @@ CentreWorkflow=Schválení ve středisku LimitFormTitle=Limit pro schválení Limit=Limit: OverLimit=Pouze nadlimitní +Centres=Střediska +OfferSelectedOnly=Nabízet pouze vybraná střediska +Select=Vybrat +OfferedCentres=Nabízená střediska Number=Číslo: Prefix=Prefix: diff --git a/src/main/webapp/settings/workflow/offeredCentres.zul b/src/main/webapp/settings/workflow/offeredCentres.zul new file mode 100644 index 00000000..d3bbb96d --- /dev/null +++ b/src/main/webapp/settings/workflow/offeredCentres.zul @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/settings/workflow/workflow.zul b/src/main/webapp/settings/workflow/workflow.zul index 663b06bd..8dde8362 100644 --- a/src/main/webapp/settings/workflow/workflow.zul +++ b/src/main/webapp/settings/workflow/workflow.zul @@ -13,6 +13,24 @@ + + + + +