GenericPerson

* neuer, eigener CreateStep erzeugt (GenericPersonCreate). Von GenericPerson abgeleitete CTs müssen diese Klasse als createComponent in der AuthoringKit-XML-Datei eingetragen, damit der Name und der Titel des CIs automatisch erzeugt werden.

 * Eintrag für Geschlecht hinzugefügt.

Member

 * creationComponent geändert

git-svn-id: https://svn.libreccm.org/ccm/trunk@560 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2010-10-07 08:26:34 +00:00
parent d28cd2cb26
commit c5d55d7f00
11 changed files with 232 additions and 35 deletions

View File

@ -11,7 +11,7 @@
classname="com.arsdigita.cms.contenttypes.Member"> classname="com.arsdigita.cms.contenttypes.Member">
<ctd:authoring-kit <ctd:authoring-kit
createComponent="com.arsdigita.cms.ui.authoring.PageCreate"> createComponent="com.arsdigita.cms.contenttypes.ui.GenericPersonCreate">
<ctd:authoring-step <ctd:authoring-step
labelKey="cms.contenttypes.shared.basic_properties.title" labelKey="cms.contenttypes.shared.basic_properties.title"

View File

@ -28,6 +28,7 @@ object type GenericPerson extends ContentPage {
String[0..1] titlepost = cms_persons.titlepost VARCHAR(256); String[0..1] titlepost = cms_persons.titlepost VARCHAR(256);
Date[0..1] birthdate = cms_persons.birthdate DATE; Date[0..1] birthdate = cms_persons.birthdate DATE;
String[0..1] gender = cms_persons.gender CHAR(1);
reference key (cms_persons.person_id); reference key (cms_persons.person_id);
} }

View File

@ -11,7 +11,7 @@
classname="com.arsdigita.cms.contenttypes.GenericPerson" classname="com.arsdigita.cms.contenttypes.GenericPerson"
isInternal="yes"> isInternal="yes">
<ctd:authoring-kit createComponent="com.arsdigita.cms.ui.authoring.PageCreate"> <ctd:authoring-kit createComponent="com.arsdigita.cms.contenttypes.ui.GenericPersonCreate">
<ctd:authoring-step <ctd:authoring-step
labelKey="cms.contenttypes.shared.basic_properties.title" labelKey="cms.contenttypes.shared.basic_properties.title"

View File

@ -19,6 +19,10 @@ cms.contenttypes.ui.person.titlepost=Name appendix
cms.contenttypes.ui.person.birthdate=Birth date cms.contenttypes.ui.person.birthdate=Birth date
cms.contenttypes.ui.person.description=Description cms.contenttypes.ui.person.description=Description
cms.contenttypes.ui.person.gender=Gender
cms.contenttypes.ui.person.gender.f=Female
cms.contenttypes.ui.person.gender.m=Male
cms.contenttypes.ui.person.contact=Contacts cms.contenttypes.ui.person.contact=Contacts
cms.contenttypes.ui.person.contacts.none=No contacts cms.contenttypes.ui.person.contacts.none=No contacts
cms.contenttypes.ui.person.add_contact=Add contact cms.contenttypes.ui.person.add_contact=Add contact

View File

@ -19,6 +19,10 @@ cms.contenttypes.ui.person.titlepost=Namesanhang
cms.contenttypes.ui.person.birthdate=Geburtstag cms.contenttypes.ui.person.birthdate=Geburtstag
cms.contenttypes.ui.person.description=Beschreibung cms.contenttypes.ui.person.description=Beschreibung
cms.contenttypes.ui.person.gender=Geschlecht
cms.contenttypes.ui.person.gender.f=Weiblich
cms.contenttypes.ui.person.gender.m=M\u00e4nnlich
cms.contenttypes.ui.person.contact=Kontakte cms.contenttypes.ui.person.contact=Kontakte
cms.contenttypes.ui.person.contacts.none=Zur Zeit sind keine Kontakte vorhanden cms.contenttypes.ui.person.contacts.none=Zur Zeit sind keine Kontakte vorhanden
cms.contenttypes.ui.person.add_contact=Kontakt hinzuf\u00fcgen cms.contenttypes.ui.person.add_contact=Kontakt hinzuf\u00fcgen

View File

@ -44,6 +44,7 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
public static final String TITLEPRE = "titlepre"; public static final String TITLEPRE = "titlepre";
public static final String TITLEPOST = "titlepost"; public static final String TITLEPOST = "titlepost";
public static final String BIRTHDATE = "birthdate"; public static final String BIRTHDATE = "birthdate";
public static final String GENDER = "gender";
public static final String CONTACTS = "contacts"; public static final String CONTACTS = "contacts";
public static final String CONTACT_TYPE = "contact_type"; public static final String CONTACT_TYPE = "contact_type";
public static final String CONTACT_ORDER = "contact_order"; public static final String CONTACT_ORDER = "contact_order";
@ -103,14 +104,6 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
return (String) get(TITLEPRE); return (String) get(TITLEPRE);
} }
public Date getBirthdate() {
return (Date) get(BIRTHDATE);
}
public void setBirthdate(Date birthdate) {
set(BIRTHDATE, birthdate);
}
public void setTitlePre(String titlePre) { public void setTitlePre(String titlePre) {
set(TITLEPRE, titlePre); set(TITLEPRE, titlePre);
} }
@ -123,6 +116,22 @@ public class GenericPerson extends ContentPage implements RelationAttributeInter
set(TITLEPOST, titlePost); set(TITLEPOST, titlePost);
} }
public Date getBirthdate() {
return (Date) get(BIRTHDATE);
}
public void setBirthdate(Date birthdate) {
set(BIRTHDATE, birthdate);
}
public String getGender() {
return (String) get(GENDER);
}
public void setGender(String gender) {
set(GENDER, gender);
}
/** /**
* A convinient method which combines {@code titlePre}, {@code givenName), * A convinient method which combines {@code titlePre}, {@code givenName),
* {@code surname} and {@code titlePost}. * {@code surname} and {@code titlePost}.

View File

@ -0,0 +1,139 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.parameters.DateParameter;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.Folder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection;
import com.arsdigita.cms.ui.authoring.CreationSelector;
import com.arsdigita.cms.ui.authoring.LanguageWidget;
import com.arsdigita.cms.ui.authoring.PageCreate;
import com.arsdigita.util.Assert;
import java.util.Date;
/**
*
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
*/
public class GenericPersonCreate extends PageCreate {
private static final String SURNAME = GenericPerson.SURNAME;
private static final String GIVENNAME = GenericPerson.GIVENNAME;
private static final String TITLEPRE = GenericPerson.TITLEPRE;
private static final String TITLEPOST = GenericPerson.TITLEPOST;
public GenericPersonCreate(final ItemSelectionModel itemModel, final CreationSelector parent) {
super(itemModel, parent);
}
@Override
protected void addWidgets() {
ContentType type = getItemSelectionModel().getContentType();
m_workflowSection = new ApplyWorkflowFormSection(type);
add(m_workflowSection, ColumnPanel.INSERT);
add(new Label(GlobalizationUtil.globalize("cms.ui.authoring.content_type")));
add(new Label(type.getLabel()));
add(new Label(GlobalizationUtil.globalize("cms.ui.language.field")));
add(new LanguageWidget(LANGUAGE));
// Set all mandatory field widgets which will be used to generat the title and name
GenericPersonPropertyForm.mandatoryFieldWidgets(this);
if (!ContentSection.getConfig().getHideLaunchDate()) {
add(new Label(GlobalizationUtil.globalize("cms.ui.authoring.page_launch_date")));
ParameterModel launchDateParam = new DateParameter(LAUNCH_DATE);
com.arsdigita.bebop.form.Date launchDate = new com.arsdigita.bebop.form.Date(launchDateParam);
if (ContentSection.getConfig().getRequireLaunchDate()) {
launchDate.addValidationListener(new LaunchDateValidationListener());
// if launch date is required, help user by suggesting today's date
launchDateParam.setDefaultValue(new Date());
}
add(launchDate);
}
}
// Validate: ensure name uniqueness
@Override
public void validate(FormSectionEvent e) throws FormProcessException {
Folder f = m_parent.getFolder(e.getPageState());
Assert.exists(f);
validateNameUniqueness(f, e, urlSave(getFullname(e)));
}
// Process: save fields to the database
@Override
public void process(final FormSectionEvent e) throws FormProcessException {
final FormData data = e.getFormData();
final PageState state = e.getPageState();
final ContentSection section = m_parent.getContentSection(state);
Folder folder = m_parent.getFolder(state);
String fullName = getFullname(e);
Assert.exists(section, ContentSection.class);
final ContentPage item = createContentPage(state);
item.setLanguage((String) data.get(LANGUAGE));
item.setName(urlSave(fullName));
item.setTitle(fullName);
if (!ContentSection.getConfig().getHideLaunchDate()) {
item.setLaunchDate((Date) data.get(LAUNCH_DATE));
}
final ContentBundle bundle = new ContentBundle(item);
bundle.setParent(folder);
bundle.setContentSection(m_parent.getContentSection(state));
bundle.save();
m_workflowSection.applyWorkflow(state, item);
GenericPerson person = new GenericPerson(item.getOID());
person.setTitlePre(data.getString(TITLEPRE));
person.setGivenName(data.getString(GIVENNAME));
person.setSurname(data.getString(SURNAME));
person.setTitlePost(data.getString(TITLEPOST));
person.save();
m_parent.editItem(state, item);
}
//
private String getFullname(FormSectionEvent e) {
final FormData data = e.getFormData();
return data.getString(TITLEPRE) + " " + data.getString(GIVENNAME) + " " + data.getString(SURNAME) + " " + data.getString(TITLEPOST);
}
// Create a ulr save version of the full name
private String urlSave(String in) {
// Replacement map
String[][] replacements = {{"ä", "ae"}, {"Ä", "Ae"}, {"ö", "oe"}, {"Ö", "Oe"}, {"ü", "ue"}, {"Ü", "Ue"}, {"ß", "ss"}, {".", ""}};
// Replace all spaces with dash
String out = in.replace(" ", "-");
// Replace all special chars defined in replacement map
for (int i = 0; i < replacements.length; i++) {
out = out.replace(replacements[i][0], replacements[i][1]);
}
// Replace all special chars that are not yet replaced with a dash
return out.replaceAll("[^A-Za-z0-9-]", "_");
}
}

View File

@ -94,6 +94,23 @@ public class GenericPersonPropertiesStep extends SimpleEditStep {
} }
}); });
sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender").localize(),
GenericPerson.GENDER,
new DomainObjectPropertySheet.AttributeFormatter() {
public String format(DomainObject item,
String attribute,
PageState state) {
//ContentPage page = (ContentPage) item;
GenericPerson person = (GenericPerson) item;
if (person.getGender() != null) {
return (String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender." + person.getGender().toLowerCase()).localize();
} else {
return (String) ContenttypesGlobalizationUtil.globalize("cms.ui.unknown").localize();
}
}
});
if (!ContentSection.getConfig().getHideLaunchDate()) { if (!ContentSection.getConfig().getHideLaunchDate()) {
sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.ui.authoring.page_launch_date").localize(), sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.ui.authoring.page_launch_date").localize(),
ContentPage.LAUNCH_DATE, ContentPage.LAUNCH_DATE,

View File

@ -19,11 +19,14 @@
package com.arsdigita.cms.contenttypes.ui; package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.FormData; import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormSection;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextArea; import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.DateParameter; import com.arsdigita.bebop.parameters.DateParameter;
@ -53,6 +56,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc
public static final String TITLEPRE = GenericPerson.TITLEPRE; public static final String TITLEPRE = GenericPerson.TITLEPRE;
public static final String TITLEPOST = GenericPerson.TITLEPOST; public static final String TITLEPOST = GenericPerson.TITLEPOST;
public static final String BIRTHDATE = GenericPerson.BIRTHDATE; public static final String BIRTHDATE = GenericPerson.BIRTHDATE;
public static final String GENDER = GenericPerson.GENDER;
public static final String DESCRIPTION = GenericPerson.DESCRIPTION; public static final String DESCRIPTION = GenericPerson.DESCRIPTION;
public static final String ID = "Person_edit"; public static final String ID = "Person_edit";
@ -69,26 +73,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc
@Override @Override
protected void addWidgets() { protected void addWidgets() {
super.addWidgets(); super.addWidgets();
mandatoryFieldWidgets(this);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.surname").localize()));
ParameterModel surnameParam = new StringParameter(SURNAME);
TextField surname = new TextField(surnameParam);
add(surname);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.givenname").localize()));
ParameterModel givennameParam = new StringParameter(GIVENNAME);
TextField givenname = new TextField(givennameParam);
add(givenname);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepre").localize()));
ParameterModel titlepreParam = new StringParameter(TITLEPRE);
TextField titlepre = new TextField(titlepreParam);
add(titlepre);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepost").localize()));
ParameterModel titlepostParam = new StringParameter(TITLEPOST);
TextField titlepost = new TextField(titlepostParam);
add(titlepost);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.birthdate").localize())); add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.birthdate").localize()));
ParameterModel birthdateParam = new DateParameter(BIRTHDATE); ParameterModel birthdateParam = new DateParameter(BIRTHDATE);
@ -97,6 +82,14 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc
birthdate.setYearRange(1900, today.get(Calendar.YEAR)); birthdate.setYearRange(1900, today.get(Calendar.YEAR));
add(birthdate); add(birthdate);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender").localize()));
ParameterModel genderParam = new StringParameter(GENDER);
SingleSelect gender = new SingleSelect(genderParam);
gender.addOption(new Option("", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.ui.select_one").localize())));
gender.addOption(new Option("f", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender.f").localize())));
gender.addOption(new Option("m", new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.gender.m").localize())));
add(gender);
add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.description").localize())); add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.description").localize()));
ParameterModel descriptionParam = new StringParameter(DESCRIPTION); ParameterModel descriptionParam = new StringParameter(DESCRIPTION);
TextArea description = new TextArea(descriptionParam); TextArea description = new TextArea(descriptionParam);
@ -106,6 +99,28 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc
} }
public static void mandatoryFieldWidgets(FormSection form) {
form.add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.surname").localize()));
ParameterModel surnameParam = new StringParameter(SURNAME);
TextField surname = new TextField(surnameParam);
form.add(surname);
form.add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.givenname").localize()));
ParameterModel givennameParam = new StringParameter(GIVENNAME);
TextField givenname = new TextField(givennameParam);
form.add(givenname);
form.add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepre").localize()));
ParameterModel titlepreParam = new StringParameter(TITLEPRE);
TextField titlepre = new TextField(titlepreParam);
form.add(titlepre);
form.add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.titlepost").localize()));
ParameterModel titlepostParam = new StringParameter(TITLEPOST);
TextField titlepost = new TextField(titlepostParam);
form.add(titlepost);
}
public void init(FormSectionEvent fse) { public void init(FormSectionEvent fse) {
FormData data = fse.getFormData(); FormData data = fse.getFormData();
GenericPerson person = (GenericPerson) super.initBasicWidgets(fse); GenericPerson person = (GenericPerson) super.initBasicWidgets(fse);
@ -115,6 +130,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc
data.put(TITLEPRE, person.getTitlePre()); data.put(TITLEPRE, person.getTitlePre());
data.put(TITLEPOST, person.getTitlePost()); data.put(TITLEPOST, person.getTitlePost());
data.put(BIRTHDATE, person.getBirthdate()); data.put(BIRTHDATE, person.getBirthdate());
data.put(GENDER, person.getGender());
data.put(DESCRIPTION, person.getDescription()); data.put(DESCRIPTION, person.getDescription());
} }
@ -137,6 +153,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc
person.setTitlePre((String) data.get(TITLEPRE)); person.setTitlePre((String) data.get(TITLEPRE));
person.setTitlePost((String) data.get(TITLEPOST)); person.setTitlePost((String) data.get(TITLEPOST));
person.setBirthdate((Date) data.get(BIRTHDATE)); person.setBirthdate((Date) data.get(BIRTHDATE));
person.setGender((String) data.get(GENDER));
person.setDescription((String)data.get(DESCRIPTION)); person.setDescription((String)data.get(DESCRIPTION));
person.save(); person.save();

View File

@ -231,6 +231,11 @@ public abstract class BasicItemForm extends FormSection
FormData data = event.getFormData(); FormData data = event.getFormData();
String newName = (String) data.get(NAME); String newName = (String) data.get(NAME);
validateNameUniqueness(parent, event, newName);
}
public void validateNameUniqueness(Folder parent, FormSectionEvent event, String newName)
throws FormProcessException {
if ( newName != null ) { if ( newName != null ) {
final String query = "com.arsdigita.cms.validateUniqueItemName"; final String query = "com.arsdigita.cms.validateUniqueItemName";
DataQuery dq = SessionManager.getSession().retrieveQuery(query); DataQuery dq = SessionManager.getSession().retrieveQuery(query);

View File

@ -50,8 +50,8 @@ public class PageCreate extends BasicPageForm
private static final Logger s_log = Logger.getLogger(PageCreate.class); private static final Logger s_log = Logger.getLogger(PageCreate.class);
private final CreationSelector m_parent; protected final CreationSelector m_parent;
private ApplyWorkflowFormSection m_workflowSection; protected ApplyWorkflowFormSection m_workflowSection;
/** /**
* The state parameter which specifies the content section * The state parameter which specifies the content section
@ -125,6 +125,7 @@ public class PageCreate extends BasicPageForm
} }
// Validate: ensure name uniqueness // Validate: ensure name uniqueness
@Override
public void validate(FormSectionEvent e) throws FormProcessException { public void validate(FormSectionEvent e) throws FormProcessException {
Folder f = m_parent.getFolder(e.getPageState()); Folder f = m_parent.getFolder(e.getPageState());
Assert.exists(f); Assert.exists(f);