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
Former-commit-id: c4589299eb
pull/2/head
parent
c9ee53b028
commit
51efd79596
|
|
@ -20,18 +20,20 @@ package com.arsdigita.cms.ui.authoring.assets.relatedinfo;
|
|||
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
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.FormSubmissionListener;
|
||||
import com.arsdigita.bebop.form.TextArea;
|
||||
import com.arsdigita.bebop.form.TextField;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.assets.ItemSearchWidget;
|
||||
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>
|
||||
|
|
@ -48,7 +50,7 @@ public class InternalLinkAddForm
|
|||
private final StringParameter selectedLanguageParam;
|
||||
|
||||
private final TextField titleField;
|
||||
private final TextArea descriptionArea;
|
||||
// private final TextArea descriptionArea;
|
||||
private final ItemSearchWidget itemSearchWidget;
|
||||
private final SaveCancelSection saveCancelSection;
|
||||
|
||||
|
|
@ -66,24 +68,46 @@ public class InternalLinkAddForm
|
|||
this.selectedLanguageParam = selectedLanguageParam;
|
||||
|
||||
titleField = new TextField("link-title");
|
||||
descriptionArea = new TextArea("link-description");
|
||||
// descriptionArea = new TextArea("link-description");
|
||||
itemSearchWidget = new ItemSearchWidget("link-item-search");
|
||||
saveCancelSection = new SaveCancelSection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FormSectionEvent e) throws FormProcessException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(FormSectionEvent e) throws FormProcessException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
public void process(final FormSectionEvent event) throws
|
||||
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
|
||||
public void submitted(FormSectionEvent e) throws FormProcessException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
public void submitted(final FormSectionEvent event) throws
|
||||
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 org.apache.commons.fileupload.MultipartStream;
|
||||
import org.libreccm.configuration.ConfigurationManager;
|
||||
import org.librecms.assets.RelatedLink;
|
||||
import org.librecms.contentsection.AttachmentList;
|
||||
import org.librecms.contentsection.AttachmentListManager;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
|
@ -278,6 +280,27 @@ class RelatedInfoStepController {
|
|||
.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(
|
||||
final AttachmentList attachmentList,
|
||||
final Locale selectedLocale) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue