Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-125413 Use new ImageSelector component in image-selector tag and remove old one #98928

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,26 +14,74 @@

package com.liferay.item.selector.taglib.servlet.taglib;

import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil;
import com.liferay.document.library.util.DLURLHelperUtil;
import com.liferay.item.selector.taglib.internal.servlet.ServletContextUtil;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.taglib.util.IncludeTag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;

/**
* @author Sergio González
* @author Roberto Díaz
* @author Carlos Lancha
*/
public class ImageSelectorTag extends IncludeTag {

@Override
public int doStartTag() throws JspException {
if (_fileEntryId != 0) {
try {
FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(
_fileEntryId);

ThemeDisplay themeDisplay = (ThemeDisplay)request.getAttribute(
WebKeys.THEME_DISPLAY);

_imageURL = DLURLHelperUtil.getPreviewURL(
fileEntry, fileEntry.getFileVersion(), themeDisplay,
StringPool.BLANK);
}
catch (Exception exception) {
_log.error(
"Unable to get HTML preview entry image URL", exception);
}
}

if (Validator.isNotNull(_paramName)) {
_imageCropRegion = ParamUtil.getString(
request, _paramName + "CropRegion");
}

return super.doStartTag();
}

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link #getImageCropDirection()}
*/
@Deprecated
public String getDraggableImage() {
return _draggableImage;
return getImageCropDirection();
}

public long getFileEntryId() {
return _fileEntryId;
}

public String getImageCropDirection() {
return _imageCropDirection;
}

public String getItemSelectorEventName() {
return _itemSelectorEventName;
}
Expand All @@ -58,14 +106,26 @@ public String getValidExtensions() {
return _validExtensions;
}

public boolean isDraggable() {
return !_imageCropDirection.equals("none");
}

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by {@link #setImageCropDirection()}
*/
@Deprecated
public void setDraggableImage(String draggableImage) {
_draggableImage = draggableImage;
setImageCropDirection(draggableImage);
}

public void setFileEntryId(long fileEntryId) {
_fileEntryId = fileEntryId;
}

public void setImageCropDirection(String imageCropDirection) {
_imageCropDirection = imageCropDirection;
}

public void setItemSelectorEventName(String itemSelectorEventName) {
_itemSelectorEventName = itemSelectorEventName;
}
Expand Down Expand Up @@ -101,8 +161,10 @@ public void setValidExtensions(String validExtensions) {
protected void cleanUp() {
super.cleanUp();

_draggableImage = "none";
_fileEntryId = 0;
_imageCropDirection = "none";
_imageCropRegion = null;
_imageURL = null;
_itemSelectorEventName = null;
_itemSelectorURL = null;
_maxFileSize = 0;
Expand All @@ -118,10 +180,17 @@ protected String getPage() {

@Override
protected void setAttributes(HttpServletRequest httpServletRequest) {
httpServletRequest.setAttribute(
"liferay-ui:image-selector:draggableImage", _draggableImage);
httpServletRequest.setAttribute(
"liferay-ui:image-selector:fileEntryId", _fileEntryId);
httpServletRequest.setAttribute(
"liferay-ui:image-selector:imageCropDirection",
_imageCropDirection);
httpServletRequest.setAttribute(
"liferay-ui:image-selector:imageCropRegion", _imageCropRegion);
httpServletRequest.setAttribute(
"liferay-ui:image-selector:imageURL", _imageURL);
httpServletRequest.setAttribute(
"liferay-ui:image-selector:isDraggable", isDraggable());
httpServletRequest.setAttribute(
"liferay-ui:image-selector:itemSelectorEventName",
_itemSelectorEventName);
Expand All @@ -139,8 +208,13 @@ protected void setAttributes(HttpServletRequest httpServletRequest) {

private static final String _PAGE = "/image_selector/page.jsp";

private String _draggableImage = "none";
private static final Log _log = LogFactoryUtil.getLog(
ImageSelectorTag.class);

private long _fileEntryId;
private String _imageCropDirection = "none";
private String _imageCropRegion;
private String _imageURL;
private String _itemSelectorEventName;
private String _itemSelectorURL;
private long _maxFileSize;
Expand Down
Expand Up @@ -34,7 +34,7 @@
<tag-class>com.liferay.item.selector.taglib.servlet.taglib.ImageSelectorTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<description>A CSS class to specify the direction of the image drag. Possible values are <![CDATA[<code>vertical</code>]]>, <![CDATA[<code>horizontal</code>]]>, <![CDATA[<code>both</code>]]>, or <![CDATA[<code>none</code>]]>.</description>
<description>Deprecated as of 7.4.0, replaced by the attribute <![CDATA[<code>imageCropDirection</code>]]>.</description>
<name>draggableImage</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
Expand All @@ -45,6 +45,12 @@
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>The direction of the image drag to crop it. Possible values are <![CDATA[<code>vertical</code>]]>, <![CDATA[<code>horizontal</code>]]>, <![CDATA[<code>both</code>]]>, or <![CDATA[<code>none</code>]]>.</description>
<name>imageCropDirection</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>The name of the event that the item selector dialog throws, in order to allow the image selector tag capture and show the selected image.</description>
<name>itemSelectorEventName</name>
Expand Down
Expand Up @@ -16,5 +16,4 @@

<%@ include file="/init.jsp" %>

<%@ page import="com.liferay.document.library.util.DLURLHelperUtil" %><%@
page import="com.liferay.portal.kernel.servlet.BrowserSnifferUtil" %>
<%@ page import="com.liferay.portal.kernel.servlet.BrowserSnifferUtil" %>
Expand Up @@ -19,6 +19,7 @@ import React from 'react';
const ChangeImageControls = ({handleClickDelete, handleClickPicture}) => (
<div className="change-image-controls">
<ClayButtonWithIcon
className="browse-image"
displayType="secondary"
monospaced
onClick={handleClickPicture}
Expand Down