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
jensp 2017-08-29 15:18:15 +00:00
parent fca9c710cd
commit c4589299eb
2 changed files with 62 additions and 15 deletions

View File

@ -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>
@ -46,44 +48,66 @@ public class InternalLinkAddForm
private final ItemSelectionModel itemSelectionModel;
private final AttachmentListSelectionModel listSelectionModel;
private final StringParameter selectedLanguageParam;
private final TextField titleField;
private final TextArea descriptionArea;
// private final TextArea descriptionArea;
private final ItemSearchWidget itemSearchWidget;
private final SaveCancelSection saveCancelSection;
public InternalLinkAddForm(
final RelatedInfoStep relatedInfoStep,
final ItemSelectionModel itemSelectionModel,
final AttachmentListSelectionModel listSelectionModel,
final StringParameter selectedLanguageParam) {
super("relatedinfo-attach-internallink-form");
this.relatedInfoStep = relatedInfoStep;
this.itemSelectionModel = itemSelectionModel;
this.listSelectionModel = listSelectionModel;
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());
}
}
}

View File

@ -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;
@ -148,7 +150,7 @@ class RelatedInfoStepController {
.stream()
.filter(current -> !current.equals(toMove))
.forEach(current -> current.setSortKey(current.getSortKey() + 1));
attachments.forEach(entityManager::merge);
}
@ -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) {