From 6b125c532feeb0dac799bfe66dac87fbe28dff44 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Fri, 14 May 2021 17:52:47 +0200 Subject: [PATCH] Template for create and edit step for postal address assets --- .../assets/PostalAddressCreateStep.java | 114 +++++++-- .../assets/PostalAddressEditStep.java | 11 +- .../ui/contentsection/assets/editstep.xhtml | 21 ++ .../postaladdress/create-postaladdress.xhtml | 102 ++++++++ .../postaladdress/edit-postaladdress.xhtml | 222 ++++++++++++++++++ .../article/article-basic-properties.xhtml | 2 +- .../ui/MvcAssetStepsBundle.properties | 62 +++++ .../ui/MvcAssetStepsBundle_de.properties | 62 +++++ 8 files changed, 567 insertions(+), 29 deletions(-) create mode 100644 ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/editstep.xhtml diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressCreateStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressCreateStep.java index 596c6bfe7..53fccf45a 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressCreateStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressCreateStep.java @@ -24,8 +24,10 @@ import org.librecms.assets.PostalAddress; import org.librecms.contentsection.AssetManager; import org.librecms.contentsection.AssetRepository; +import java.util.Arrays; import java.util.Locale; import java.util.Map; +import java.util.stream.Collectors; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; @@ -44,18 +46,34 @@ public class PostalAddressCreateStep private static final String FORM_PARAMS_NAME = "name"; private static final String FORM_PARAMS_TITLE = "title"; - + private static final String FORM_PARAM_INITIAL_LOCALE = "locale"; @Inject private AssetManager assetManager; - + @Inject private AssetRepository assetRepo; - + @Inject private GlobalizationHelper globalizationHelper; + private String name; + + private String title; + + private String initialLocale; + + private String address; + + private String postalCode; + + private String city; + + private String state; + + private String isoCountryCode; + @Override public String showCreateStep() { return "/org/librecms/ui/assets/postaladdress/create-postaladdress.xhtml"; @@ -76,14 +94,14 @@ public class PostalAddressCreateStep ); return showCreateStep(); } - - final String name = formParams.get(FORM_PARAMS_NAME)[0]; + + name = formParams.get(FORM_PARAMS_NAME)[0]; if (!name.matches("^([a-zA-Z0-9_-]*)$")) { addMessage( "danger", globalizationHelper - .getLocalizedTextsUtil(getBundle()) - .getText("postaladdress.createstep.name.error.invalid") + .getLocalizedTextsUtil(getBundle()) + .getText("postaladdress.createstep.name.error.invalid") ); return showCreateStep(); } @@ -99,8 +117,8 @@ public class PostalAddressCreateStep ); return showCreateStep(); } - final String title = formParams.get(FORM_PARAMS_TITLE)[0]; - + title = formParams.get(FORM_PARAMS_TITLE)[0]; + if (!formParams.containsKey(FORM_PARAM_INITIAL_LOCALE) || formParams.get(FORM_PARAM_INITIAL_LOCALE) == null || formParams.get(FORM_PARAM_INITIAL_LOCALE).length == 0) { @@ -112,32 +130,31 @@ public class PostalAddressCreateStep ); return showCreateStep(); } - final Locale locale = new Locale( - formParams.get(FORM_PARAM_INITIAL_LOCALE)[0] - ); - - final String address = formParams.get("address")[0]; - final String postalCode = formParams.get("postalCode")[0]; - final String city = formParams.get("city")[0]; - final String state = formParams.get("state")[0]; - final String isoCountryCode = formParams.get("isoCountryCode")[0]; - + initialLocale = formParams.get(FORM_PARAM_INITIAL_LOCALE)[0]; + final Locale locale = new Locale(initialLocale); + + address = formParams.get("address")[0]; + postalCode = formParams.get("postalCode")[0]; + city = formParams.get("city")[0]; + state = formParams.get("state")[0]; + isoCountryCode = formParams.get("isoCountryCode")[0]; + final PostalAddress postalAddress = assetManager.createAsset( - name, + name, title, - locale, - getFolder(), + locale, + getFolder(), PostalAddress.class ); - + postalAddress.setAddress(address); postalAddress.setPostalCode(postalCode); postalAddress.setCity(city); postalAddress.setState(state); postalAddress.setIsoCountryCode(isoCountryCode); - + assetRepo.save(postalAddress); - + return String.format( "redirect:/%s/assets/%s/%s/@postaladdress-edit", getContentSectionLabel(), @@ -145,7 +162,6 @@ public class PostalAddressCreateStep name ); } - @Override public String getAssetType() { @@ -171,4 +187,50 @@ public class PostalAddressCreateStep return MvcAssetStepsConstants.BUNDLE; } + public String getName() { + return name; + } + + public String getTitle() { + return title; + } + + public String getInitialLocale() { + return initialLocale; + } + + public String getAddress() { + return address; + } + + public String getPostalCode() { + return postalCode; + } + + public String getCity() { + return city; + } + + public String getState() { + return state; + } + + public String getIsoCountryCode() { + return isoCountryCode; + } + + public Map getCountries() { + return Arrays + .stream(Locale.getISOCountries()) + .map(country -> new Locale(country)) + .collect( + Collectors.toMap( + Locale::toString, + locale -> locale.getDisplayCountry( + globalizationHelper.getNegotiatedLocale() + ) + ) + ); + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java index 6a6304a42..59ba7d3ed 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PostalAddressEditStep.java @@ -324,6 +324,12 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep { public String getIsoCountryCode() { return getPostalAddress().getIsoCountryCode(); } + + public String getCountry() { + return new Locale(getPostalAddress() + .getIsoCountryCode()) + .getDisplayCountry(globalizationHelper.getNegotiatedLocale()); + } @POST @Path("/properties") @@ -374,8 +380,9 @@ public class PostalAddressEditStep extends AbstractMvcAssetEditStep { .collect( Collectors.toMap( Locale::toString, - locale -> locale.getDisplayCountry(globalizationHelper - .getNegotiatedLocale()) + locale -> locale.getDisplayCountry( + globalizationHelper.getNegotiatedLocale() + ) ) ); } diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/editstep.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/editstep.xhtml new file mode 100644 index 000000000..53b2dd9b7 --- /dev/null +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/editstep.xhtml @@ -0,0 +1,21 @@ +]> + + + + + + + + + + + + + + + diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/create-postaladdress.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/create-postaladdress.xhtml index 8b1378917..40a470361 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/create-postaladdress.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/create-postaladdress.xhtml @@ -1 +1,103 @@ +]> + + + +
+

#{CmsAssetsStepsDefaultMessagesBundle["postaladdress.createform.title"]}

+ + + + + +
+ + + + + + + + + + + + + + + + + + #{CmsAssetsStepsDefaultMessagesBundle['createform.cancel']} + + + + + +
+
+ +
+ diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml index 8b1378917..6123d1d66 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contentsection/assets/postaladdress/edit-postaladdress.xhtml @@ -1 +1,223 @@ +]> + + +

#{CmsAssetsStepsDefaultMessagesBundle.getMessage('postaladdress.editstep.header', [CmsPostalAddressEditStep.name])}

+ +

#{CmsAssetsStepsDefaultMessagesBundle['editstep.name.header']}

+
+
#{CmsPostalAddressEditStep.name}
+ + + +
+ + + + + + + +

#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.header']}

+ + +
+ +
+ +
+
+
+
#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.address.label']}
+
#{CmsPostalAddressEditStep.address}
+
+
+
#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.postal_code.label']}
+
#{CmsPostalAddressEditStep.postalCode}
+
+
+
#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.city.label']}
+
#{CmsPostalAddressEditStep.city}
+
+
+
#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.state.label']}
+
#{CmsPostalAddressEditStep.state}
+
+
+
#{CmsAssetsStepsDefaultMessagesBundle['postaladdress.editstep.properties.country.label']}
+
#{CmsPostalAddressEditStep.country}
+
+
+ +
+ + \ No newline at end of file diff --git a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml index 800c1c708..965f01e68 100644 --- a/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml +++ b/ccm-cms/src/main/resources/WEB-INF/views/org/librecms/ui/contenttypes/article/article-basic-properties.xhtml @@ -44,7 +44,7 @@ class="close" data-dismiss="modal" type="button"> - +