diff --git a/ccm-cms-types-member/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Member.xml b/ccm-cms-types-member/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Member.xml index d3299cd81..5c8e8f144 100644 --- a/ccm-cms-types-member/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Member.xml +++ b/ccm-cms-types-member/src/WEB-INF/content-types/com/arsdigita/cms/contenttypes/Member.xml @@ -11,7 +11,7 @@ classname="com.arsdigita.cms.contenttypes.Member"> + createComponent="com.arsdigita.cms.contenttypes.ui.GenericPersonCreate"> - + + */ +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-]", "_"); + } +} diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java index ead2d6c0e..c01ed1192 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertiesStep.java @@ -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()) { sheet.add((String) ContenttypesGlobalizationUtil.globalize("cms.ui.authoring.page_launch_date").localize(), ContentPage.LAUNCH_DATE, diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertyForm.java index 37df906a3..609009eb6 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/GenericPersonPropertyForm.java @@ -19,11 +19,14 @@ package com.arsdigita.cms.contenttypes.ui; import com.arsdigita.bebop.FormData; +import com.arsdigita.bebop.FormSection; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; 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.TextField; 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 TITLEPOST = GenericPerson.TITLEPOST; 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 ID = "Person_edit"; @@ -69,26 +73,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc @Override protected void addWidgets() { super.addWidgets(); - - 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); + mandatoryFieldWidgets(this); add(new Label((String) ContenttypesGlobalizationUtil.globalize("cms.contenttypes.ui.person.birthdate").localize())); ParameterModel birthdateParam = new DateParameter(BIRTHDATE); @@ -97,6 +82,14 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc birthdate.setYearRange(1900, today.get(Calendar.YEAR)); 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())); ParameterModel descriptionParam = new StringParameter(DESCRIPTION); 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) { FormData data = fse.getFormData(); GenericPerson person = (GenericPerson) super.initBasicWidgets(fse); @@ -115,6 +130,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc data.put(TITLEPRE, person.getTitlePre()); data.put(TITLEPOST, person.getTitlePost()); data.put(BIRTHDATE, person.getBirthdate()); + data.put(GENDER, person.getGender()); data.put(DESCRIPTION, person.getDescription()); } @@ -137,6 +153,7 @@ public class GenericPersonPropertyForm extends BasicPageForm implements FormProc person.setTitlePre((String) data.get(TITLEPRE)); person.setTitlePost((String) data.get(TITLEPOST)); person.setBirthdate((Date) data.get(BIRTHDATE)); + person.setGender((String) data.get(GENDER)); person.setDescription((String)data.get(DESCRIPTION)); person.save(); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/authoring/BasicItemForm.java b/ccm-cms/src/com/arsdigita/cms/ui/authoring/BasicItemForm.java index 4ed151079..e0a969d5c 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/authoring/BasicItemForm.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/authoring/BasicItemForm.java @@ -231,6 +231,11 @@ public abstract class BasicItemForm extends FormSection FormData data = event.getFormData(); String newName = (String) data.get(NAME); + validateNameUniqueness(parent, event, newName); + } + + public void validateNameUniqueness(Folder parent, FormSectionEvent event, String newName) + throws FormProcessException { if ( newName != null ) { final String query = "com.arsdigita.cms.validateUniqueItemName"; DataQuery dq = SessionManager.getSession().retrieveQuery(query); diff --git a/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreate.java b/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreate.java index 7616dc438..f037ce41a 100755 --- a/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreate.java +++ b/ccm-cms/src/com/arsdigita/cms/ui/authoring/PageCreate.java @@ -50,8 +50,8 @@ public class PageCreate extends BasicPageForm private static final Logger s_log = Logger.getLogger(PageCreate.class); - private final CreationSelector m_parent; - private ApplyWorkflowFormSection m_workflowSection; + protected final CreationSelector m_parent; + protected ApplyWorkflowFormSection m_workflowSection; /** * The state parameter which specifies the content section @@ -125,6 +125,7 @@ public class PageCreate extends BasicPageForm } // Validate: ensure name uniqueness + @Override public void validate(FormSectionEvent e) throws FormProcessException { Folder f = m_parent.getFolder(e.getPageState()); Assert.exists(f);