]> WPIA git - gigi.git/commitdiff
ADD: Contact infromtaion form
authorJanis Streib <janis@dogcraft.de>
Sun, 24 Aug 2014 09:42:35 +0000 (11:42 +0200)
committerJanis Streib <janis@dogcraft.de>
Sun, 24 Aug 2014 09:43:56 +0000 (11:43 +0200)
src/org/cacert/gigi/pages/account/MyDetails.java
src/org/cacert/gigi/pages/account/MyDetails.templ
src/org/cacert/gigi/pages/account/MyListingForm.java [new file with mode: 0644]
src/org/cacert/gigi/pages/account/MyListingForm.templ [new file with mode: 0644]

index 2ddb6096dea8ef3921417f2f87140ecc7c99fdeb..9f9a344c42c311a9fbcc0a6f1a69a418be4bbf71 100644 (file)
@@ -23,7 +23,9 @@ public class MyDetails extends Page {
         PrintWriter out = resp.getWriter();
         HashMap<String, Object> map = new HashMap<String, Object>();
         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);
     }
index 1d91950455b4922b43e7d803dc15d784c2477e03..eb86e511f5042077f227cc15b084124026c67b48 100644 (file)
@@ -1 +1,3 @@
-<?=$detailsForm?>
\ No newline at end of file
+<?=$detailsForm?>
+<h2><?=_My Listing?></h2>
+<?=$contactMeForm?>
\ 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 (file)
index 0000000..6b29aac
--- /dev/null
@@ -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<String, Object> 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 (file)
index 0000000..1eed71e
--- /dev/null
@@ -0,0 +1,21 @@
+<table class="wrapper dataTable">
+  <tr>
+    <th colspan="2"><?=_My Listing?></td>
+  </tr>
+  <tr>
+    <td><?=_Directory Listing?>:</td>
+    <td>
+       <select name="listme">
+               <option value="0" <?=$notSelected?>><?=_I don't want to be listed?></option>
+               <option value="1" <?=$selected?>><?=_I want to be listed?></option>
+       </select>
+    </td>
+  </tr>
+  <tr>
+    <td><?=_Contact information?>:</td>
+    <td><textarea name="contactinfo" cols="40" rows="5" wrap="virtual"><?=$activeInfo?></textarea></td>
+  </tr>
+  <tr>
+    <td colspan="2"><input type="submit" name="processContact" value="<?=_Update?>"></td>
+  </tr>
+</table>
\ No newline at end of file