CCM NG: Form for Person asset
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@6154 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
dc1379a1c3
commit
33aad81580
|
|
@ -36,8 +36,13 @@ import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
import org.librecms.assets.Person;
|
import org.librecms.assets.Person;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -50,8 +55,11 @@ import static org.librecms.CmsConstants.*;
|
||||||
public class PersonForm extends AbstractContactableEntityForm<Person> {
|
public class PersonForm extends AbstractContactableEntityForm<Person> {
|
||||||
|
|
||||||
private TextField surnameField;
|
private TextField surnameField;
|
||||||
|
|
||||||
private TextField givenNameField;
|
private TextField givenNameField;
|
||||||
|
|
||||||
private TextField prefixField;
|
private TextField prefixField;
|
||||||
|
|
||||||
private TextField suffixField;
|
private TextField suffixField;
|
||||||
|
|
||||||
private Submit addPersonNameButton;
|
private Submit addPersonNameButton;
|
||||||
|
|
@ -77,7 +85,7 @@ public class PersonForm extends AbstractContactableEntityForm<Person> {
|
||||||
CMS_BUNDLE));
|
CMS_BUNDLE));
|
||||||
givenNameField = new TextField("givenName");
|
givenNameField = new TextField("givenName");
|
||||||
add(givenNameLabel);
|
add(givenNameLabel);
|
||||||
add(surnameLabel);
|
add(givenNameField);
|
||||||
|
|
||||||
final Label prefixLabel = new Label(new GlobalizedMessage(
|
final Label prefixLabel = new Label(new GlobalizedMessage(
|
||||||
"cms.ui.authoring.assets.person.prefix",
|
"cms.ui.authoring.assets.person.prefix",
|
||||||
|
|
@ -107,22 +115,38 @@ public class PersonForm extends AbstractContactableEntityForm<Person> {
|
||||||
CMS_BUNDLE));
|
CMS_BUNDLE));
|
||||||
add(birthdateLabel);
|
add(birthdateLabel);
|
||||||
birthdateField = new Date("birthdate");
|
birthdateField = new Date("birthdate");
|
||||||
|
add(birthdateField);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<Person> getAssetClass() {
|
protected Class<Person> getAssetClass() {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
return Person.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void showLocale(PageState state) {
|
protected void showLocale(final PageState state) {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
||||||
|
// Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, Object> collectData(FormSectionEvent event) throws
|
protected Map<String, Object> collectData(
|
||||||
FormProcessException {
|
final FormSectionEvent event) throws FormProcessException {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
final Map<String, Object> data = new HashMap<>();
|
||||||
|
|
||||||
|
data.put(PersonFormController.SURNAME, surnameField.getValue(state));
|
||||||
|
data.put(PersonFormController.GIVENNAME,
|
||||||
|
givenNameField.getValue(state));
|
||||||
|
data.put(PersonFormController.PREFIX, prefixField.getValue(state));
|
||||||
|
data.put(PersonFormController.SUFFIX, suffixField.getValue(state));
|
||||||
|
|
||||||
|
data.put(PersonFormController.BIRTHDATE,
|
||||||
|
birthdateField.getValue(state));
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -130,15 +154,50 @@ public class PersonForm extends AbstractContactableEntityForm<Person> {
|
||||||
|
|
||||||
super.init(event);
|
super.init(event);
|
||||||
|
|
||||||
// ToDo
|
final PageState state = event.getPageState();
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
|
final Map<String, Object> data = getController()
|
||||||
|
.getAssetData(getSelectedAssetId(state),
|
||||||
|
getAssetClass(),
|
||||||
|
getSelectedLocale(state));
|
||||||
|
|
||||||
|
if (data.containsKey(PersonFormController.SURNAME)) {
|
||||||
|
surnameField.setValue(state,
|
||||||
|
data.get(PersonFormController.SURNAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.containsKey(PersonFormController.GIVENNAME)) {
|
||||||
|
givenNameField.setValue(state,
|
||||||
|
data.get(PersonFormController.GIVENNAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.containsKey(PersonFormController.PREFIX)) {
|
||||||
|
prefixField.setValue(state, data.get(PersonFormController.PREFIX));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.containsKey(PersonFormController.SUFFIX)) {
|
||||||
|
suffixField.setValue(state, data.get(PersonFormController.SUFFIX));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.containsKey(PersonFormController.BIRTHDATE)) {
|
||||||
|
birthdateField.setValue(state,
|
||||||
|
data.get(PersonFormController.BIRTHDATE));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(final FormSectionEvent event) throws
|
public void process(final FormSectionEvent event) throws
|
||||||
FormProcessException {
|
FormProcessException {
|
||||||
// ToDo
|
|
||||||
throw new UnsupportedOperationException();
|
if (addPersonNameButton.equals(event.getSource())) {
|
||||||
|
|
||||||
|
final PersonFormController controller
|
||||||
|
= (PersonFormController) getController();
|
||||||
|
controller.addPersonName(getSelectedAssetId(event.getPageState()));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
super.process(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Table buildPersonNamesTable() {
|
private Table buildPersonNamesTable() {
|
||||||
|
|
@ -218,6 +277,7 @@ public class PersonForm extends AbstractContactableEntityForm<Person> {
|
||||||
private final Iterator<String[]> personNames;
|
private final Iterator<String[]> personNames;
|
||||||
|
|
||||||
private String[] currentPersonName;
|
private String[] currentPersonName;
|
||||||
|
|
||||||
private int row;
|
private int row;
|
||||||
|
|
||||||
public PersonNamesTableModel(final List<String[]> personNames) {
|
public PersonNamesTableModel(final List<String[]> personNames) {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,11 @@ import org.librecms.assets.PersonManager;
|
||||||
import org.librecms.assets.PersonName;
|
import org.librecms.assets.PersonName;
|
||||||
import org.librecms.assets.PersonRepository;
|
import org.librecms.assets.PersonRepository;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -44,15 +48,23 @@ public class PersonFormController
|
||||||
extends AbstractContactableEntityFormController<Person> {
|
extends AbstractContactableEntityFormController<Person> {
|
||||||
|
|
||||||
protected static final String SUFFIX = "suffix";
|
protected static final String SUFFIX = "suffix";
|
||||||
|
|
||||||
protected static final String PREFIX = "prefix";
|
protected static final String PREFIX = "prefix";
|
||||||
|
|
||||||
protected static final String GIVENNAME = "givenName";
|
protected static final String GIVENNAME = "givenName";
|
||||||
|
|
||||||
protected static final String SURNAME = "surname";
|
protected static final String SURNAME = "surname";
|
||||||
|
|
||||||
protected static final String BIRTHDATE = "birthdate";
|
protected static final String BIRTHDATE = "birthdate";
|
||||||
|
|
||||||
protected static final String PERSON_NAMES = "personNames";
|
protected static final String PERSON_NAMES = "personNames";
|
||||||
|
|
||||||
protected static final int SURNAME_INDEX = 0;
|
protected static final int SURNAME_INDEX = 0;
|
||||||
|
|
||||||
protected static final int GIVENNAME_INDEX = 1;
|
protected static final int GIVENNAME_INDEX = 1;
|
||||||
|
|
||||||
protected static final int PREFIX_INDEX = 2;
|
protected static final int PREFIX_INDEX = 2;
|
||||||
|
|
||||||
protected static final int SUFFIX_INDEX = 3;
|
protected static final int SUFFIX_INDEX = 3;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
|
@ -82,7 +94,12 @@ public class PersonFormController
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
data.put(PERSON_NAMES, names);
|
data.put(PERSON_NAMES, names);
|
||||||
|
|
||||||
data.put(BIRTHDATE, asset.getBirthdate());
|
final LocalDate birthdate = asset.getBirthdate();
|
||||||
|
if (birthdate != null) {
|
||||||
|
final Instant instant = Instant.from(birthdate);
|
||||||
|
final Date birthdateValue = Date.from(instant);
|
||||||
|
data.put(BIRTHDATE, birthdateValue);
|
||||||
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +140,13 @@ public class PersonFormController
|
||||||
|
|
||||||
if (data.containsKey(BIRTHDATE)) {
|
if (data.containsKey(BIRTHDATE)) {
|
||||||
|
|
||||||
asset.setBirthdate((LocalDate) data.get(BIRTHDATE));
|
final Date birthdateValue = (Date) data.get(BIRTHDATE);
|
||||||
|
final Instant instant = birthdateValue.toInstant();
|
||||||
|
final LocalDate birthdate = LocalDateTime
|
||||||
|
.ofInstant(instant, ZoneId.systemDefault())
|
||||||
|
.toLocalDate();
|
||||||
|
|
||||||
|
asset.setBirthdate(birthdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String surname = (String) data.get(SURNAME);
|
final String surname = (String) data.get(SURNAME);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue