Some improvments for the person edit step
parent
025e48aae0
commit
813d5d1136
|
|
@ -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,12 +45,19 @@ public class ContactableEntityEditStepModel {
|
|||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
@Inject
|
||||
private ServletContext servletContext;
|
||||
|
||||
private Map<String, String> availableContactEntryKeys;
|
||||
|
||||
private List<ContactEntryListItemModel> contactEntries;
|
||||
|
||||
private PostalAddress postalAddress;
|
||||
|
||||
public String getContextPath() {
|
||||
return servletContext.getContextPath();
|
||||
}
|
||||
|
||||
public Map<String, String> getAvailableContactEntryKeys() {
|
||||
return Collections.unmodifiableMap(availableContactEntryKeys);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<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 {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,15 +35,15 @@ import javax.inject.Named;
|
|||
@Named("CmsPersonEditStepModel")
|
||||
public class PersonEditStepModel {
|
||||
|
||||
private List<PersonName> personName;
|
||||
private List<PersonNameRow> personName;
|
||||
|
||||
private String birthdate;
|
||||
|
||||
public List<PersonName> getPersonNames() {
|
||||
public List<PersonNameRow> getPersonNames() {
|
||||
return Collections.unmodifiableList(personName);
|
||||
}
|
||||
|
||||
protected void setPersonNames(final List<PersonName> personNames) {
|
||||
protected void setPersonNames(final List<PersonNameRow> personNames) {
|
||||
this.personName = new ArrayList<>(personNames);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
required="true"
|
||||
shortDescription="Base URL for the actions of the asset picker."
|
||||
type="String" />
|
||||
<cc:attribute name="assetType"
|
||||
<cc:attribute name="assetType"
|
||||
required="false"
|
||||
shortDescription="Type of assets to show."
|
||||
type="String"
|
||||
|
|
@ -21,6 +21,10 @@
|
|||
required="true"
|
||||
shortDescription="The current content section."
|
||||
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"
|
||||
required="false"
|
||||
shortDescription="Title of the asset picker dialog"
|
||||
|
|
@ -39,8 +43,9 @@
|
|||
type="int" />
|
||||
</cc:interface>
|
||||
<cc:implementation>
|
||||
<div class="ccm-cms-asset-picker"
|
||||
<div class="ccm-cms-asset-picker"
|
||||
data-assettype="#{cc.attrs.assetType}"
|
||||
data-contextpath="#{cc.attrs.contextPath}"
|
||||
data-contentsection="#{cc.attrs.contentSection}">
|
||||
<div aria-hidden="true"
|
||||
aria-labelledby="#{cc.attrs.assetPickerId}-dialog-title"
|
||||
|
|
@ -88,7 +93,7 @@
|
|||
</button>
|
||||
</div>
|
||||
<form action="#{cc.attrs.actionUrl}"
|
||||
class="modal-content"
|
||||
class="modal-body"
|
||||
method="post">
|
||||
<input class="assetpicker-param"
|
||||
id="#{cc.attrs.assetPickerId}-param-input"
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
class="modal-content"
|
||||
method="post">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-header"
|
||||
<h4 class="modal-title"
|
||||
id="add-contactentry-dialog-title">
|
||||
#{CmsAssetsStepsDefaultMessagesBundle['contactable.contactentries.add.title']}
|
||||
</h4>
|
||||
|
|
@ -213,6 +213,7 @@
|
|||
actionUrl="#{actionBaseUrl}/postaladdress"
|
||||
assetType="#{CmsContactableEditStepModel.postalAddressType}"
|
||||
assetPickerId="postaladdress-picker"
|
||||
contextPath="#{CmsContactableEditStepModel.contextPath}"
|
||||
contentSection="#{ContentSectionModel.sectionName}"
|
||||
formParamName="postalAddressIdentifier"
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@
|
|||
<tbody>
|
||||
<c:forEach items="#{CmsPersonEditStepModel.personNames}"
|
||||
var="personName">
|
||||
<tr>
|
||||
<tr data-index="#{personName.index}">
|
||||
<td>#{personName.prefix}</td>
|
||||
<td>#{personName.surname}</td>
|
||||
<td>#{personName.givenName}</td>
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
id="personname-edit-dialog-#{personName.hashCode()}"
|
||||
tabindex="-1">
|
||||
<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"
|
||||
method="post">
|
||||
<div class="modal-header">
|
||||
|
|
@ -192,7 +192,7 @@
|
|||
id="personname-remove-dialog-#{personName.hashCode()}"
|
||||
tabindex="-1">
|
||||
<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"
|
||||
method="post">
|
||||
<div class="modal-header">
|
||||
|
|
|
|||
|
|
@ -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.label=Suffix
|
||||
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.dialog.title=Remove Person Name
|
||||
person.personname.remove.dialog.close=Cancel
|
||||
|
|
@ -273,3 +273,13 @@ contactable.postaladdress.set=Set postal address
|
|||
person.personname.givenname.label=Given name
|
||||
person.personname.add.dialog.close=Cancel
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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.label=Suffix
|
||||
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.dialog.title=Namen entfernen
|
||||
person.personname.remove.dialog.close=Abbrechen
|
||||
|
|
@ -273,3 +273,13 @@ contactable.postaladdress.set=Postanschrift setzen
|
|||
person.personname.givenname.label=Vorname
|
||||
person.personname.add.dialog.close=Abbrechen
|
||||
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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import * as $ from "jquery";
|
||||
|
||||
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++) {
|
||||
initAssetPicker(assetPickers[i]);
|
||||
|
|
@ -11,12 +11,15 @@ document.addEventListener("DOMContentLoaded", function (event) {
|
|||
async function initAssetPicker(assetPickerElem: Element) {
|
||||
const assetPickerId = assetPickerElem.getAttribute("id");
|
||||
const assetType = getAssetType(assetPickerElem);
|
||||
const contextPath = assetPickerElem.getAttribute("data-contextpath");
|
||||
const contentSection = assetPickerElem.getAttribute("data-contentsection");
|
||||
|
||||
const fetchUrl = contextPath
|
||||
? `./${contextPath}/content-sections/${contentSection}/assets/?type=${assetType}`
|
||||
: `./content-sections/${contentSection}/assets/?type=${assetType}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(
|
||||
`/content-sections/${contentSection}/assets/?type=${assetType}`
|
||||
);
|
||||
const response = await fetch(fetchUrl);
|
||||
|
||||
if (response.ok) {
|
||||
const assets = (await response.json()) as [];
|
||||
|
|
|
|||
Loading…
Reference in New Issue