From: Janis Streib Date: Sun, 24 Aug 2014 09:42:35 +0000 (+0200) Subject: ADD: Contact infromtaion form X-Git-Url: https://code.wpia.club/?p=gigi.git;a=commitdiff_plain;h=7d143b2edcb0ea7bfe149fd6b77b35ffcf94acf5 ADD: Contact infromtaion form --- diff --git a/src/org/cacert/gigi/pages/account/MyDetails.java b/src/org/cacert/gigi/pages/account/MyDetails.java index 2ddb6096..9f9a344c 100644 --- a/src/org/cacert/gigi/pages/account/MyDetails.java +++ b/src/org/cacert/gigi/pages/account/MyDetails.java @@ -23,7 +23,9 @@ public class MyDetails extends Page { PrintWriter out = resp.getWriter(); HashMap map = new HashMap(); MyDetailsForm form = new MyDetailsForm(req, getUser(req)); + MyListingForm listingForm = new MyListingForm(req, getUser(req)); map.put("detailsForm", form); + map.put("contactMeForm", listingForm); getDefaultTemplate().output(out, getLanguage(req), map); } @@ -32,6 +34,9 @@ public class MyDetails extends Page { if(req.getParameter("processDetails") != null) { MyDetailsForm form = Form.getForm(req, MyDetailsForm.class); form.submit(resp.getWriter(), req); + } else if (req.getParameter("processContact") != null) { + MyListingForm form = Form.getForm(req, MyListingForm.class); + form.submit(resp.getWriter(), req); } super.doPost(req, resp); } diff --git a/src/org/cacert/gigi/pages/account/MyDetails.templ b/src/org/cacert/gigi/pages/account/MyDetails.templ index 1d919504..eb86e511 100644 --- a/src/org/cacert/gigi/pages/account/MyDetails.templ +++ b/src/org/cacert/gigi/pages/account/MyDetails.templ @@ -1 +1,3 @@ - \ No newline at end of file + +

+ \ No newline at end of file diff --git a/src/org/cacert/gigi/pages/account/MyListingForm.java b/src/org/cacert/gigi/pages/account/MyListingForm.java new file mode 100644 index 00000000..6b29aac2 --- /dev/null +++ b/src/org/cacert/gigi/pages/account/MyListingForm.java @@ -0,0 +1,66 @@ +package org.cacert.gigi.pages.account; + +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.sql.SQLException; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.cacert.gigi.GigiApiException; +import org.cacert.gigi.User; +import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.Form; +import org.cacert.gigi.output.template.Template; +import org.cacert.gigi.pages.Page; + +public class MyListingForm extends Form { + + private static Template template; + + static{ + template = new Template(new InputStreamReader(MyListingForm.class.getResourceAsStream("MyListingForm.templ"))); + } + + private User target; + + public MyListingForm(HttpServletRequest hsr, User target) { + super(hsr); + this.target = target; + } + + @Override + public boolean submit(PrintWriter out, HttpServletRequest req) { + if (req.getParameter("listme") != null && req.getParameter("contactinfo") != null) { + try { + target.setDirectoryListing( !req.getParameter("listme").equals("0")); + target.setContactInformation(req.getParameter("contactinfo")); + return true; + } catch (SQLException e) { + new GigiApiException(e).format(out, Page.getLanguage(req)); + e.printStackTrace(); + return false; + } + } + return false; + } + + @Override + protected void outputContent(PrintWriter out, Language l, Map vars) { + try { + if (target.wantsDirectoryListing()) { + vars.put("selected", "selected"); + vars.put("notSelected", ""); + vars.put("activeInfo", target.getContactInformation()); + } else { + vars.put("selected", ""); + vars.put("notSelected", "selected"); + vars.put("activeInfo", ""); + } + } catch (SQLException e) { + new GigiApiException(e).format(out, l); + } + template.output(out, l, vars); + } + +} diff --git a/src/org/cacert/gigi/pages/account/MyListingForm.templ b/src/org/cacert/gigi/pages/account/MyListingForm.templ new file mode 100644 index 00000000..1eed71ea --- /dev/null +++ b/src/org/cacert/gigi/pages/account/MyListingForm.templ @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + +
+
: + +
:
\ No newline at end of file