X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2Fpages%2Forga%2FCreateOrgForm.java;h=7b69822549d16860cd37da089a967933b0d28f07;hb=c9ed09f0007fc2c813815be927a5a24b23dab83c;hp=194fe529ce7a997f7a08ce94389393a1e2f073bf;hpb=680b03f826182ea5d743b9fa6bc4b5b16e001e10;p=gigi.git diff --git a/src/org/cacert/gigi/pages/orga/CreateOrgForm.java b/src/org/cacert/gigi/pages/orga/CreateOrgForm.java index 194fe529..7b698225 100644 --- a/src/org/cacert/gigi/pages/orga/CreateOrgForm.java +++ b/src/org/cacert/gigi/pages/orga/CreateOrgForm.java @@ -6,13 +6,11 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.cacert.gigi.GigiApiException; -import org.cacert.gigi.dbObjects.CountryCode; -import org.cacert.gigi.dbObjects.CountryCode.CountryCodeType; import org.cacert.gigi.dbObjects.Organisation; import org.cacert.gigi.email.EmailProvider; import org.cacert.gigi.localisation.Language; +import org.cacert.gigi.output.CountrySelector; import org.cacert.gigi.output.template.Form; -import org.cacert.gigi.output.template.IterableDataset; import org.cacert.gigi.output.template.SprintfCommand; import org.cacert.gigi.output.template.Template; import org.cacert.gigi.pages.LoginPage; @@ -25,8 +23,6 @@ public class CreateOrgForm extends Form { private String o = ""; - private String c = ""; - private String st = ""; private String l = ""; @@ -39,15 +35,11 @@ public class CreateOrgForm extends Form { private boolean isEdit = false; - private CountryCode[] countryCode; + private CountrySelector cs; public CreateOrgForm(HttpServletRequest hsr) { super(hsr); - try { - countryCode = CountryCode.getCountryCodes(CountryCodeType.CODE_2_CHARS); - } catch (GigiApiException e) { - throw new Error(e); // should not happen - } + cs = new CountrySelector("C", false); } public CreateOrgForm(HttpServletRequest hsr, Organisation t) { @@ -55,7 +47,9 @@ public class CreateOrgForm extends Form { isEdit = true; result = t; o = t.getName(); - c = t.getState(); + + cs = new CountrySelector("C", false, t.getCountry()); + st = t.getProvince(); l = t.getCity(); email = t.getContactEmail(); @@ -64,29 +58,27 @@ public class CreateOrgForm extends Form { } @Override - public boolean submit(PrintWriter out, HttpServletRequest req) throws GigiApiException { + public SubmissionResult submit(HttpServletRequest req) throws GigiApiException { String action = req.getParameter("action"); if (action == null) { - return false; + throw new GigiApiException("No action given."); } if (action.equals("new")) { checkCertData(req); checkOrganisationData(req); - Organisation ne = new Organisation(o, c, st, l, email, optionalName, postalAddress, LoginPage.getUser(req)); + Organisation ne = new Organisation(o, cs.getCountry(), st, l, email, optionalName, postalAddress, LoginPage.getUser(req)); result = ne; - return true; } else if (action.equals("updateOrganisationData")) { checkOrganisationData(req); result.updateOrgData(email, optionalName, postalAddress); - return true; } else if (action.equals("updateCertificateData")) { checkCertData(req); - result.updateCertData(o, c, st, l); - return true; + result.updateCertData(o, cs.getCountry(), st, l); + } else { + throw new GigiApiException("No valid action given."); } - - return false; + return new RedirectResult(ViewOrgPage.DEFAULT_PATH + "/" + result.getId()); } private void checkOrganisationData(HttpServletRequest req) throws GigiApiException { @@ -100,7 +92,6 @@ public class CreateOrgForm extends Form { private void checkCertData(HttpServletRequest req) throws GigiApiException { o = extractParam(req, "O"); - c = extractParam(req, "C").toUpperCase(); st = extractParam(req, "ST"); l = extractParam(req, "L"); @@ -108,7 +99,7 @@ public class CreateOrgForm extends Form { throw new GigiApiException(SprintfCommand.createSimple("{0} not given or longer than {1} characters", "Organisation name", 64)); } - CountryCode.checkCountryCode(c, CountryCodeType.CODE_2_CHARS); + cs.update(req); if (st.length() > 128 || st.length() < 1) { throw new GigiApiException(SprintfCommand.createSimple("{0} not given or longer than {1} characters", "State/county", 128)); @@ -127,41 +118,16 @@ public class CreateOrgForm extends Form { return parameter.trim(); } - public Organisation getResult() { - return result; - } - @Override protected void outputContent(PrintWriter out, Language l, Map vars) { vars.put("O", o); - vars.put("C", c); + vars.put("C", cs); vars.put("ST", st); vars.put("L", this.l); vars.put("email", email); vars.put("optionalName", optionalName); vars.put("postalAddress", postalAddress); - vars.put("countryCode", new IterableDataset() { - - int i = 0; - - @Override - public boolean next(Language l, Map vars) { - if (i >= countryCode.length) { - return false; - } - CountryCode t = countryCode[i++]; - vars.put("id", t.getId()); - vars.put("cc", t.getCountryCode()); - vars.put("display", t.getCountry()); - if (t.getCountryCode().equals(c)) { - vars.put("selected", "selected"); - } else { - vars.put("selected", ""); - } - return true; - } - }); - // vars.put("countryCode", countryCode); + vars.put("countryCode", cs); if (isEdit) { vars.put("edit", true); }