diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java index 27abc6f24..18ef18ed5 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java @@ -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 Jens Pelzetter @@ -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()); + } + } } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java index 4e1dae08c..4a4215c9f 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java @@ -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) {