Skip to content

Commit

Permalink
LPD-36211 Only show confirmation when trash is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
boton authored and brianchandotcom committed Sep 16, 2024
1 parent 34dcd47 commit 2af8dab
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,37 @@
import com.liferay.portal.kernel.portlet.LiferayWindowState;
import com.liferay.portal.kernel.portlet.PortletURLUtil;
import com.liferay.portal.kernel.portlet.url.builder.PortletURLBuilder;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.trash.TrashHelper;

import java.util.Map;

import javax.portlet.ResourceURL;

import javax.servlet.http.HttpServletRequest;

/**
* @author Ambrín Chaudhary
*/
public class MBEditMessageDisplayContext {

public MBEditMessageDisplayContext(
HttpServletRequest httpServletRequest,
LiferayPortletRequest liferayPortletRequest,
LiferayPortletResponse liferayPortletResponse, MBMessage message) {
LiferayPortletResponse liferayPortletResponse, MBMessage message,
TrashHelper trashHelper) {

_liferayPortletRequest = liferayPortletRequest;
_liferayPortletResponse = liferayPortletResponse;
_message = message;
_trashHelper = trashHelper;

_themeDisplay = (ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
}

public Map<String, Object> getMBPortletComponentContext() throws Exception {
Expand All @@ -55,6 +66,9 @@ public Map<String, Object> getMBPortletComponentContext() throws Exception {
).put(
"rootNodeId",
_liferayPortletResponse.getNamespace() + "mbEditPageContainer"
).put(
"trashEnabled",
() -> _trashHelper.isTrashEnabled(_themeDisplay.getScopeGroupId())
).build();

if (_message != null) {
Expand Down Expand Up @@ -90,5 +104,7 @@ public Map<String, Object> getMBPortletComponentContext() throws Exception {
private final LiferayPortletRequest _liferayPortletRequest;
private final LiferayPortletResponse _liferayPortletResponse;
private MBMessage _message;
private final ThemeDisplay _themeDisplay;
private final TrashHelper _trashHelper;

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MBPortlet {
confirmDiscardImages: CONFIRM_DISCARD_IMAGES,
},
viewTrashAttachmentsURL,
trashEnabled,
}) {
this._namespace = namespace;
this._constants = constants;
Expand All @@ -39,6 +40,7 @@ class MBPortlet {
this._replyToMessageId = replyToMessageId;
this._strings = strings;
this._viewTrashAttachmentsURL = viewTrashAttachmentsURL;
this._trashEnabled = trashEnabled;

this.rootNode = document.getElementById(rootNodeId);

Expand Down Expand Up @@ -104,7 +106,7 @@ class MBPortlet {
.get('contentBox')
.delegate(
'click',
this._removeAttachment.bind(this),
this._confirmRemoveAttachment.bind(this),
'.delete-attachment'
);
});
Expand Down Expand Up @@ -154,39 +156,53 @@ class MBPortlet {
}

/**
* Sends a request to remove the selected attachment.
* Show a confimation modal if trash is enabled
*
* @param {Event} event The click event that triggered the remove action
*/
_removeAttachment(event) {
_confirmRemoveAttachment(event) {
event.preventDefault();

openConfirmModal({
message: Liferay.Language.get(
'are-you-sure-you-want-to-delete-this'
),
onConfirm: (isConfirmed) => {
if (!isConfirmed) {
return;
}
if (this._trashEnabled) {
this._removeAttachment(event);
}
else {
openConfirmModal({
message: Liferay.Language.get(
'are-you-sure-you-want-to-delete-this'
),
onConfirm: (isConfirmed) => {
if (!isConfirmed) {
return;
}

const link = event.currentTarget;
const deleteURL = link.getAttribute('href');
this._removeAttachment(event);
},
});
}
}

fetch(deleteURL).then(() => {
Liferay.componentReady(this.searchContainerId).then(
(searchContainer) => {
searchContainer.deleteRow(
link.ancestor('tr'),
link.getAttribute('data-rowid')
);
searchContainer.updateDataStore();
}
/**
* Sends a request to remove the selected attachment.
*
* @param {Event} event The click event that triggered the remove action
*/
_removeAttachment(event) {
const link = event.currentTarget;
const deleteURL = link.getAttribute('href');

fetch(deleteURL).then(() => {
Liferay.componentReady(this.searchContainerId).then(
(searchContainer) => {
searchContainer.deleteRow(
link.ancestor('tr'),
link.getAttribute('data-rowid')
);
searchContainer.updateDataStore();
}
);

this._updateRemovedAttachments();
});
},
this._updateRemovedAttachments();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ if (portletTitleBasedNavigation) {
</clay:container-fluid>

<%
MBEditMessageDisplayContext mbEditMessageDisplayContext = new MBEditMessageDisplayContext(liferayPortletRequest, liferayPortletResponse, message);
MBEditMessageDisplayContext mbEditMessageDisplayContext = new MBEditMessageDisplayContext(request, liferayPortletRequest, liferayPortletResponse, message, trashHelper);
%>

<liferay-frontend:component
Expand Down

0 comments on commit 2af8dab

Please sign in to comment.