CCM NG/ccm-cms: Form for adding internal link
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4960 8810af33-2d31-482b-a856-94f89814c4df
parent
fca9c710cd
commit
c4589299eb
|
|
@ -20,18 +20,20 @@ package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
import com.arsdigita.bebop.Form;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
import com.arsdigita.bebop.SaveCancelSection;
|
||||||
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.TextArea;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
import com.arsdigita.bebop.form.TextField;
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
import com.arsdigita.cms.ItemSelectionModel;
|
import com.arsdigita.cms.ItemSelectionModel;
|
||||||
import com.arsdigita.cms.ui.assets.ItemSearchWidget;
|
import com.arsdigita.cms.ui.assets.ItemSearchWidget;
|
||||||
import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
|
import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -46,44 +48,66 @@ public class InternalLinkAddForm
|
||||||
private final ItemSelectionModel itemSelectionModel;
|
private final ItemSelectionModel itemSelectionModel;
|
||||||
private final AttachmentListSelectionModel listSelectionModel;
|
private final AttachmentListSelectionModel listSelectionModel;
|
||||||
private final StringParameter selectedLanguageParam;
|
private final StringParameter selectedLanguageParam;
|
||||||
|
|
||||||
private final TextField titleField;
|
private final TextField titleField;
|
||||||
private final TextArea descriptionArea;
|
// private final TextArea descriptionArea;
|
||||||
private final ItemSearchWidget itemSearchWidget;
|
private final ItemSearchWidget itemSearchWidget;
|
||||||
private final SaveCancelSection saveCancelSection;
|
private final SaveCancelSection saveCancelSection;
|
||||||
|
|
||||||
public InternalLinkAddForm(
|
public InternalLinkAddForm(
|
||||||
final RelatedInfoStep relatedInfoStep,
|
final RelatedInfoStep relatedInfoStep,
|
||||||
final ItemSelectionModel itemSelectionModel,
|
final ItemSelectionModel itemSelectionModel,
|
||||||
final AttachmentListSelectionModel listSelectionModel,
|
final AttachmentListSelectionModel listSelectionModel,
|
||||||
final StringParameter selectedLanguageParam) {
|
final StringParameter selectedLanguageParam) {
|
||||||
|
|
||||||
super("relatedinfo-attach-internallink-form");
|
super("relatedinfo-attach-internallink-form");
|
||||||
|
|
||||||
this.relatedInfoStep = relatedInfoStep;
|
this.relatedInfoStep = relatedInfoStep;
|
||||||
this.itemSelectionModel = itemSelectionModel;
|
this.itemSelectionModel = itemSelectionModel;
|
||||||
this.listSelectionModel = listSelectionModel;
|
this.listSelectionModel = listSelectionModel;
|
||||||
this.selectedLanguageParam = selectedLanguageParam;
|
this.selectedLanguageParam = selectedLanguageParam;
|
||||||
|
|
||||||
titleField = new TextField("link-title");
|
titleField = new TextField("link-title");
|
||||||
descriptionArea = new TextArea("link-description");
|
// descriptionArea = new TextArea("link-description");
|
||||||
itemSearchWidget = new ItemSearchWidget("link-item-search");
|
itemSearchWidget = new ItemSearchWidget("link-item-search");
|
||||||
saveCancelSection = new SaveCancelSection();
|
saveCancelSection = new SaveCancelSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(FormSectionEvent e) throws FormProcessException {
|
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process(FormSectionEvent e) throws FormProcessException {
|
public void process(final FormSectionEvent event) throws
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final RelatedInfoStepController controller = cdiUtil
|
||||||
|
.findBean(RelatedInfoStepController.class);
|
||||||
|
|
||||||
|
controller.createInternalLink(
|
||||||
|
listSelectionModel.getSelectedAttachmentList(state),
|
||||||
|
(Long) itemSearchWidget.getValue(state),
|
||||||
|
(String) titleField.getValue(state),
|
||||||
|
(String) state.getValue(selectedLanguageParam));
|
||||||
|
|
||||||
|
relatedInfoStep.showAttachmentsTable(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void submitted(FormSectionEvent e) throws FormProcessException {
|
public void submitted(final FormSectionEvent event) throws
|
||||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
FormProcessException {
|
||||||
|
|
||||||
|
if (saveCancelSection.getCancelButton().isSelected(event.getPageState())) {
|
||||||
|
relatedInfoStep.showAttachmentsTable(event.getPageState());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
|
||||||
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
import com.arsdigita.kernel.KernelConfig;
|
||||||
|
|
||||||
|
import org.apache.commons.fileupload.MultipartStream;
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
import org.libreccm.configuration.ConfigurationManager;
|
||||||
|
import org.librecms.assets.RelatedLink;
|
||||||
import org.librecms.contentsection.AttachmentList;
|
import org.librecms.contentsection.AttachmentList;
|
||||||
import org.librecms.contentsection.AttachmentListManager;
|
import org.librecms.contentsection.AttachmentListManager;
|
||||||
import org.librecms.contentsection.ContentItem;
|
import org.librecms.contentsection.ContentItem;
|
||||||
|
|
@ -148,7 +150,7 @@ class RelatedInfoStepController {
|
||||||
.stream()
|
.stream()
|
||||||
.filter(current -> !current.equals(toMove))
|
.filter(current -> !current.equals(toMove))
|
||||||
.forEach(current -> current.setSortKey(current.getSortKey() + 1));
|
.forEach(current -> current.setSortKey(current.getSortKey() + 1));
|
||||||
|
|
||||||
attachments.forEach(entityManager::merge);
|
attachments.forEach(entityManager::merge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -278,6 +280,27 @@ class RelatedInfoStepController {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected void createInternalLink(final AttachmentList attachmentList,
|
||||||
|
final long targetItemId,
|
||||||
|
final String title,
|
||||||
|
// final String description,
|
||||||
|
final String selectedLanguage) {
|
||||||
|
|
||||||
|
final ContentItem targetItem = itemRepo
|
||||||
|
.findById(targetItemId)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No ContentItem with ID %d in the database.", targetItemId)));
|
||||||
|
|
||||||
|
final RelatedLink link = new RelatedLink();
|
||||||
|
link.setTargetItem(targetItem);
|
||||||
|
final Locale selectedLocale = new Locale(selectedLanguage);
|
||||||
|
link.getTitle().addValue(selectedLocale, title);
|
||||||
|
|
||||||
|
|
||||||
|
itemAttachmentManager.attachAsset(link, attachmentList);
|
||||||
|
}
|
||||||
|
|
||||||
private AttachmentListTableRow buildAttachmentListTableRow(
|
private AttachmentListTableRow buildAttachmentListTableRow(
|
||||||
final AttachmentList attachmentList,
|
final AttachmentList attachmentList,
|
||||||
final Locale selectedLocale) {
|
final Locale selectedLocale) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue