Removal of attachments working
parent
069592cdbc
commit
d14e2433da
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (C) 2021 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package com.arsdigita.cms.ui.assets.forms;
|
||||
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.cms.ui.assets.AbstractAssetForm;
|
||||
import com.arsdigita.cms.ui.assets.AssetPane;
|
||||
|
||||
import org.librecms.assets.RelatedLink;
|
||||
import org.librecms.assets.SideNote;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class RelatedLinkForm extends AbstractAssetForm<RelatedLink>{
|
||||
|
||||
public RelatedLinkForm(final AssetPane assetPane) {
|
||||
super(assetPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<RelatedLink> getAssetClass() {
|
||||
return RelatedLink.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showLocale(final PageState state) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, Object> collectData(final FormSectionEvent event) throws
|
||||
FormProcessException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
package org.librecms.assets;
|
||||
|
||||
import com.arsdigita.cms.ui.assets.forms.RelatedLinkForm;
|
||||
import com.arsdigita.cms.ui.assets.forms.SideNoteForm;
|
||||
|
||||
import org.librecms.contentsection.Asset;
|
||||
import org.hibernate.envers.Audited;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
|
@ -31,6 +34,7 @@ import javax.persistence.OneToOne;
|
|||
import javax.persistence.Table;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE;
|
||||
|
||||
/**
|
||||
* An link to information related to a content item, either to an (external) URL
|
||||
|
|
@ -42,6 +46,13 @@ import static org.librecms.CmsConstants.*;
|
|||
@Entity
|
||||
@Table(name = "RELATED_LINKS", schema = DB_SCHEMA)
|
||||
@Audited
|
||||
@AssetType(
|
||||
assetForm = RelatedLinkForm.class,
|
||||
labelBundle = ASSETS_BUNDLE,
|
||||
labelKey = "relatedlink.label",
|
||||
descriptionBundle = ASSETS_BUNDLE,
|
||||
descriptionKey = "relatededlink.description"
|
||||
)
|
||||
public class RelatedLink extends Asset implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 6933875117588667160L;
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class ItemAttachmentManager {
|
|||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
public void save(final ItemAttachment<?> attachment) {
|
||||
if (attachment.getAttachmentId() == 0) {
|
||||
|
|
@ -73,7 +73,7 @@ public class ItemAttachmentManager {
|
|||
} else {
|
||||
entityManager.merge(attachment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the provided {@link Asset} to the provided {@link AttachmentList}.
|
||||
|
|
@ -173,9 +173,14 @@ public class ItemAttachmentManager {
|
|||
|
||||
@SuppressWarnings("rawtypes")
|
||||
final List<ItemAttachment> attachments = query.getResultList();
|
||||
attachments.forEach(
|
||||
(attachment) -> asset.removeItemAttachment(attachment)
|
||||
);
|
||||
attachments.forEach((attachment) -> entityManager.remove(attachment));
|
||||
|
||||
if (!assetManager.isShared(asset)) {
|
||||
if (assetManager.isShared(asset)) {
|
||||
assetRepo.save(asset);
|
||||
} else {
|
||||
entityManager.remove(asset);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1759,7 +1759,7 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
|
|||
* @param listIdentifierParam The identifier of the {@link AttachmentList}
|
||||
* to which the attachment belongs.
|
||||
* @param attachmentUuid The UUID of the attachment to remove.
|
||||
* @param confirm The value of the {@code confirm} parameter. If
|
||||
* @param confirmed The value of the {@code confirm} parameter. If
|
||||
* the value anything other than the string
|
||||
* {@code true} the method does nothing.
|
||||
*
|
||||
|
|
@ -1778,8 +1778,8 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
|
|||
final String listIdentifierParam,
|
||||
@PathParam("attachmentUuid")
|
||||
final String attachmentUuid,
|
||||
@FormParam("confirm")
|
||||
final String confirm
|
||||
@FormParam("confirmed")
|
||||
final String confirmed
|
||||
) {
|
||||
try {
|
||||
init();
|
||||
|
|
@ -1807,18 +1807,15 @@ public class RelatedInfoStep extends AbstractMvcAuthoringStep {
|
|||
.equals(attachmentUuid))
|
||||
.findFirst();
|
||||
|
||||
if (result.isPresent() && "true".equalsIgnoreCase(confirm)) {
|
||||
if (result.isPresent() && "true".equalsIgnoreCase(confirmed)) {
|
||||
final Asset asset = result.get().getAsset();
|
||||
attachmentManager.unattachAsset(asset, list);
|
||||
if (asset instanceof RelatedLink
|
||||
&& ((RelatedLink) asset).getTargetItem() != null) {
|
||||
assetRepo.delete(asset);
|
||||
}
|
||||
// if (asset instanceof RelatedLink) {
|
||||
// assetRepo.delete(asset);
|
||||
// }
|
||||
}
|
||||
|
||||
return buildRedirectPathForStep(
|
||||
String.format("/attachmentlists/%s/@details", list.getName())
|
||||
);
|
||||
return buildRedirectPathForStep();
|
||||
} else {
|
||||
return documentUi.showAccessDenied(
|
||||
getContentSection(),
|
||||
|
|
|
|||
|
|
@ -179,11 +179,6 @@
|
|||
dialogTitle="#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.remove.title']}"
|
||||
message="#{CmsDefaultStepsMessageBundle.getMessage('relatedinfo.attachmentlists.remove.message', [list.name])}"
|
||||
/>
|
||||
<!-- <button class="btn btn-danger"
|
||||
type="button">
|
||||
<bootstrap:svgIcon icon="x-circle" />
|
||||
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachmentlists.attachment.remove.label']}</span>
|
||||
</button>-->
|
||||
<librecms:assetPicker
|
||||
actionUrl="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@relatedinfo/attachmentlists/#{list.name}/attachments/@create"
|
||||
assetType="#{CmsRelatedInfoStep.fileAssetType}"
|
||||
|
|
@ -214,7 +209,7 @@
|
|||
</c:choose>
|
||||
<span class="cms-attachment-label">#{attachment.title}</span>
|
||||
</div>
|
||||
<div class="cms-attachment-buttons">
|
||||
<div class="cms-attachment-buttons d-flex">
|
||||
<button class="btn btn-secondary cms-sort-handle mr-2"
|
||||
type="button">
|
||||
<bootstrap:svgIcon icon="arrows-move" />
|
||||
|
|
@ -233,11 +228,17 @@
|
|||
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachments.edit.button']}"</span>
|
||||
</a>
|
||||
</c:if>
|
||||
<button class="btn btn-danger ml-2"
|
||||
type="button">
|
||||
<bootstrap:svgIcon icon="x-circle" />
|
||||
<span class="sr-only">#{CmsDefaultStepsMessageBundle['relatedinfo.attachments.delete.button']}"</span>
|
||||
</button>
|
||||
<libreccm:deleteDialog
|
||||
actionTarget="#{mvc.basePath}/#{ContentSectionModel.sectionName}/documents/#{CmsSelectedDocumentModel.itemPath}/@relatedinfo/attachmentlists/#{list.name}/attachments/#{attachment.uuid}/@remove"
|
||||
buttonLabelClass="sr-only"
|
||||
buttonText="#{CmsDefaultStepsMessageBundle['relatedinfo.attachment.remove.label']}"
|
||||
buttonTextClass="ml-2"
|
||||
cancelLabel="#{CmsDefaultStepsMessageBundle['relatedinfo.attachment.remove.cancel']}"
|
||||
confirmLabel="#{CmsDefaultStepsMessageBundle['relatedinfo.attachment.remove.confirm']}"
|
||||
dialogId="attachment-delete-#{attachment.uuid}"
|
||||
dialogTitle="#{CmsDefaultStepsMessageBundle['relatedinfo.attachment.remove.title']}"
|
||||
message="#{CmsDefaultStepsMessageBundle.getMessage('relatedinfo.attachment.remove.message', [list.name, attachment.title])}"
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
</c:forEach>
|
||||
|
|
@ -245,7 +246,7 @@
|
|||
</li>
|
||||
</c:forEach>
|
||||
</ul>
|
||||
|
||||
|
||||
<div>
|
||||
<button class="btn btn-secondary save-order-button"
|
||||
disabled="disabled"
|
||||
|
|
|
|||
|
|
@ -23,3 +23,5 @@ person.label=Person
|
|||
person.desc=Data about a person
|
||||
postaladdress.label=Postal Address
|
||||
postaladdress.desc=A postal address
|
||||
relatedlink.label=Related Link
|
||||
relatededlink.description=A link to a resource with related information, either internal (to another content item) or external (to another web site)
|
||||
|
|
|
|||
|
|
@ -23,3 +23,5 @@ person.label=Person
|
|||
person.desc=Daten zu einer Person
|
||||
postaladdress.label=Post-Adresse
|
||||
postaladdress.desc=Postalische Addresse
|
||||
relatedlink.label=Weiterf\u00fchrender Link
|
||||
relatededlink.description=Ein Link zu einer Ressource mit weiterf\u00fchrenden Informationen, entweder intern (zu einem Dokument) oder extern (zu einer anderen Webseite).
|
||||
|
|
|
|||
|
|
@ -229,3 +229,8 @@ relatedinfo.attachmentlists.remove.confirm=Remove
|
|||
relatedinfo.attachmentlists.remove.title=Confirm attachment list removal
|
||||
relatedinfo.attachmentlists.remove.message=Are you sure to remove the attachmentlist {0} and all attachments in the list?
|
||||
contentsection.documents.relatedinfo.link.back=Back
|
||||
relatedinfo.attachment.remove.label=Remove
|
||||
relatedinfo.attachment.remove.cancel=Cancel
|
||||
relatedinfo.attachment.remove.confirm=Remove
|
||||
relatedinfo.attachment.remove.title=Confirm removal of attachment
|
||||
relatedinfo.attachment.remove.message=Are your sure to remove the attachment {1} from attachment list {0}?
|
||||
|
|
|
|||
|
|
@ -229,3 +229,8 @@ relatedinfo.attachmentlists.remove.confirm=Entfernen
|
|||
relatedinfo.attachmentlists.remove.title=Entfernen der Anhangliste best\u00e4tigen
|
||||
relatedinfo.attachmentlists.remove.message=Sind Sie sicher, dass die die Anhangliste {0} und alle Anh\u00e4nge in dieser Liste entfernen wollen?
|
||||
contentsection.documents.relatedinfo.link.back=Zur\u00fcck
|
||||
relatedinfo.attachment.remove.label=Entfernen
|
||||
relatedinfo.attachment.remove.cancel=Abbrechen
|
||||
relatedinfo.attachment.remove.confirm=Entfernen
|
||||
relatedinfo.attachment.remove.title=Confirm removal of attachment
|
||||
relatedinfo.attachment.remove.message=Sind Sie sicher, dass Sie die weiterf\u00fchrende Information {1} aus der Anhangliste {0} entfernen wollen?
|
||||
|
|
|
|||
Loading…
Reference in New Issue