CCM NG/ccm-cms: EditStep for editing the text of a news
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4847 8810af33-2d31-482b-a856-94f89814c4df
Former-commit-id: a571525e62
pull/2/head
parent
6b4eda03af
commit
b67ca2c7a4
|
|
@ -20,10 +20,8 @@ package com.arsdigita.cms.ui.authoring;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
import com.arsdigita.bebop.Component;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.RequestLocal;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
import com.arsdigita.bebop.form.SingleSelect;
|
||||||
import com.arsdigita.bebop.parameters.LongParameter;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
|
||||||
|
|
@ -33,7 +31,6 @@ import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.l10n.LocalizedString;
|
|
||||||
import org.librecms.contentsection.ContentItemRepository;
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,116 @@
|
||||||
|
package com.arsdigita.cms.ui.authoring;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.form.Option;
|
||||||
|
import com.arsdigita.bebop.form.SingleSelect;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
|
import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess;
|
||||||
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.librecms.contentsection.ContentItemRepository;
|
||||||
|
import org.librecms.contenttypes.News;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import static com.arsdigita.cms.ui.authoring.TextBody.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class NewsTextBody extends TextBody {
|
||||||
|
|
||||||
|
private final ItemSelectionModel itemSelectionModel;
|
||||||
|
private final StringParameter selectedLanguageParam;
|
||||||
|
|
||||||
|
public NewsTextBody(final ItemSelectionModel itemSelectionModel,
|
||||||
|
final AuthoringKitWizard authoringKitWizard,
|
||||||
|
final StringParameter selectedLanguageParam) {
|
||||||
|
|
||||||
|
super(itemSelectionModel, selectedLanguageParam);
|
||||||
|
|
||||||
|
this.itemSelectionModel = itemSelectionModel;
|
||||||
|
this.selectedLanguageParam = selectedLanguageParam;
|
||||||
|
|
||||||
|
// Rest the component when it is hidden
|
||||||
|
authoringKitWizard
|
||||||
|
.getList()
|
||||||
|
.addActionListener(event -> reset(event.getPageState()));
|
||||||
|
|
||||||
|
// Set the right component access on the forms
|
||||||
|
final Component uploadComponent = getComponent(FILE_UPLOAD);
|
||||||
|
if (uploadComponent != null) {
|
||||||
|
setComponentAccess(FILE_UPLOAD,
|
||||||
|
new WorkflowLockedComponentAccess(
|
||||||
|
uploadComponent, itemSelectionModel));
|
||||||
|
}
|
||||||
|
final Component textEntryComponent = getComponent(TEXT_ENTRY);
|
||||||
|
setComponentAccess(TEXT_ENTRY,
|
||||||
|
new WorkflowLockedComponentAccess(
|
||||||
|
textEntryComponent, itemSelectionModel));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the options for the mime type select widget of
|
||||||
|
* <code>GenericArticleForm</code> and sets the default mime type.
|
||||||
|
*
|
||||||
|
* @param mimeSelect
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void setMimeTypeOptions(final SingleSelect mimeSelect) {
|
||||||
|
mimeSelect.addOption(new Option("text/html", "HTML Text"));
|
||||||
|
mimeSelect.setOptionSelected("text/html");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected News getSelectedNews(final PageState state) {
|
||||||
|
|
||||||
|
return (News) itemSelectionModel.getSelectedItem(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getTextPropertyName() {
|
||||||
|
return "text";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getText(final PageState state) {
|
||||||
|
|
||||||
|
final News news = getSelectedNews(state);
|
||||||
|
|
||||||
|
final String selectedLanguage = (String) state
|
||||||
|
.getValue(selectedLanguageParam);
|
||||||
|
final Locale selectedLocale;
|
||||||
|
if (selectedLanguage == null) {
|
||||||
|
selectedLocale = KernelConfig.getConfig().getDefaultLocale();
|
||||||
|
} else {
|
||||||
|
selectedLocale = new Locale(selectedLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return news.getText().getValue(selectedLocale);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateText(final PageState state, final String text) {
|
||||||
|
|
||||||
|
final News news = getSelectedNews(state);
|
||||||
|
final String selectedLanguage = (String) state.getValue(
|
||||||
|
selectedLanguageParam);
|
||||||
|
final Locale selectedLocale;
|
||||||
|
if (selectedLanguage == null) {
|
||||||
|
selectedLocale = KernelConfig.getConfig().getDefaultLocale();
|
||||||
|
} else {
|
||||||
|
selectedLocale = new Locale(selectedLanguage);
|
||||||
|
}
|
||||||
|
|
||||||
|
news.getText().addValue(selectedLocale, text);
|
||||||
|
final ContentItemRepository itemRepo = CdiUtil
|
||||||
|
.createCdiUtil()
|
||||||
|
.findBean(ContentItemRepository.class);
|
||||||
|
itemRepo.save(news);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
package org.librecms.contenttypes;
|
package org.librecms.contenttypes;
|
||||||
|
|
||||||
import com.arsdigita.cms.contenttypes.ui.NewsPropertiesStep;
|
import com.arsdigita.cms.contenttypes.ui.NewsPropertiesStep;
|
||||||
|
import com.arsdigita.cms.ui.authoring.NewsTextBody;
|
||||||
import com.arsdigita.cms.ui.contenttypes.NewsCreateForm;
|
import com.arsdigita.cms.ui.contenttypes.NewsCreateForm;
|
||||||
|
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
|
|
@ -62,6 +63,15 @@ import static org.librecms.CmsConstants.*;
|
||||||
descriptionKey = "cms.contenttypes.shared.basic_properties"
|
descriptionKey = "cms.contenttypes.shared.basic_properties"
|
||||||
+ ".description",
|
+ ".description",
|
||||||
order = 1)
|
order = 1)
|
||||||
|
,
|
||||||
|
@AuthoringStep(
|
||||||
|
component = NewsTextBody.class,
|
||||||
|
labelBundle = "org.librecms.CmsResources",
|
||||||
|
labelKey = "cms.contenttypes.shared.body_text.title",
|
||||||
|
descriptionBundle = "org.librecms.CmsResources",
|
||||||
|
descriptionKey = "cms.contenttypes.shared.body_text.description",
|
||||||
|
order = 2
|
||||||
|
)
|
||||||
})
|
})
|
||||||
public class News extends ContentItem implements Serializable {
|
public class News extends ContentItem implements Serializable {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue