All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.liferay.journal.web.internal.display.context.JournalDDMTemplateManagementToolbarDisplayContext Maven / Gradle / Ivy
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* 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.
*/
package com.liferay.journal.web.internal.display.context;
import com.liferay.dynamic.data.mapping.configuration.DDMWebConfiguration;
import com.liferay.dynamic.data.mapping.model.DDMStructure;
import com.liferay.dynamic.data.mapping.model.DDMTemplate;
import com.liferay.frontend.taglib.clay.servlet.taglib.display.context.SearchContainerManagementToolbarDisplayContext;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.CreationMenu;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.DropdownItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.DropdownItemListBuilder;
import com.liferay.journal.constants.JournalPortletKeys;
import com.liferay.journal.model.JournalArticle;
import com.liferay.journal.web.internal.security.permission.resource.DDMTemplatePermission;
import com.liferay.petra.portlet.url.builder.PortletURLBuilder;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portlet.LiferayPortletRequest;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.template.TemplateConstants;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.PortalUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.staging.StagingGroupHelper;
import com.liferay.staging.StagingGroupHelperUtil;
import java.util.List;
import javax.portlet.PortletURL;
import javax.servlet.http.HttpServletRequest;
/**
* @author Eudaldo Alonso
*/
public class JournalDDMTemplateManagementToolbarDisplayContext
extends SearchContainerManagementToolbarDisplayContext {
public JournalDDMTemplateManagementToolbarDisplayContext(
HttpServletRequest httpServletRequest,
LiferayPortletRequest liferayPortletRequest,
LiferayPortletResponse liferayPortletResponse,
JournalDDMTemplateDisplayContext journalDDMTemplateDisplayContext)
throws Exception {
super(
httpServletRequest, liferayPortletRequest, liferayPortletResponse,
journalDDMTemplateDisplayContext.getDDMTemplateSearch());
_ddmWebConfiguration =
(DDMWebConfiguration)httpServletRequest.getAttribute(
DDMWebConfiguration.class.getName());
_journalDDMTemplateDisplayContext = journalDDMTemplateDisplayContext;
}
@Override
public List getActionDropdownItems() {
return DropdownItemListBuilder.add(
dropdownItem -> {
dropdownItem.putData("action", "deleteDDMTemplates");
dropdownItem.setIcon("times-circle");
dropdownItem.setLabel(
LanguageUtil.get(httpServletRequest, "delete"));
dropdownItem.setQuickAction(true);
}
).build();
}
public String getAvailableActions(DDMTemplate ddmTemplate)
throws PortalException {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
if (DDMTemplatePermission.contains(
themeDisplay.getPermissionChecker(), ddmTemplate,
ActionKeys.DELETE)) {
return "deleteDDMTemplates";
}
return StringPool.BLANK;
}
@Override
public String getClearResultsURL() {
return PortletURLBuilder.create(
getPortletURL()
).setKeywords(
StringPool.BLANK
).buildString();
}
@Override
public String getComponentId() {
return "ddmTemplateManagementToolbar";
}
@Override
public CreationMenu getCreationMenu() {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
return new CreationMenu() {
{
addPrimaryDropdownItem(
dropdownItem -> {
dropdownItem.setHref(
liferayPortletResponse.createRenderURL(), "mvcPath",
"/edit_ddm_template.jsp", "redirect",
themeDisplay.getURLCurrent(), "classPK",
_journalDDMTemplateDisplayContext.getClassPK());
dropdownItem.setLabel(
LanguageUtil.format(
httpServletRequest, "add-x",
StringBundler.concat(
LanguageUtil.get(
httpServletRequest,
TemplateConstants.LANG_TYPE_FTL +
"[stands-for]"),
StringPool.SPACE,
StringPool.OPEN_PARENTHESIS,
StringPool.PERIOD,
TemplateConstants.LANG_TYPE_FTL,
StringPool.CLOSE_PARENTHESIS),
false));
});
}
};
}
@Override
public String getSearchActionURL() {
PortletURL searchActionURL = getPortletURL();
return searchActionURL.toString();
}
@Override
public String getSearchContainerId() {
return "ddmTemplates";
}
@Override
public Boolean isSelectable() {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
User user = themeDisplay.getUser();
return !user.isDefaultUser();
}
@Override
public Boolean isShowCreationMenu() {
ThemeDisplay themeDisplay =
(ThemeDisplay)httpServletRequest.getAttribute(
WebKeys.THEME_DISPLAY);
Group group = themeDisplay.getScopeGroup();
StagingGroupHelper stagingGroupHelper =
StagingGroupHelperUtil.getStagingGroupHelper();
if ((stagingGroupHelper.isLocalLiveGroup(group) ||
stagingGroupHelper.isRemoteLiveGroup(group)) &&
stagingGroupHelper.isStagedPortlet(
group, JournalPortletKeys.JOURNAL)) {
return false;
}
try {
if (_ddmWebConfiguration.enableTemplateCreation() &&
DDMTemplatePermission.containsAddTemplatePermission(
themeDisplay.getPermissionChecker(),
themeDisplay.getScopeGroupId(),
PortalUtil.getClassNameId(DDMStructure.class),
PortalUtil.getClassNameId(JournalArticle.class))) {
return true;
}
}
catch (Exception exception) {
if (_log.isDebugEnabled()) {
_log.debug(exception, exception);
}
}
return false;
}
@Override
protected String getDefaultDisplayStyle() {
return "icon";
}
@Override
protected String getDisplayStyle() {
return _journalDDMTemplateDisplayContext.getDisplayStyle();
}
@Override
protected String[] getDisplayViews() {
return new String[] {"list", "icon"};
}
@Override
protected String[] getNavigationKeys() {
return new String[] {"all"};
}
@Override
protected String[] getOrderByKeys() {
return new String[] {"modified-date", "id"};
}
private static final Log _log = LogFactoryUtil.getLog(
JournalDDMTemplateManagementToolbarDisplayContext.class);
private final DDMWebConfiguration _ddmWebConfiguration;
private final JournalDDMTemplateDisplayContext
_journalDDMTemplateDisplayContext;
}