]> WPIA git - gigi.git/blob - src/club/wpia/gigi/pages/account/MyDetails.java
fix: move switch to organisation context to separate page
[gigi.git] / src / club / wpia / gigi / pages / account / MyDetails.java
1 package club.wpia.gigi.pages.account;
2
3 import java.io.IOException;
4 import java.io.PrintWriter;
5 import java.util.HashMap;
6
7 import javax.servlet.http.HttpServletRequest;
8 import javax.servlet.http.HttpServletResponse;
9
10 import club.wpia.gigi.output.template.Form;
11 import club.wpia.gigi.pages.LoginPage;
12 import club.wpia.gigi.pages.Page;
13 import club.wpia.gigi.pages.orga.MyOrganisationsForm;
14
15 public class MyDetails extends Page {
16
17     public MyDetails() {
18         super("My Details");
19     }
20
21     public static final String PATH = "/account/details";
22
23     @Override
24     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
25         PrintWriter out = resp.getWriter();
26         HashMap<String, Object> map = new HashMap<String, Object>();
27         MyDetailsForm form = new MyDetailsForm(req, getUser(req));
28         map.put("detailsForm", form);
29         if (LoginPage.getUser(req).getOrganisations().size() != 0) {
30             map.put("orgaForm", new MyOrganisationsForm(req));
31         }
32         getDefaultTemplate().output(out, getLanguage(req), map);
33     }
34
35     @Override
36     public boolean beforePost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
37         if (req.getParameter("orgaForm") != null) {
38             return Form.getForm(req, MyOrganisationsForm.class).submitExceptionProtected(req, resp);
39         }
40         if (req.getParameter("action") != null || req.getParameter("removeName") != null || req.getParameter("deprecateName") != null || req.getParameter("preferred") != null) {
41             return Form.getForm(req, MyDetailsForm.class).submitExceptionProtected(req, resp);
42         }
43         return false;
44     }
45
46     @Override
47     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
48         if (Form.printFormErrors(req, resp.getWriter())) {
49             if (req.getParameter("orgaForm") != null) {
50                 Form.getForm(req, MyOrganisationsForm.class).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
51             }
52             if (req.getParameter("action") != null || req.getParameter("removeName") != null || req.getParameter("deprecateName") != null || req.getParameter("preferred") != null) {
53                 Form.getForm(req, MyDetailsForm.class).output(resp.getWriter(), getLanguage(req), new HashMap<String, Object>());
54             }
55         }
56     }
57 }