Some improvments for the person edit step

pull/10/head
Jens Pelzetter 2021-06-03 20:45:55 +02:00
parent 025e48aae0
commit 813d5d1136
10 changed files with 166 additions and 27 deletions

View File

@ -32,6 +32,7 @@ import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.servlet.ServletContext;
/** /**
* *
@ -44,11 +45,18 @@ public class ContactableEntityEditStepModel {
@Inject @Inject
private GlobalizationHelper globalizationHelper; private GlobalizationHelper globalizationHelper;
@Inject
private ServletContext servletContext;
private Map<String, String> availableContactEntryKeys; private Map<String, String> availableContactEntryKeys;
private List<ContactEntryListItemModel> contactEntries; private List<ContactEntryListItemModel> contactEntries;
private PostalAddress postalAddress; private PostalAddress postalAddress;
public String getContextPath() {
return servletContext.getContextPath();
}
public Map<String, String> getAvailableContactEntryKeys() { public Map<String, String> getAvailableContactEntryKeys() {
return Collections.unmodifiableMap(availableContactEntryKeys); return Collections.unmodifiableMap(availableContactEntryKeys);

View File

@ -30,6 +30,9 @@ import org.librecms.ui.contentsections.ContentSectionNotFoundException;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle; import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
@ -95,18 +98,25 @@ public class PersonEditStep extends AbstractContactableEntityEditStep {
if (getAsset() instanceof Person) { if (getAsset() instanceof Person) {
editStepModel.setBirthdate( editStepModel.setBirthdate(
Optional Optional
.ofNullable(getPerson().getBirthdate()) .ofNullable(getPerson().getBirthdate())
.map( .map(
birthdate -> birthdate.format( birthdate -> birthdate.format(
DateTimeFormatter DateTimeFormatter
.ofLocalizedDate(FormatStyle.SHORT) .ofLocalizedDate(FormatStyle.SHORT)
.withLocale( .withLocale(
globalizationHelper.getNegotiatedLocale() globalizationHelper.getNegotiatedLocale()
) )
.withZone(ZoneId.systemDefault()))) .withZone(ZoneId.systemDefault())))
.orElse("") .orElse("")
); );
editStepModel.setPersonNames(getPerson().getPersonNames()); final List<PersonNameRow> 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 { } else {
throw new AssetNotFoundException( throw new AssetNotFoundException(
assetUi.showAssetNotFound( 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;
}
} }

View File

@ -35,15 +35,15 @@ import javax.inject.Named;
@Named("CmsPersonEditStepModel") @Named("CmsPersonEditStepModel")
public class PersonEditStepModel { public class PersonEditStepModel {
private List<PersonName> personName; private List<PersonNameRow> personName;
private String birthdate; private String birthdate;
public List<PersonName> getPersonNames() { public List<PersonNameRow> getPersonNames() {
return Collections.unmodifiableList(personName); return Collections.unmodifiableList(personName);
} }
protected void setPersonNames(final List<PersonName> personNames) { protected void setPersonNames(final List<PersonNameRow> personNames) {
this.personName = new ArrayList<>(personNames); this.personName = new ArrayList<>(personNames);
} }

View File

@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
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;
}
}

View File

@ -8,7 +8,7 @@
required="true" required="true"
shortDescription="Base URL for the actions of the asset picker." shortDescription="Base URL for the actions of the asset picker."
type="String" /> type="String" />
<cc:attribute name="assetType" <cc:attribute name="assetType"
required="false" required="false"
shortDescription="Type of assets to show." shortDescription="Type of assets to show."
type="String" type="String"
@ -21,6 +21,10 @@
required="true" required="true"
shortDescription="The current content section." shortDescription="The current content section."
type="String" /> type="String" />
<cc:attribute name="contextPath"
required="true"
shortDescription="The context path of the CCM installation. May be empty."
type="String" />
<cc:attribute name="dialogTitle" <cc:attribute name="dialogTitle"
required="false" required="false"
shortDescription="Title of the asset picker dialog" shortDescription="Title of the asset picker dialog"
@ -39,8 +43,9 @@
type="int" /> type="int" />
</cc:interface> </cc:interface>
<cc:implementation> <cc:implementation>
<div class="ccm-cms-asset-picker" <div class="ccm-cms-asset-picker"
data-assettype="#{cc.attrs.assetType}" data-assettype="#{cc.attrs.assetType}"
data-contextpath="#{cc.attrs.contextPath}"
data-contentsection="#{cc.attrs.contentSection}"> data-contentsection="#{cc.attrs.contentSection}">
<div aria-hidden="true" <div aria-hidden="true"
aria-labelledby="#{cc.attrs.assetPickerId}-dialog-title" aria-labelledby="#{cc.attrs.assetPickerId}-dialog-title"
@ -88,7 +93,7 @@
</button> </button>
</div> </div>
<form action="#{cc.attrs.actionUrl}" <form action="#{cc.attrs.actionUrl}"
class="modal-content" class="modal-body"
method="post"> method="post">
<input class="assetpicker-param" <input class="assetpicker-param"
id="#{cc.attrs.assetPickerId}-param-input" id="#{cc.attrs.assetPickerId}-param-input"

View File

@ -28,7 +28,7 @@
class="modal-content" class="modal-content"
method="post"> method="post">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-header" <h4 class="modal-title"
id="add-contactentry-dialog-title"> id="add-contactentry-dialog-title">
#{CmsAssetsStepsDefaultMessagesBundle['contactable.contactentries.add.title']} #{CmsAssetsStepsDefaultMessagesBundle['contactable.contactentries.add.title']}
</h4> </h4>
@ -213,6 +213,7 @@
actionUrl="#{actionBaseUrl}/postaladdress" actionUrl="#{actionBaseUrl}/postaladdress"
assetType="#{CmsContactableEditStepModel.postalAddressType}" assetType="#{CmsContactableEditStepModel.postalAddressType}"
assetPickerId="postaladdress-picker" assetPickerId="postaladdress-picker"
contextPath="#{CmsContactableEditStepModel.contextPath}"
contentSection="#{ContentSectionModel.sectionName}" contentSection="#{ContentSectionModel.sectionName}"
formParamName="postalAddressIdentifier" formParamName="postalAddressIdentifier"
/> />

View File

@ -105,7 +105,7 @@
<tbody> <tbody>
<c:forEach items="#{CmsPersonEditStepModel.personNames}" <c:forEach items="#{CmsPersonEditStepModel.personNames}"
var="personName"> var="personName">
<tr> <tr data-index="#{personName.index}">
<td>#{personName.prefix}</td> <td>#{personName.prefix}</td>
<td>#{personName.surname}</td> <td>#{personName.surname}</td>
<td>#{personName.givenName}</td> <td>#{personName.givenName}</td>
@ -124,7 +124,7 @@
id="personname-edit-dialog-#{personName.hashCode()}" id="personname-edit-dialog-#{personName.hashCode()}"
tabindex="-1"> tabindex="-1">
<div class="modal-dialog"> <div class="modal-dialog">
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/asset/#{CmsSelectedAssetModel.assetPath}/@person-edit/personnames/@edit" <form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@person-edit/personnames/#{personName.index}/@edit"
class="modal-content" class="modal-content"
method="post"> method="post">
<div class="modal-header"> <div class="modal-header">
@ -192,7 +192,7 @@
id="personname-remove-dialog-#{personName.hashCode()}" id="personname-remove-dialog-#{personName.hashCode()}"
tabindex="-1"> tabindex="-1">
<div class="modal-dialog"> <div class="modal-dialog">
<form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/asset/#{CmsSelectedAssetModel.assetPath}/@person-edit/personnames/@remove" <form action="#{mvc.basePath}/#{ContentSectionModel.sectionName}/assets/#{CmsSelectedAssetModel.assetPath}/@person-edit/personnames/@remove"
class="modal-content" class="modal-content"
method="post"> method="post">
<div class="modal-header"> <div class="modal-header">

View File

@ -257,7 +257,7 @@ person.personname.givenname.help=The name of the person.
person.personname.suffix.help=Suffixes of the name, for example Ph.D. person.personname.suffix.help=Suffixes of the name, for example Ph.D.
person.personname.suffix.label=Suffix person.personname.suffix.label=Suffix
person.personname.edit.dialog.close=Cancel person.personname.edit.dialog.close=Cancel
person.personname.edit.dialog.submit=Add name person.personname.edit.dialog.submit=Save
person.personname.remove=Remove person name person.personname.remove=Remove person name
person.personname.remove.dialog.title=Remove Person Name person.personname.remove.dialog.title=Remove Person Name
person.personname.remove.dialog.close=Cancel person.personname.remove.dialog.close=Cancel
@ -273,3 +273,13 @@ contactable.postaladdress.set=Set postal address
person.personname.givenname.label=Given name person.personname.givenname.label=Given name
person.personname.add.dialog.close=Cancel person.personname.add.dialog.close=Cancel
person.personname.add.dialog.submit=Add person name person.personname.add.dialog.submit=Add person name
person.personname.edit.dialog.title=Edit person name
contactable.contactentries.add.close=Cancel
assetpicker.title=Select asset
assetpicker.close=Cancel
assetpicker.filter.help=Filter for finding assets.
assetpicker.filter.label=Filter
assetpicker.select=Select asset
assetpicker.column.name=Name
assetpicker.column.type=Type
assetpicker.column.action=Action

View File

@ -257,7 +257,7 @@ person.personname.givenname.help=Der Name der Person.
person.personname.suffix.help=Suffixe des Namens, zum Beispiel Ph.D. person.personname.suffix.help=Suffixe des Namens, zum Beispiel Ph.D.
person.personname.suffix.label=Suffix person.personname.suffix.label=Suffix
person.personname.edit.dialog.close=Abbrechen person.personname.edit.dialog.close=Abbrechen
person.personname.edit.dialog.submit=Namen hinzuf\u00fcgen person.personname.edit.dialog.submit=Speichern
person.personname.remove=Namen entfernen person.personname.remove=Namen entfernen
person.personname.remove.dialog.title=Namen entfernen person.personname.remove.dialog.title=Namen entfernen
person.personname.remove.dialog.close=Abbrechen person.personname.remove.dialog.close=Abbrechen
@ -273,3 +273,13 @@ contactable.postaladdress.set=Postanschrift setzen
person.personname.givenname.label=Vorname person.personname.givenname.label=Vorname
person.personname.add.dialog.close=Abbrechen person.personname.add.dialog.close=Abbrechen
person.personname.add.dialog.submit=Personenamen hinzuf\u00fcgen person.personname.add.dialog.submit=Personenamen hinzuf\u00fcgen
person.personname.edit.dialog.title=Personenname bearbeiten
contactable.contactentries.add.close=Abbrechen
assetpicker.title=Asset ausw\u00e4hlen
assetpicker.close=Abbrechen
assetpicker.filter.help=Filter zum finden von Assets.
assetpicker.filter.label=Filter
assetpicker.select=Asset ausw\u00e4hlen
assetpicker.column.name=Name
assetpicker.column.type=Typ
assetpicker.column.action=Aktion

View File

@ -1,7 +1,7 @@
import * as $ from "jquery"; import * as $ from "jquery";
document.addEventListener("DOMContentLoaded", function (event) { document.addEventListener("DOMContentLoaded", function (event) {
const assetPickers = document.querySelectorAll("ccm-cms-asset-picker"); const assetPickers = document.querySelectorAll(".ccm-cms-asset-picker");
for (let i = 0; i < assetPickers.length; i++) { for (let i = 0; i < assetPickers.length; i++) {
initAssetPicker(assetPickers[i]); initAssetPicker(assetPickers[i]);
@ -11,12 +11,15 @@ document.addEventListener("DOMContentLoaded", function (event) {
async function initAssetPicker(assetPickerElem: Element) { async function initAssetPicker(assetPickerElem: Element) {
const assetPickerId = assetPickerElem.getAttribute("id"); const assetPickerId = assetPickerElem.getAttribute("id");
const assetType = getAssetType(assetPickerElem); const assetType = getAssetType(assetPickerElem);
const contextPath = assetPickerElem.getAttribute("data-contextpath");
const contentSection = assetPickerElem.getAttribute("data-contentsection"); const contentSection = assetPickerElem.getAttribute("data-contentsection");
const fetchUrl = contextPath
? `./${contextPath}/content-sections/${contentSection}/assets/?type=${assetType}`
: `./content-sections/${contentSection}/assets/?type=${assetType}`;
try { try {
const response = await fetch( const response = await fetch(fetchUrl);
`/content-sections/${contentSection}/assets/?type=${assetType}`
);
if (response.ok) { if (response.ok) {
const assets = (await response.json()) as []; const assets = (await response.json()) as [];