Add previous and next buttons on monthly timesheet

FEA: ItEr76S28UserDashboard
This commit is contained in:
Manuel Rego Casasnovas 2012-05-29 18:47:56 +02:00
parent 06d8bca18f
commit 4ef953883b
4 changed files with 105 additions and 2 deletions

View file

@ -77,7 +77,9 @@ public interface IMonthlyTimesheetModel {
/**
* Sets the {@link EffortDuration} in the current monthly timesheet for the
* specified <code>orderElement</code> and <code>date</code>.
* specified <code>orderElement</code> and <code>date</code>.<br />
*
* Marks the current monthly timesheet as modified.
*/
void setEffortDuration(OrderElement orderElement, LocalDate date,
EffortDuration effortDuration);
@ -128,4 +130,22 @@ public interface IMonthlyTimesheetModel {
*/
Order getOrder(OrderElement orderElement);
}
/**
* Returns <code>true</code> if current monthly timesheet has been modified
* by the user.
*/
boolean isModified();
/**
* Checks if current monthly timesheet is the first month, that means the
* first activation period of the resource.
*/
boolean isFirstMonth();
/**
* Checks if current monthly timesheet is the last month, that means the
* next month of current date.
*/
boolean isLastMonth();
}

View file

@ -25,12 +25,16 @@ import static org.libreplan.web.planner.tabs.MultipleTabsPlannerController.BREAD
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.libreplan.business.orders.entities.OrderElement;
import org.libreplan.business.workingday.EffortDuration;
import org.libreplan.web.common.Util;
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
import org.libreplan.web.common.entrypoints.EntryPointsHandler;
import org.libreplan.web.common.entrypoints.EntryPointsHandler.ICapture;
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
import org.libreplan.web.users.services.CustomTargetUrlResolver;
import org.springframework.util.Assert;
@ -38,6 +42,7 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Cell;
import org.zkoss.zul.Column;
import org.zkoss.zul.Columns;
@ -69,6 +74,13 @@ public class MonthlyTimesheetController extends GenericForwardComposer
private BandboxSearch orderElementBandboxSearch;
private Button previousMonth;
private Button nextMonth;
@Resource
private IMonthlyTimesheetController monthlyTimesheetController;
private RowRenderer rowRenderer = new RowRenderer() {
private LocalDate first;
@ -412,6 +424,43 @@ public class MonthlyTimesheetController extends GenericForwardComposer
}
}
public boolean isFirstMonth() {
return monthlyTimesheetModel.isFirstMonth();
}
public boolean isLastMonth() {
return monthlyTimesheetModel.isLastMonth();
}
public void previousMonth() {
if (monthlyTimesheetModel.isModified()) {
throw new WrongValueException(
previousMonth,
_("There are unsaved changes in the current monthly timesheet, please save before moving"));
}
sendToMonthlyTimesheet(monthlyTimesheetModel.getDate().minusMonths(1));
}
public void nextMonth() {
if (monthlyTimesheetModel.isModified()) {
throw new WrongValueException(
nextMonth,
_("There are unsaved changes in the current monthly timesheet, please save before moving"));
}
sendToMonthlyTimesheet(monthlyTimesheetModel.getDate().plusMonths(1));
}
private void sendToMonthlyTimesheet(final LocalDate date) {
String capturePath = EntryPointsHandler.capturePath(new ICapture() {
@Override
public void capture() {
monthlyTimesheetController.goToCreateOrEditForm(date);
}
});
Executions.getCurrent().sendRedirect(capturePath);
}
}
/**

View file

@ -101,6 +101,8 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
@Autowired
private IOrderDAO orderDAO;
private boolean modified;
@Override
@Transactional(readOnly = true)
public void initCreateOrEdit(LocalDate date) {
@ -117,6 +119,8 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
initWorkReport();
initOrderElements();
modified = false;
}
private void initDates() {
@ -266,6 +270,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
workReport.addWorkReportLine(workReportLine);
}
workReportLine.setEffort(effortDuration);
modified = true;
}
private WorkReportLine createWorkReportLine(OrderElement orderElement,
@ -298,6 +303,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
.getWorkReportLines());
workReportDAO.save(workReport);
}
modified = false;
}
@Override
@ -306,6 +312,7 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
date = null;
orderElements = null;
workReport = null;
modified = false;
}
@Override
@ -353,4 +360,22 @@ public class MonthlyTimesheetModel implements IMonthlyTimesheetModel {
return orderDAO.loadOrderAvoidingProxyFor(orderElement);
}
@Override
public boolean isModified() {
return modified;
}
@Override
public boolean isFirstMonth() {
LocalDate activationDate = getWorker().getCalendar()
.getFistCalendarAvailability().getStartDate();
return firstDay.equals(activationDate.dayOfMonth().withMinimumValue());
}
@Override
public boolean isLastMonth() {
return firstDay.equals(new LocalDate().plusMonths(1).dayOfMonth()
.withMinimumValue());
}
}

View file

@ -30,6 +30,15 @@
<window apply="org.libreplan.web.users.dashboard.MonthlyTimesheetController"
self="@{define(content)}" title="${i18n:_('Monthly timesheet')}">
<button id="previousMonth"
onClick="controller.previousMonth();"
label="${i18n:_('Previous')}"
disabled="@{controller.firstMonth}" />
<button id="nextMonth"
onClick="controller.nextMonth();"
label="${i18n:_('Next')}"
disabled="@{controller.lastMonth}" />
<groupbox style="margin-top: 5px" closable="false">
<caption label="${i18n:_('Timesheet data')}" />
<grid fixedLayout="true">