From 813d5d1136f7539d8131bf58828847f8d0a9db5f Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Thu, 3 Jun 2021 20:45:55 +0200 Subject: [PATCH] Some improvments for the person edit step --- .../ContactableEntityEditStepModel.java | 8 ++ .../assets/PersonEditStep.java | 45 ++++++++--- .../assets/PersonEditStepModel.java | 6 +- .../contentsections/assets/PersonNameRow.java | 79 +++++++++++++++++++ .../components/librecms/assetPicker.xhtml | 11 ++- .../assets/edit-contactable.xhtml | 3 +- .../assets/person/edit-person.xhtml | 6 +- .../ui/MvcAssetStepsBundle.properties | 12 ++- .../ui/MvcAssetStepsBundle_de.properties | 12 ++- .../content-sections/cms-assetpicker.ts | 11 ++- 10 files changed, 166 insertions(+), 27 deletions(-) create mode 100644 ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonNameRow.java diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/ContactableEntityEditStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/ContactableEntityEditStepModel.java index 35e66d93f..7e509cf10 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/ContactableEntityEditStepModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/ContactableEntityEditStepModel.java @@ -32,6 +32,7 @@ import java.util.Optional; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; +import javax.servlet.ServletContext; /** * @@ -44,11 +45,18 @@ public class ContactableEntityEditStepModel { @Inject private GlobalizationHelper globalizationHelper; + @Inject + private ServletContext servletContext; + private Map availableContactEntryKeys; private List contactEntries; private PostalAddress postalAddress; + + public String getContextPath() { + return servletContext.getContextPath(); + } public Map getAvailableContactEntryKeys() { return Collections.unmodifiableMap(availableContactEntryKeys); diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStep.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStep.java index 007009da1..c3e6969ed 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStep.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStep.java @@ -30,6 +30,9 @@ import org.librecms.ui.contentsections.ContentSectionNotFoundException; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Optional; import javax.enterprise.context.RequestScoped; @@ -95,18 +98,25 @@ public class PersonEditStep extends AbstractContactableEntityEditStep { if (getAsset() instanceof Person) { editStepModel.setBirthdate( Optional - .ofNullable(getPerson().getBirthdate()) - .map( - birthdate -> birthdate.format( - DateTimeFormatter - .ofLocalizedDate(FormatStyle.SHORT) - .withLocale( - globalizationHelper.getNegotiatedLocale() - ) - .withZone(ZoneId.systemDefault()))) - .orElse("") + .ofNullable(getPerson().getBirthdate()) + .map( + birthdate -> birthdate.format( + DateTimeFormatter + .ofLocalizedDate(FormatStyle.SHORT) + .withLocale( + globalizationHelper.getNegotiatedLocale() + ) + .withZone(ZoneId.systemDefault()))) + .orElse("") ); - editStepModel.setPersonNames(getPerson().getPersonNames()); + final List personNames = new ArrayList<>(); + for (int i = 0; i < getPerson().getPersonNames().size(); i++) { + personNames.add( + buildPersonNameRow(i, getPerson().getPersonNames().get(i)) + ); + } + Collections.reverse(personNames); + editStepModel.setPersonNames(personNames); } else { throw new AssetNotFoundException( assetUi.showAssetNotFound( @@ -271,4 +281,17 @@ public class PersonEditStep extends AbstractContactableEntityEditStep { } } + private PersonNameRow buildPersonNameRow( + final int index, final PersonName personName + ) { + final PersonNameRow row = new PersonNameRow(); + row.setIndex(index); + row.setSurname(personName.getSurname()); + row.setPrefix(personName.getPrefix()); + row.setSuffix(personName.getSuffix()); + row.setGivenName(personName.getGivenName()); + + return row; + } + } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStepModel.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStepModel.java index bf55ca30d..8ed42fc5b 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStepModel.java +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonEditStepModel.java @@ -35,15 +35,15 @@ import javax.inject.Named; @Named("CmsPersonEditStepModel") public class PersonEditStepModel { - private List personName; + private List personName; private String birthdate; - public List getPersonNames() { + public List getPersonNames() { return Collections.unmodifiableList(personName); } - protected void setPersonNames(final List personNames) { + protected void setPersonNames(final List personNames) { this.personName = new ArrayList<>(personNames); } diff --git a/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonNameRow.java b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonNameRow.java new file mode 100644 index 000000000..714886a00 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/ui/contentsections/assets/PersonNameRow.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.librecms.ui.contentsections.assets; + +/** + * + * @author Jens Pelzetter + */ +public class PersonNameRow { + + private int index; + + private String prefix; + + private String surname; + + private String givenName; + + private String suffix; + + public int getIndex() { + return index; + } + + public void setIndex(final int index) { + this.index = index; + } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(final String prefix) { + this.prefix = prefix; + } + + public String getSurname() { + return surname; + } + + public void setSurname(final String surname) { + this.surname = surname; + } + + public String getGivenName() { + return givenName; + } + + public void setGivenName(final String givenName) { + this.givenName = givenName; + } + + public String getSuffix() { + return suffix; + } + + public void setSuffix(final String suffix) { + this.suffix = suffix; + } + + + +} diff --git a/ccm-cms/src/main/resources/META-INF/resources/components/librecms/assetPicker.xhtml b/ccm-cms/src/main/resources/META-INF/resources/components/librecms/assetPicker.xhtml index 54ac85f63..42a8aeaba 100644 --- a/ccm-cms/src/main/resources/META-INF/resources/components/librecms/assetPicker.xhtml +++ b/ccm-cms/src/main/resources/META-INF/resources/components/librecms/assetPicker.xhtml @@ -8,7 +8,7 @@ required="true" shortDescription="Base URL for the actions of the asset picker." type="String" /> - + -