diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ViewSwitcher.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ViewSwitcher.java index 4da903978..b502acdfa 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ViewSwitcher.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/ViewSwitcher.java @@ -26,6 +26,7 @@ import java.util.Map; import org.navalplanner.web.planner.allocation.AdvancedAllocationController; import org.navalplanner.web.planner.allocation.AllocationResult; +import org.navalplanner.web.planner.allocation.AdvancedAllocationController.IAdvanceAllocationResultReceiver; import org.navalplanner.web.resourceload.ResourceLoadController; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; @@ -53,18 +54,21 @@ public class ViewSwitcher implements Composer { isInPlanningOrder = true; } - public void goToAdvancedAllocation(AllocationResult allocationResult) { + public void goToAdvancedAllocation(AllocationResult allocationResult, + IAdvanceAllocationResultReceiver resultReceiver) { planningOrder = ComponentsReplacer.replaceAllChildren(parent, - "advance_allocation.zul", - createArgsForAdvancedAllocation(allocationResult)); + "advance_allocation.zul", createArgsForAdvancedAllocation( + allocationResult, resultReceiver)); isInPlanningOrder = false; } private Map createArgsForAdvancedAllocation( - AllocationResult allocationResult) { + AllocationResult allocationResult, + IAdvanceAllocationResultReceiver resultReceiver) { Map result = new HashMap(); result.put("advancedAllocationController", - new AdvancedAllocationController(this, allocationResult)); + new AdvancedAllocationController(this, allocationResult, + resultReceiver)); return result; } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java index ca064fd70..442d7b2a8 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationController.java @@ -47,6 +47,12 @@ import org.zkoss.zul.api.Column; public class AdvancedAllocationController extends GenericForwardComposer { + public interface IAdvanceAllocationResultReceiver { + public void accepted(AllocationResult modifiedAllocationResult); + + public void cancel(); + } + private Div insertionPointTimetracker; private Div insertionPointLeftPanel; private Div insertionPointRightPanel; @@ -58,11 +64,14 @@ public class AdvancedAllocationController extends private TimeTrackedTable table; private final ViewSwitcher switcher; private final AllocationResult allocationResult; + private final IAdvanceAllocationResultReceiver resultReceiver; public AdvancedAllocationController(ViewSwitcher switcher, - AllocationResult allocationResult) { + AllocationResult allocationResult, + IAdvanceAllocationResultReceiver resultReceiver) { this.switcher = switcher; this.allocationResult = allocationResult; + this.resultReceiver = resultReceiver; } @Override @@ -94,15 +103,13 @@ public class AdvancedAllocationController extends } public void onClick$acceptButton() { - backToPreviousButton(); + switcher.goToPlanningOrderView(); + resultReceiver.accepted(allocationResult); } public void onClick$cancelButton() { - backToPreviousButton(); - } - - private void backToPreviousButton() { switcher.goToPlanningOrderView(); + resultReceiver.cancel(); } public void onClick$zoomIncrease() { diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java index 6493af1ef..c9eb98d86 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IResourceAllocationModel.java @@ -83,4 +83,6 @@ public interface IResourceAllocationModel { org.zkoss.ganttz.data.Task ganttTask, PlanningState planningState); + void accept(AllocationResult modifiedAllocationResult); + } diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java index 81745b838..6afe8a88d 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationController.java @@ -46,6 +46,7 @@ import org.navalplanner.web.common.Util; import org.navalplanner.web.common.ViewSwitcher; import org.navalplanner.web.common.components.WorkerSearch; import org.navalplanner.web.planner.PlanningState; +import org.navalplanner.web.planner.allocation.AdvancedAllocationController.IAdvanceAllocationResultReceiver; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; import org.zkoss.zk.ui.Component; @@ -318,10 +319,26 @@ public class ResourceAllocationController extends GenericForwardComposer { public void advanceAllocation() { AllocationResult allocationResult = allocationsBeingEdited .doAllocation(); - switcher.goToAdvancedAllocation(allocationResult); + switcher.goToAdvancedAllocation(allocationResult, + createResultReceiver()); window.setVisible(false); } + private IAdvanceAllocationResultReceiver createResultReceiver() { + return new IAdvanceAllocationResultReceiver() { + + @Override + public void cancel() { + showWindow(); + } + + @Override + public void accepted(AllocationResult modifiedAllocationResult) { + resourceAllocationModel.accept(modifiedAllocationResult); + } + }; + } + /** * Renders a {@link SpecificResourceAllocation} item * @author Diego Pino Garcia diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java index f2b0c47b7..e529bfe9c 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/ResourceAllocationModel.java @@ -103,9 +103,21 @@ public class ResourceAllocationModel implements IResourceAllocationModel { @Override @Transactional(readOnly = true) public void accept() { + stepsBeforeDoingAllocation(); + doTheAllocation(resourceAllocationsBeingEdited + .doAllocation()); + } + + @Override + @Transactional(readOnly = true) + public void accept(AllocationResult modifiedAllocationResult) { + stepsBeforeDoingAllocation(); + doTheAllocation(modifiedAllocationResult); + } + + private void stepsBeforeDoingAllocation() { planningState.reassociateResourcesWithSession(resourceDAO); removeDeletedAllocations(); - doTheAllocation(); } private void removeDeletedAllocations() { @@ -116,9 +128,7 @@ public class ResourceAllocationModel implements IResourceAllocationModel { } } - private void doTheAllocation() { - AllocationResult allocationResult = resourceAllocationsBeingEdited - .doAllocation(); + private void doTheAllocation(AllocationResult allocationResult) { allocationResult.applyTo(task); ganttTask.setEndDate(task.getEndDate()); }