1
2 package com.pnpconsult.zeiterfassung.actions.manager;
3
4 import java.util.Collection;
5
6 import javax.servlet.http.HttpServletRequest;
7 import javax.servlet.http.HttpServletResponse;
8
9 import org.apache.struts.action.Action;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionForward;
12 import org.apache.struts.action.ActionMapping;
13
14 import com.pnpconsult.zeiterfassung.helper.TableManager;
15 import com.pnpconsult.zeiterfassung.helper.UserEntryManager;
16 import com.pnpconsult.zeiterfassung.model.UserEntry;
17 import com.pnpconsult.zeiterfassung.table.Row;
18 import com.pnpconsult.zeiterfassung.table.Table;
19 import com.pnpconsult.zeiterfassung.table.UserEntryRow;
20
21 /***
22 * @author <a href="mailto:powerpete@users.sf.net">Moritz Petersen</a>
23 * @version $Id: EditUserEntryRowAction.java,v 1.4 2004/06/24 20:54:18 powerpete Exp $
24 *
25 * @struts.action
26 * path="/secure/manager/editUserEntryRow"
27 * name="editUserEntryRowForm"
28 * scope="session"
29 * validate="false"
30 *
31 * @struts.action-forward
32 * name="edit"
33 * path="/secure/manager/editUserEntryRow.jsp"
34 *
35 * @struts.action-forward
36 * name="table"
37 * path="/secure/manager/table.jsp"
38 *
39 * @struts.action-forward
40 * name="menu"
41 * path="/secure/manager/managerMenu.jsp"
42 */
43 public class EditUserEntryRowAction extends Action
44 {
45 public ActionForward execute(
46 ActionMapping mapping,
47 ActionForm form,
48 HttpServletRequest request,
49 HttpServletResponse response) throws Exception
50 {
51 EditUserEntryRowForm editUserEntryRowForm = (EditUserEntryRowForm) form;
52 int index = editUserEntryRowForm.getIndex();
53 Table table = new TableManager().get(request);
54 if (table == null) { return mapping.findForward("menu"); }
55 Row row = table.getRow(index);
56 Collection entries = ((UserEntryRow) row).getEntries();
57 if (editUserEntryRowForm.userHasNotClicked())
58 {
59 editUserEntryRowForm.setEntries(entries);
60 return mapping.findForward("edit");
61 }
62 else if (editUserEntryRowForm.userHasClickedNewline())
63 {
64 if (entries.size() > 0)
65 {
66 UserEntry entry = (UserEntry) entries.iterator().next();
67 UserEntry copy = new UserEntry();
68 copy.setActivity(entry.getActivity());
69 copy.setBillingFactor(entry.getBillingFactor());
70 copy.setDate(entry.getDate());
71 copy.setHours(entry.getHours());
72 copy.setInformation(entry.getInformation());
73 copy.setInvolved(entry.getInvolved());
74 copy.setPartner(entry.getPartner());
75 copy.setProject(entry.getProject());
76 copy.setSaved(true);
77 copy.setTargetDate(entry.getTargetDate());
78 copy.setUser(entry.getUser());
79 new UserEntryManager().save(copy);
80 entries.add(copy);
81 editUserEntryRowForm.setEntries(entries);
82 editUserEntryRowForm.updateEntries();
83 table.reload();
84 return mapping.findForward("edit");
85 }
86 }
87 else if (editUserEntryRowForm.userHasClickedOK())
88 {
89 editUserEntryRowForm.updateEntries();
90 table.reload();
91 return mapping.findForward("table");
92 }
93 else if (editUserEntryRowForm.userHasClickedCancel())
94 {
95 return mapping.findForward("table");
96 }
97 return mapping.findForward("menu");
98 }
99 }