Add button to edit personal expense sheet from user dashboard
Modify behavior of ExpenseSheetCRUDController to redirect to user dashboard if creation or edition comes from there. FEA: ItEr76S28UserDashboard
This commit is contained in:
parent
8b4707d829
commit
58e9a6d96c
5 changed files with 118 additions and 3 deletions
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* This file is part of LibrePlan
|
||||
*
|
||||
* Copyright (C) 2012 Igalia, S.L.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.libreplan.web.common.converters;
|
||||
|
||||
import org.libreplan.business.common.exceptions.InstanceNotFoundException;
|
||||
import org.libreplan.business.expensesheet.daos.IExpenseSheetDAO;
|
||||
import org.libreplan.business.expensesheet.entities.ExpenseSheet;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* A {@link IConverter} for {@link ExpenseSheet} objects.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
@Component
|
||||
@Scope(BeanDefinition.SCOPE_SINGLETON)
|
||||
public class ExpenseSheetConverter implements IConverter<ExpenseSheet> {
|
||||
|
||||
@Autowired
|
||||
private IExpenseSheetDAO expenseSheetDAO;
|
||||
|
||||
@Override
|
||||
public Class<ExpenseSheet> getType() {
|
||||
return ExpenseSheet.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asString(ExpenseSheet entity) {
|
||||
return entity.getId().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpenseSheet asObject(String stringRepresentation) {
|
||||
try {
|
||||
return expenseSheetDAO.find(Long.parseLong(stringRepresentation));
|
||||
} catch (InstanceNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String asStringUngeneric(Object entity) {
|
||||
return asString((ExpenseSheet) entity);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -41,8 +41,10 @@ import org.libreplan.web.common.Level;
|
|||
import org.libreplan.web.common.Util;
|
||||
import org.libreplan.web.common.components.bandboxsearch.BandboxSearch;
|
||||
import org.libreplan.web.common.entrypoints.IURLHandlerRegistry;
|
||||
import org.libreplan.web.users.services.CustomTargetUrlResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.CheckEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
|
|
@ -93,6 +95,10 @@ public class ExpenseSheetCRUDController extends
|
|||
|
||||
private IURLHandlerRegistry URLHandlerRegistry;
|
||||
|
||||
private boolean fromUserDashboard = false;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
|
|
@ -551,7 +557,8 @@ public class ExpenseSheetCRUDController extends
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void delete(ExpenseSheet expenseSheet) throws InstanceNotFoundException {
|
||||
public void delete(ExpenseSheet expenseSheet)
|
||||
throws InstanceNotFoundException {
|
||||
expenseSheetModel.removeExpenseSheet(expenseSheet);
|
||||
}
|
||||
|
||||
|
|
@ -578,6 +585,7 @@ public class ExpenseSheetCRUDController extends
|
|||
state = CRUDControllerState.CREATE;
|
||||
initCreate(true);
|
||||
showEditWindow();
|
||||
fromUserDashboard = true;
|
||||
}
|
||||
|
||||
private void initCreate(boolean personal) {
|
||||
|
|
@ -590,4 +598,29 @@ public class ExpenseSheetCRUDController extends
|
|||
return resource == null ? "" : resource.getShortDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void goToEditPersonalExpenseSheet(ExpenseSheet expenseSheet) {
|
||||
goToEditForm(expenseSheet);
|
||||
fromUserDashboard = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showListWindow() {
|
||||
if (fromUserDashboard) {
|
||||
String url = CustomTargetUrlResolver.USER_DASHBOARD_URL;
|
||||
if (!cancel) {
|
||||
url += "?expense_sheet_saved="
|
||||
+ expenseSheetModel.getExpenseSheet().getCode();
|
||||
}
|
||||
Executions.getCurrent().sendRedirect(url);
|
||||
} else {
|
||||
super.showListWindow();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void cancel() {
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,6 @@ public interface IExpenseSheetCRUDController {
|
|||
void goToCreatePersonalExpenseSheet();
|
||||
|
||||
@EntryPoint("edit")
|
||||
void goToEditForm(ExpenseSheet expenseSheet);
|
||||
void goToEditPersonalExpenseSheet(ExpenseSheet expenseSheet);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ import org.libreplan.business.expensesheet.entities.ExpenseSheet;
|
|||
import org.libreplan.web.common.Util;
|
||||
import org.libreplan.web.expensesheet.IExpenseSheetCRUDController;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Row;
|
||||
import org.zkoss.zul.RowRenderer;
|
||||
|
|
@ -48,7 +50,7 @@ public class ExpensesAreaController extends GenericForwardComposer {
|
|||
|
||||
@Override
|
||||
public void render(Row row, Object data) throws Exception {
|
||||
ExpenseSheet expenseSheet = (ExpenseSheet) data;
|
||||
final ExpenseSheet expenseSheet = (ExpenseSheet) data;
|
||||
row.setValue(expenseSheet);
|
||||
|
||||
Util.appendLabel(row, expenseSheet.getDescription());
|
||||
|
|
@ -57,6 +59,14 @@ public class ExpensesAreaController extends GenericForwardComposer {
|
|||
Util.addCurrencySymbol(expenseSheet.getTotal()));
|
||||
Util.appendLabel(row, expenseSheet.getFirstExpense().toString());
|
||||
Util.appendLabel(row, expenseSheet.getLastExpense().toString());
|
||||
|
||||
Util.appendOperationsAndOnClickEvent(row, new EventListener() {
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
expenseSheetCRUDController
|
||||
.goToEditPersonalExpenseSheet(expenseSheet);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,13 @@ public class UserDashboardController extends GenericForwardComposer {
|
|||
messagesForUser.showMessage(Level.INFO,
|
||||
_("Monthly timesheet \"{0}\" saved", monthlyTimesheet));
|
||||
}
|
||||
|
||||
String expenseSheetSaved = Executions.getCurrent().getParameter(
|
||||
"expense_sheet_saved");
|
||||
if (!StringUtils.isBlank(expenseSheetSaved)) {
|
||||
messagesForUser.showMessage(Level.INFO,
|
||||
_("Expense sheet \"{0}\" saved", expenseSheetSaved));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue