CCM NG/ccm-cms: Forms for creating items of type Article, Event, MultiPartArticle and News
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4692 8810af33-2d31-482b-a856-94f89814c4df
parent
8657ce76e3
commit
c4cfcf8b55
|
|
@ -0,0 +1,161 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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 com.arsdigita.cms.contenttypes.ui.mparticle;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.FormSection;
|
||||||
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
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.event.FormValidationListener;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection;
|
||||||
|
import com.arsdigita.cms.ui.authoring.CreationComponent;
|
||||||
|
import com.arsdigita.cms.ui.authoring.CreationSelector;
|
||||||
|
import com.arsdigita.cms.ui.authoring.LanguageWidget;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
import java.util.Date;
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
import org.librecms.contenttypes.MultiPartArticle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A form which will create a MultiPartArticle or one of its subclasses.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:dturner@arsidigita.com">Dave Turner</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class MultiPartArticleCreateForm
|
||||||
|
extends MultiPartArticleForm
|
||||||
|
implements FormInitListener,
|
||||||
|
FormProcessListener,
|
||||||
|
FormSubmissionListener,
|
||||||
|
FormValidationListener,
|
||||||
|
CreationComponent {
|
||||||
|
|
||||||
|
private final CreationSelector creationSelector;
|
||||||
|
private ApplyWorkflowFormSection workflowSection;
|
||||||
|
|
||||||
|
public MultiPartArticleCreateForm(final ItemSelectionModel itemSelectionModel,
|
||||||
|
final CreationSelector creationSelector) {
|
||||||
|
super("MultiPartArticleCreate", itemSelectionModel);
|
||||||
|
this.creationSelector = creationSelector;
|
||||||
|
workflowSection.setCreationSelector(creationSelector);
|
||||||
|
workflowSection.setContentType(itemSelectionModel.getContentType());
|
||||||
|
addSubmissionListener(this);
|
||||||
|
getSaveCancelSection()
|
||||||
|
.getSaveButton()
|
||||||
|
.setButtonLabel(new GlobalizedMessage("cms.ui.create",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
workflowSection = new ApplyWorkflowFormSection();
|
||||||
|
add(workflowSection, ColumnPanel.INSERT);
|
||||||
|
add(new Label(new GlobalizedMessage("cms.ui.language.field",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
add(new LanguageWidget(LANGUAGE));
|
||||||
|
super.addWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the ApplyWorkflowFormSection associated with this
|
||||||
|
* CreationComponent.
|
||||||
|
*
|
||||||
|
* @return the ApplyWorkflowFormSection associated with this
|
||||||
|
* CreationComponent.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ApplyWorkflowFormSection getWorkflowSection() {
|
||||||
|
return workflowSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||||
|
// this is currently a no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void submitted(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (getSaveCancelSection().getCancelButton().isSelected(state)) {
|
||||||
|
creationSelector.redirectBack(state);
|
||||||
|
throw new FormProcessException(
|
||||||
|
"Submission cancelled",
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.mparticle.submission_cancelled",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final Folder folder = creationSelector.getFolder(event.getPageState());
|
||||||
|
if (!validateNameUniqueness(folder, event)) {
|
||||||
|
throw new FormProcessException(
|
||||||
|
"An item with this name already exists",
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.mparticle."
|
||||||
|
+ "an_item_with_this_name_already_exists",
|
||||||
|
CmsConstants.CMS_BUNDLE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent e) throws FormProcessException {
|
||||||
|
final FormData data = e.getFormData();
|
||||||
|
final PageState state = e.getPageState();
|
||||||
|
final ContentSection section = creationSelector.getContentSection(state);
|
||||||
|
final Folder folder = creationSelector.getFolder(state);
|
||||||
|
|
||||||
|
final MultiPartArticle article = createArticle(state,
|
||||||
|
(String) data.get(NAME),
|
||||||
|
section,
|
||||||
|
folder);
|
||||||
|
article.getTitle().addValue(KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) data.get(TITLE));
|
||||||
|
if (!CMSConfig.getConfig().isHideLaunchDate()) {
|
||||||
|
article.setLaunchDate((Date) data.get(LAUNCH_DATE));
|
||||||
|
}
|
||||||
|
article
|
||||||
|
.getSummary()
|
||||||
|
.addValue(KernelConfig.getConfig().getDefaultLocale(),
|
||||||
|
(String) data.get(SUMMARY));
|
||||||
|
|
||||||
|
workflowSection.applyWorkflow(state, article);
|
||||||
|
|
||||||
|
creationSelector.editItem(state, article);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,338 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2017 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 com.arsdigita.cms.contenttypes.ui.mparticle;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
|
import com.arsdigita.bebop.Embedded;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.FormSection;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.FormValidationListener;
|
||||||
|
import com.arsdigita.bebop.form.TextArea;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.bebop.parameters.DateParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
||||||
|
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||||
|
import com.arsdigita.bebop.parameters.ParameterModel;
|
||||||
|
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
||||||
|
import com.arsdigita.bebop.parameters.URLTokenValidationListener;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
import com.arsdigita.web.Web;
|
||||||
|
import com.arsdigita.xml.Element;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.arsdigita.cms.CMSConfig;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.librecms.CmsConstants;
|
||||||
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
import org.librecms.contentsection.ContentSection;
|
||||||
|
import org.librecms.contentsection.Folder;
|
||||||
|
import org.librecms.contenttypes.MultiPartArticle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A form for editing MultiPartArticle and subclasses.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:dturner@arsdigita.com">Dave Turner</a>
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public abstract class MultiPartArticleForm
|
||||||
|
extends FormSection
|
||||||
|
implements FormInitListener,
|
||||||
|
FormProcessListener,
|
||||||
|
FormValidationListener {
|
||||||
|
|
||||||
|
private ItemSelectionModel itemSelectionModel;
|
||||||
|
private SaveCancelSection saveCancelSection;
|
||||||
|
/**
|
||||||
|
* Constant property, placeholder for a JavaScript element.
|
||||||
|
*/
|
||||||
|
private final Embedded m_script = new Embedded(
|
||||||
|
String.format(""
|
||||||
|
+ "<script language=\"javascript\" "
|
||||||
|
+ " src=\"%s/javascript/manipulate-input.js\">"
|
||||||
|
+ "</script>",
|
||||||
|
Web.getWebappContextPath()),
|
||||||
|
false);
|
||||||
|
|
||||||
|
public static final String NAME = "name";
|
||||||
|
public static final String TITLE = "title";
|
||||||
|
public static final String SUMMARY = "summary";
|
||||||
|
public static final String LAUNCH_DATE = "launch_date";
|
||||||
|
public static final String LANGUAGE = "language";
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
|
MultiPartArticleForm.class);
|
||||||
|
|
||||||
|
public MultiPartArticleForm(final String formName,
|
||||||
|
final ItemSelectionModel itemSelectionModel) {
|
||||||
|
|
||||||
|
super(new ColumnPanel(2));
|
||||||
|
|
||||||
|
this.itemSelectionModel = itemSelectionModel;
|
||||||
|
|
||||||
|
ColumnPanel panel = (ColumnPanel) getPanel();
|
||||||
|
panel.setBorder(false);
|
||||||
|
panel.setPadColor("#FFFFFF");
|
||||||
|
panel.setColumnWidth(1, "20%");
|
||||||
|
panel.setColumnWidth(2, "80%");
|
||||||
|
panel.setWidth("100%");
|
||||||
|
|
||||||
|
addWidgets();
|
||||||
|
|
||||||
|
addSaveCancelSection();
|
||||||
|
|
||||||
|
addInitListener(this);
|
||||||
|
addProcessListener(this);
|
||||||
|
addValidationListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSaveCancelSection() {
|
||||||
|
saveCancelSection = new SaveCancelSection();
|
||||||
|
add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SaveCancelSection getSaveCancelSection() {
|
||||||
|
return saveCancelSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addWidgets() {
|
||||||
|
|
||||||
|
// add(new Label(GlobalizationUtil
|
||||||
|
// .globalize("cms.contenttypes.ui.title")));
|
||||||
|
TextField titleWidget = new TextField(new TrimmedStringParameter(TITLE));
|
||||||
|
titleWidget.setLabel(new GlobalizedMessage("cms.contenttypes.ui.title",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
titleWidget.addValidationListener(new NotNullValidationListener());
|
||||||
|
titleWidget.setOnFocus("if (this.form." + NAME + ".value == '') { "
|
||||||
|
+ " defaulting = true; this.form." + NAME
|
||||||
|
+ ".value = urlize(this.value); }");
|
||||||
|
titleWidget.setOnKeyUp(
|
||||||
|
"if (defaulting) { this.form." + NAME
|
||||||
|
+ ".value = urlize(this.value) }"
|
||||||
|
);
|
||||||
|
add(titleWidget);
|
||||||
|
|
||||||
|
//add(new Label(GlobalizationUtil
|
||||||
|
// .globalize("cms.contenttypes.ui.name")));
|
||||||
|
TextField nameWidget = new TextField(new TrimmedStringParameter(NAME));
|
||||||
|
nameWidget.setLabel(new GlobalizedMessage("cms.contenttypes.ui.name",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
nameWidget.addValidationListener(new NotNullValidationListener());
|
||||||
|
nameWidget.addValidationListener(new URLTokenValidationListener());
|
||||||
|
nameWidget.setOnFocus("defaulting = false");
|
||||||
|
nameWidget.setOnBlur(
|
||||||
|
"if (this.value == '') "
|
||||||
|
+ "{ defaulting = true; this.value = urlize(this.form." + TITLE
|
||||||
|
+ ".value) }"
|
||||||
|
);
|
||||||
|
add(nameWidget);
|
||||||
|
|
||||||
|
if (!CMSConfig.getConfig().isHideLaunchDate()) {
|
||||||
|
//add(new Label(GlobalizationUtil
|
||||||
|
// .globalize("cms.ui.authoring.page_launch_date")));
|
||||||
|
final ParameterModel launchDateParam = new DateParameter(LAUNCH_DATE);
|
||||||
|
com.arsdigita.bebop.form.Date launchDate
|
||||||
|
= new com.arsdigita.bebop.form.Date(
|
||||||
|
launchDateParam);
|
||||||
|
if (CMSConfig.getConfig().isRequireLaunchDate()) {
|
||||||
|
launchDate.addValidationListener(new NotNullValidationListener(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.mparticle.no_launch_date",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
// if launch date is required, help user by suggesting today's date
|
||||||
|
launchDateParam.setDefaultValue(new Date());
|
||||||
|
}
|
||||||
|
launchDate.setLabel(new GlobalizedMessage(
|
||||||
|
"cms.ui.authoring.page_launch_date",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
add(launchDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
//add(new Label(GlobalizationUtil
|
||||||
|
// .globalize("cms.contenttypes.ui.summary")));
|
||||||
|
final TextArea summaryWidget = new TextArea(
|
||||||
|
new TrimmedStringParameter(SUMMARY));
|
||||||
|
if (CMSConfig.getConfig().isMandatoryDescriptions()) {
|
||||||
|
summaryWidget
|
||||||
|
.addValidationListener(new NotEmptyValidationListener(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.description_missing",
|
||||||
|
CmsConstants.CMS_BUNDLE)));
|
||||||
|
}
|
||||||
|
summaryWidget.setLabel(new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.summary",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
summaryWidget.setRows(5);
|
||||||
|
summaryWidget.setCols(30);
|
||||||
|
summaryWidget.setHint(new GlobalizedMessage(
|
||||||
|
"cms.contenttypes.ui.summary_hint",
|
||||||
|
CmsConstants.CMS_BUNDLE));
|
||||||
|
add(summaryWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void init(final FormSectionEvent event)
|
||||||
|
throws FormProcessException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract void validate(final FormSectionEvent event)
|
||||||
|
throws FormProcessException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to initialise the name/title/summary widgets.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public MultiPartArticle initBasicWidgets(final FormSectionEvent event) {
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final MultiPartArticle article = (MultiPartArticle) itemSelectionModel
|
||||||
|
.getSelectedObject(state);
|
||||||
|
|
||||||
|
if (article != null) {
|
||||||
|
data.put(NAME, article.getName());
|
||||||
|
data.put(TITLE, article.getTitle());
|
||||||
|
if (!CMSConfig.getConfig().isHideLaunchDate()) {
|
||||||
|
data.put(LAUNCH_DATE, article.getLaunchDate());
|
||||||
|
}
|
||||||
|
data.put(SUMMARY, article.getSummary());
|
||||||
|
}
|
||||||
|
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to process the name/title/summary widgets.
|
||||||
|
*
|
||||||
|
* @param event
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public MultiPartArticle processBasicWidgets(final FormSectionEvent event) {
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final MultiPartArticle article = (MultiPartArticle) itemSelectionModel
|
||||||
|
.getSelectedObject(state);
|
||||||
|
|
||||||
|
if (article != null) {
|
||||||
|
final Locale defaultLocale = KernelConfig.getConfig().
|
||||||
|
getDefaultLocale();
|
||||||
|
article.getName().addValue(defaultLocale,
|
||||||
|
(String) data.get(NAME));
|
||||||
|
article.getTitle().addValue(defaultLocale,
|
||||||
|
(String) data.get(TITLE));
|
||||||
|
if (!CMSConfig.getConfig().isHideLaunchDate()) {
|
||||||
|
article.setLaunchDate((Date) data.get(LAUNCH_DATE));
|
||||||
|
}
|
||||||
|
article.getSummary().addValue(defaultLocale,
|
||||||
|
(String) data.get(SUMMARY));
|
||||||
|
}
|
||||||
|
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure that the name of an item is unique within a folder.
|
||||||
|
*
|
||||||
|
* @param folder the folder in which to check
|
||||||
|
* @param event the FormSectionEvent which was passed to the validation
|
||||||
|
* listener
|
||||||
|
*
|
||||||
|
* @return true if the name is not null and unique, false otherwise
|
||||||
|
*/
|
||||||
|
public boolean validateNameUniqueness(final Folder folder,
|
||||||
|
final FormSectionEvent event) {
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
final String name = (String) data.get(NAME);
|
||||||
|
|
||||||
|
if (name != null) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentItemRepository itemRepo = cdiUtil
|
||||||
|
.findBean(ContentItemRepository.class);
|
||||||
|
|
||||||
|
final long result = itemRepo.countByNameInFolder(folder, name);
|
||||||
|
|
||||||
|
return result == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// false if name == null
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method to create a new MultiPartArticle and update the selected
|
||||||
|
* model. This can be called in the process method of a ProcessListener.
|
||||||
|
*
|
||||||
|
* @param state the current page state
|
||||||
|
* @param name
|
||||||
|
* @param section
|
||||||
|
* @param folder
|
||||||
|
*
|
||||||
|
* @return the new content item (or a proper subclass)
|
||||||
|
* @throws com.arsdigita.bebop.FormProcessException
|
||||||
|
*/
|
||||||
|
public MultiPartArticle createArticle(final PageState state,
|
||||||
|
final String name,
|
||||||
|
final ContentSection section,
|
||||||
|
final Folder folder)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final ContentItemManager itemManager = cdiUtil
|
||||||
|
.findBean(ContentItemManager.class);
|
||||||
|
|
||||||
|
final MultiPartArticle article = itemManager
|
||||||
|
.createContentItem(name,
|
||||||
|
section,
|
||||||
|
folder,
|
||||||
|
MultiPartArticle.class);
|
||||||
|
|
||||||
|
if (itemSelectionModel.getSelectedKey(state) == null) {
|
||||||
|
itemSelectionModel.setSelectedKey(state, article.getObjectId());
|
||||||
|
}
|
||||||
|
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateXML(final PageState state, final Element parent) {
|
||||||
|
|
||||||
|
m_script.generateXML(state, parent);
|
||||||
|
super.generateXML(state, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -372,8 +372,6 @@ public abstract class BasicItemForm extends FormSection
|
||||||
|
|
||||||
if (newName != null) {
|
if (newName != null) {
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
final CategoryRepository categoryRepo = cdiUtil
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final ContentItemRepository itemRepo = cdiUtil
|
final ContentItemRepository itemRepo = cdiUtil
|
||||||
.findBean(ContentItemRepository.class);
|
.findBean(ContentItemRepository.class);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,6 @@ import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentItemManager;
|
import org.librecms.contentsection.ContentItemManager;
|
||||||
import org.librecms.contentsection.ContentType;
|
import org.librecms.contentsection.ContentType;
|
||||||
import org.librecms.contentsection.FolderManager;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
@ -74,8 +71,6 @@ public abstract class BasicPageForm extends BasicItemForm {
|
||||||
|
|
||||||
private static final String LAUNCH_DATE = "launch_date";
|
private static final String LAUNCH_DATE = "launch_date";
|
||||||
|
|
||||||
private FormSection widgetSection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new BasicPageForm
|
* Construct a new BasicPageForm
|
||||||
*
|
*
|
||||||
|
|
@ -194,7 +189,6 @@ public abstract class BasicPageForm extends BasicItemForm {
|
||||||
|
|
||||||
final Optional<Folder> folder = itemManager.getItemFolder(item);
|
final Optional<Folder> folder = itemManager.getItemFolder(item);
|
||||||
if (folder.isPresent()) {
|
if (folder.isPresent()) {
|
||||||
final FormData data = fse.getFormData();
|
|
||||||
final String name = fse.getFormData().getString(NAME);
|
final String name = fse.getFormData().getString(NAME);
|
||||||
if (!item.getName()
|
if (!item.getName()
|
||||||
.getValue(KernelConfig.getConfig().getDefaultLocale())
|
.getValue(KernelConfig.getConfig().getDefaultLocale())
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package com.arsdigita.cms.ui.authoring;
|
||||||
import com.arsdigita.bebop.ColumnPanel;
|
import com.arsdigita.bebop.ColumnPanel;
|
||||||
import com.arsdigita.bebop.Component;
|
import com.arsdigita.bebop.Component;
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
|
import com.arsdigita.bebop.FormSection;
|
||||||
import com.arsdigita.bebop.MetaForm;
|
import com.arsdigita.bebop.MetaForm;
|
||||||
import com.arsdigita.bebop.Page;
|
import com.arsdigita.bebop.Page;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
|
|
@ -108,12 +109,10 @@ public class CreationSelector extends MetaForm {
|
||||||
* creation components from the database and stick them in the Map.
|
* creation components from the database and stick them in the Map.
|
||||||
*
|
*
|
||||||
* @param typeSelectionModel the {@link SingleSelectionModel} which will
|
* @param typeSelectionModel the {@link SingleSelectionModel} which will
|
||||||
* supply a BigDecimal ID of the content type to
|
* supply a BigDecimal ID of the content type to instantiate
|
||||||
* instantiate
|
|
||||||
*
|
*
|
||||||
* @param folderSelectionModel the {@link FolderSelectionModel} containing
|
* @param folderSelectionModel the {@link FolderSelectionModel} containing
|
||||||
* the folder in which new items are to be
|
* the folder in which new items are to be created
|
||||||
* created
|
|
||||||
*/
|
*/
|
||||||
public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel,
|
public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel,
|
||||||
final FolderSelectionModel folderSelectionModel) {
|
final FolderSelectionModel folderSelectionModel) {
|
||||||
|
|
@ -191,7 +190,7 @@ public class CreationSelector extends MetaForm {
|
||||||
*/
|
*/
|
||||||
protected Component instantiateKitComponent(final AuthoringKitInfo kit,
|
protected Component instantiateKitComponent(final AuthoringKitInfo kit,
|
||||||
final ContentType type) {
|
final ContentType type) {
|
||||||
final Class<? extends ItemCreateForm> createClass = kit
|
final Class<? extends FormSection> createClass = kit
|
||||||
.getCreateComponent();
|
.getCreateComponent();
|
||||||
final Object[] vals;
|
final Object[] vals;
|
||||||
|
|
||||||
|
|
@ -200,8 +199,7 @@ public class CreationSelector extends MetaForm {
|
||||||
itemIdParameter);
|
itemIdParameter);
|
||||||
vals = new Object[]{itemModel, this};
|
vals = new Object[]{itemModel, this};
|
||||||
|
|
||||||
final Constructor<? extends ItemCreateForm> constructor
|
final Constructor<? extends FormSection> constructor = createClass
|
||||||
= createClass
|
|
||||||
.getConstructor(arguments);
|
.getConstructor(arguments);
|
||||||
final Component component = (Component) constructor
|
final Component component = (Component) constructor
|
||||||
.newInstance(vals);
|
.newInstance(vals);
|
||||||
|
|
|
||||||
|
|
@ -35,13 +35,9 @@ import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
import com.arsdigita.util.Assert;
|
import com.arsdigita.util.Assert;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.arsdigita.cms.CMSConfig;
|
|
||||||
import org.librecms.CmsConstants;
|
import org.librecms.CmsConstants;
|
||||||
import org.librecms.contentsection.ContentItem;
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -58,7 +54,7 @@ import java.util.Locale;
|
||||||
* @author Stanislav Freidin (stas@arsdigita.com)
|
* @author Stanislav Freidin (stas@arsdigita.com)
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class PageCreate
|
public class PageCreateForm
|
||||||
extends BasicPageForm
|
extends BasicPageForm
|
||||||
implements FormSubmissionListener, CreationComponent {
|
implements FormSubmissionListener, CreationComponent {
|
||||||
|
|
||||||
|
|
@ -81,7 +77,7 @@ public class PageCreate
|
||||||
* CreationSelector#editItem(PageState, ContentItem)} methods on the parent
|
* CreationSelector#editItem(PageState, ContentItem)} methods on the parent
|
||||||
* eventually
|
* eventually
|
||||||
*/
|
*/
|
||||||
public PageCreate(final ItemSelectionModel itemModel,
|
public PageCreateForm(final ItemSelectionModel itemModel,
|
||||||
final CreationSelector creationSelector) {
|
final CreationSelector creationSelector) {
|
||||||
|
|
||||||
super("PageCreate", itemModel);
|
super("PageCreate", itemModel);
|
||||||
|
|
@ -141,6 +137,7 @@ public class PageCreate
|
||||||
/**
|
/**
|
||||||
* Create a new item id.
|
* Create a new item id.
|
||||||
*
|
*
|
||||||
|
* @param event
|
||||||
* @throws com.arsdigita.bebop.FormProcessException
|
* @throws com.arsdigita.bebop.FormProcessException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -152,6 +149,7 @@ public class PageCreate
|
||||||
* If the Cancel button was pressed, hide self and show the display
|
* If the Cancel button was pressed, hide self and show the display
|
||||||
* component.
|
* component.
|
||||||
*
|
*
|
||||||
|
* @param event
|
||||||
* @throws com.arsdigita.bebop.FormProcessException
|
* @throws com.arsdigita.bebop.FormProcessException
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ui.authoring.PageCreateForm;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -44,6 +45,8 @@ import org.librecms.contentsection.ContentItem;
|
||||||
@Table(name = "ARTICLES", schema = DB_SCHEMA)
|
@Table(name = "ARTICLES", schema = DB_SCHEMA)
|
||||||
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Article",
|
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Article",
|
||||||
descriptionBundle = "org.librecms.contenttypes.Article")
|
descriptionBundle = "org.librecms.contenttypes.Article")
|
||||||
|
@AuthoringKit(createComponent = PageCreateForm.class,
|
||||||
|
steps = {})
|
||||||
public class Article extends ContentItem implements Serializable {
|
public class Article extends ContentItem implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3832010184748095822L;
|
private static final long serialVersionUID = 3832010184748095822L;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.ui.item.ItemCreateForm;
|
import com.arsdigita.bebop.FormSection;
|
||||||
|
import com.arsdigita.cms.ui.authoring.PageCreateForm;
|
||||||
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
|
|
@ -33,7 +34,7 @@ import java.lang.annotation.Target;
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface AuthoringKit {
|
public @interface AuthoringKit {
|
||||||
|
|
||||||
Class<? extends ItemCreateForm> createComponent();
|
Class<? extends FormSection> createComponent();
|
||||||
|
|
||||||
AuthoringStep[] steps();
|
AuthoringStep[] steps();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.FormSection;
|
||||||
|
import com.arsdigita.cms.ui.authoring.PageCreateForm;
|
||||||
import com.arsdigita.cms.ui.item.ItemCreateForm;
|
import com.arsdigita.cms.ui.item.ItemCreateForm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
@ -36,7 +38,7 @@ public class AuthoringKitInfo {
|
||||||
* The create component (the form used to collect the mandatory data for the
|
* The create component (the form used to collect the mandatory data for the
|
||||||
* content type).
|
* content type).
|
||||||
*/
|
*/
|
||||||
private Class<? extends ItemCreateForm> createComponent;
|
private Class<? extends FormSection> createComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The authoring steps of the authoring kit.
|
* The authoring steps of the authoring kit.
|
||||||
|
|
@ -47,12 +49,12 @@ public class AuthoringKitInfo {
|
||||||
authoringSteps = new ArrayList<>();
|
authoringSteps = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Class<? extends ItemCreateForm> getCreateComponent() {
|
public Class<? extends FormSection> getCreateComponent() {
|
||||||
return createComponent;
|
return createComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateComponent(
|
public void setCreateComponent(
|
||||||
final Class<? extends ItemCreateForm> createComponent) {
|
final Class<? extends FormSection> createComponent) {
|
||||||
|
|
||||||
this.createComponent = createComponent;
|
this.createComponent = createComponent;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ui.authoring.PageCreateForm;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -50,6 +51,8 @@ import static org.librecms.CmsConstants.*;
|
||||||
@Table(name = "EVENTS", schema = DB_SCHEMA)
|
@Table(name = "EVENTS", schema = DB_SCHEMA)
|
||||||
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Event",
|
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Event",
|
||||||
descriptionBundle = "org.librecms.contenttypes.Event")
|
descriptionBundle = "org.librecms.contenttypes.Event")
|
||||||
|
@AuthoringKit(createComponent = PageCreateForm.class,
|
||||||
|
steps = {})
|
||||||
public class Event extends ContentItem implements Serializable {
|
public class Event extends ContentItem implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -9104886733503414635L;
|
private static final long serialVersionUID = -9104886733503414635L;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.contenttypes.ui.mparticle.MultiPartArticleCreateForm;
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
import org.librecms.contentsection.ContentItem;
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
@ -47,6 +48,8 @@ import static org.librecms.CmsConstants.*;
|
||||||
@Table(name = "MULTIPART_ARTICLES", schema = DB_SCHEMA)
|
@Table(name = "MULTIPART_ARTICLES", schema = DB_SCHEMA)
|
||||||
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.MultiPartArticle",
|
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.MultiPartArticle",
|
||||||
descriptionBundle = "org.librecms.contenttypes.MultiPartArticle")
|
descriptionBundle = "org.librecms.contenttypes.MultiPartArticle")
|
||||||
|
@AuthoringKit(createComponent = MultiPartArticleCreateForm.class,
|
||||||
|
steps = {})
|
||||||
public class MultiPartArticle extends ContentItem implements Serializable {
|
public class MultiPartArticle extends ContentItem implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -587374085831420868L;
|
private static final long serialVersionUID = -587374085831420868L;
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ui.authoring.PageCreateForm;
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
import org.libreccm.l10n.LocalizedString;
|
||||||
|
|
@ -48,6 +49,8 @@ import static org.librecms.CmsConstants.*;
|
||||||
@Table(name = "NEWS", schema = DB_SCHEMA)
|
@Table(name = "NEWS", schema = DB_SCHEMA)
|
||||||
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.News",
|
@ContentTypeDescription(labelBundle = "org.librecms.contenttypes.News",
|
||||||
descriptionBundle = "org.librecms.contenttypes.News")
|
descriptionBundle = "org.librecms.contenttypes.News")
|
||||||
|
@AuthoringKit(createComponent = PageCreateForm.class,
|
||||||
|
steps = {})
|
||||||
public class News extends ContentItem implements Serializable {
|
public class News extends ContentItem implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = -4939565845920227974L;
|
private static final long serialVersionUID = -4939565845920227974L;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue