Skip to content

Commit

Permalink
LPS-52978 Add configuration for comments and partially extract alloyE…
Browse files Browse the repository at this point in the history
…ditor base config to a OSGI module
  • Loading branch information
Sergio Gonzalez authored and brianchandotcom committed Mar 27, 2015
1 parent 7eb456f commit c1648ba
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 35 deletions.
4 changes: 4 additions & 0 deletions modules/apps/mentions/mentions-portlet/bnd.bnd
@@ -0,0 +1,4 @@
Bundle-Name: Liferay Comments Editor Conf
Bundle-SymbolicName: com.liferay.comments.portlet.editor.conf
Bundle-Version: 1.0.0
Include-Resource: classes
Empty file.
8 changes: 8 additions & 0 deletions modules/apps/mentions/mentions-portlet/build.xml
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<!DOCTYPE project>

<project>
<import file="../../../../tools/sdk/build-common-osgi-plugin.xml" />

<property name="auto.deploy.dir" value="${liferay.home}/osgi/portal" />
</project>
22 changes: 22 additions & 0 deletions modules/apps/mentions/mentions-portlet/ivy.xml
@@ -0,0 +1,22 @@
<?xml version="1.0"?>

<ivy-module
version="2.0"
xmlns:m2="http://ant.apache.org/ivy/maven"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
>
<info module="${plugin.name}" organisation="com.liferay">
<extends extendType="configurations,description,info" location="${sdk.dir}/ivy.xml" module="com.liferay.sdk" organisation="com.liferay" revision="latest.integration" />
</info>

<publications>
<artifact type="jar" />
<artifact type="pom" />
<artifact m2:classifier="sources" />
</publications>

<dependencies defaultconf="default">
<dependency name="org.osgi.core" org="org.osgi" rev="6.0.0" />
</dependencies>
</ivy-module>
@@ -0,0 +1,111 @@
/**
* 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.comments.portlet.editor.conf;

import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.portlet.LiferayPortletURL;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.HtmlUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortletKeys;
import com.liferay.portlet.editor.config.PortletEditorConfigContributor;
import org.osgi.service.component.annotations.Component;

import java.util.Locale;
import java.util.Map;

/**
* @author Sergio González
*/
@Component(property = {"editor.impl=alloyeditor"})
public class AlloyEditorConfigContributor
implements PortletEditorConfigContributor {

public void populateConfigJSONObject(
JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes,
ThemeDisplay themeDisplay,
LiferayPortletResponse liferayPortletResponse) {

String contentsLanguageId = (String)inputEditorTaglibAttributes.get(
"liferay-ui:input-editor:contentsLanguageId");

Locale contentsLocale = LocaleUtil.fromLanguageId(contentsLanguageId);

String contentsLanguageDir = LanguageUtil.get(
contentsLocale, "lang.dir");

contentsLanguageId = LocaleUtil.toLanguageId(contentsLocale);

jsonObject.put(
"contentsLangDirection", HtmlUtil.escapeJS(contentsLanguageDir));
jsonObject.put(
"contentsLanguage", contentsLanguageId.replace("iw_", "he_"));

LiferayPortletURL documentSelectorURL =
liferayPortletResponse.createRenderURL(
PortletKeys.DOCUMENT_SELECTOR);

documentSelectorURL.setParameter("mvcPath", "/view.jsp");
documentSelectorURL.setParameter(
"groupId", String.valueOf(themeDisplay.getScopeGroupId()));

String name =
liferayPortletResponse.getNamespace() +
GetterUtil.getString((String)inputEditorTaglibAttributes.get(
"liferay-ui:input-editor:name"));

documentSelectorURL.setParameter("eventName", name + "selectDocument");
documentSelectorURL.setParameter(
"showGroupsSelector", Boolean.TRUE.toString());

Map<String, String> fileBrowserParamsMap =
(Map<String, String>)inputEditorTaglibAttributes.get(
"liferay-ui:input-editor:fileBrowserParams");

if (fileBrowserParamsMap != null) {
for (Map.Entry<String, String> entry :
fileBrowserParamsMap.entrySet()) {

documentSelectorURL.setParameter(entry.getKey(), entry.getValue());
}
}

jsonObject.put("filebrowserBrowseUrl", documentSelectorURL.toString());
jsonObject.put(
"filebrowserFlashBrowseUrl",
documentSelectorURL.toString() + "&Type=flash");
jsonObject.put(
"filebrowserImageBrowseLinkUrl",
documentSelectorURL.toString() + "&Type=image");
jsonObject.put(
"filebrowserImageBrowseUrl",
documentSelectorURL.toString() + "&Type=image");

String languageId = LocaleUtil.toLanguageId(themeDisplay.getLocale());

jsonObject.put("language", languageId.replace("iw_", "he_"));
jsonObject.put("srcNode", "#" + name);
}

public void populateOptionsJSONObject(
JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes,
ThemeDisplay themeDisplay,
LiferayPortletResponse liferayPortletResponse) {
}

}
@@ -0,0 +1,100 @@
/**
* 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.comments.portlet.editor.conf;

import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.portlet.LiferayPortletResponse;
import com.liferay.portal.kernel.portlet.LiferayPortletURL;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.Validator;
import com.liferay.portal.theme.ThemeDisplay;
import com.liferay.portal.util.PortalUtil;
import com.liferay.portlet.editor.config.PortletEditorConfigContributor;

import java.util.Map;

import org.osgi.service.component.annotations.Component;

/**
* @author Sergio González
*/
@Component(property = {"editor.config.key=commentsEditor"})
public class CommentsPortletEditorConfigContributor
implements PortletEditorConfigContributor {

public void populateConfigJSONObject(
JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes,
ThemeDisplay themeDisplay,
LiferayPortletResponse liferayPortletResponse) {

JSONObject trigger = JSONFactoryUtil.createJSONObject();
trigger.put(
"resultFilters", "function(query, results) {return results;}");
trigger.put("resultTextLocator", "screenName");

LiferayPortletURL autoCompleteUserURL =
liferayPortletResponse.createResourceURL("1_WAR_mentionsportlet");

String source =
autoCompleteUserURL.toString() + "&" +
PortalUtil.getPortletNamespace("1_WAR_mentionsportlet");

trigger.put("source", source);
trigger.put("term", "@");
trigger.put("tplReplace", "{mention}");

StringBundler sb = new StringBundler(8);

sb.append("<div class=\"display-style-3 taglib-user-display\">");
sb.append("<span>");
sb.append("<span class=\"user-profile-image\" ");
sb.append("style=\"background-image: url('{portraitURL}');");
sb.append("background-size: 32px 32px; height: 32px; width: 32px;\"");
sb.append("</span><span class=\"user-name\">{fullName}</span>");
sb.append("<span class=\"user-details\">@{screenName}</span></span>");
sb.append("</div>");

trigger.put("tplResults", sb.toString());

JSONArray array = JSONFactoryUtil.createJSONArray();

array.put(trigger);

JSONObject autoCompleteConfig = JSONFactoryUtil.createJSONObject();

String extraPlugins = jsonObject.getString("extraPlugins");

if (Validator.isNotNull(extraPlugins)) {
extraPlugins += ",autocomple";
}
else {
extraPlugins = "autocomplete";
}

autoCompleteConfig.put("extraPlugins", extraPlugins);
autoCompleteConfig.put("trigger", array);

jsonObject.put("autocomplete", autoCompleteConfig);
}

public void populateOptionsJSONObject(
JSONObject jsonObject, Map<String, Object> inputEditorTaglibAttributes,
ThemeDisplay themeDisplay,
LiferayPortletResponse liferayPortletResponse) {
}

}
32 changes: 0 additions & 32 deletions portal-web/docroot/html/js/editor/alloyeditor.jsp
Expand Up @@ -35,7 +35,6 @@ JSONObject editorConfigJSONObject = (data != null) ? (JSONObject)data.get("edito
JSONObject editorOptionsJSONObject = (data != null) ? (JSONObject)data.get("editorOptions") : null;
String editorImpl = (String)request.getAttribute("liferay-ui:input-editor:editorImpl");
Map<String, String> fileBrowserParamsMap = (Map<String, String>)request.getAttribute("liferay-ui:input-editor:fileBrowserParams");
String name = namespace + GetterUtil.getString((String)request.getAttribute("liferay-ui:input-editor:name"));
String initMethod = (String)request.getAttribute("liferay-ui:input-editor:initMethod");
Expand Down Expand Up @@ -175,9 +174,6 @@ if (showSource) {
Locale contentsLocale = LocaleUtil.fromLanguageId(contentsLanguageId);
contentsLanguageId = LocaleUtil.toLanguageId(contentsLocale);
String contentsLanguageDir = LanguageUtil.get(contentsLocale, "lang.dir");
String languageId = LocaleUtil.toLanguageId(locale);
%>

var alloyEditor;
Expand All @@ -186,34 +182,6 @@ if (showSource) {
document.getElementById('<%= name %>').setAttribute('contenteditable', true);

var defaultConfig = {
contentsLangDirection: '<%= HtmlUtil.escapeJS(contentsLanguageDir) %>',

contentsLanguage: '<%= contentsLanguageId.replace("iw_", "he_") %>',

<liferay-portlet:renderURL portletName="<%= PortletKeys.DOCUMENT_SELECTOR %>" varImpl="documentSelectorURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
<portlet:param name="mvcPath" value="/view.jsp" />
<portlet:param name="groupId" value="<%= String.valueOf(scopeGroupId) %>" />
<portlet:param name="eventName" value='<%= name + "selectDocument" %>' />
<portlet:param name="showGroupsSelector" value="true" />
</liferay-portlet:renderURL>

<%
if (fileBrowserParamsMap != null) {
for (Map.Entry<String, String> entry : fileBrowserParamsMap.entrySet()) {
documentSelectorURL.setParameter(entry.getKey(), entry.getValue());
}
}
%>

filebrowserBrowseUrl: '<%= documentSelectorURL %>',
filebrowserFlashBrowseUrl: '<%= documentSelectorURL %>&Type=flash',
filebrowserImageBrowseLinkUrl: '<%= documentSelectorURL %>&Type=image',
filebrowserImageBrowseUrl: '<%= documentSelectorURL %>&Type=image',

language: '<%= languageId.replace("iw_", "he_") %>',

srcNode: '#<%= name %>',

toolbars: {
add: ['imageselector'],
image: ['left', 'right'],
Expand Down
2 changes: 1 addition & 1 deletion portal-web/docroot/html/taglib/ui/discussion/page.jsp
Expand Up @@ -144,7 +144,7 @@ CommentsEditorDisplayContext commentsEditorDisplayContext = new CommentsEditorDi
</div>

<div class="lfr-discussion-body">
<liferay-ui:input-editor contents="" data="<%= commentsEditorDisplayContext.getEditorData() %>" editorImpl="<%= EDITOR_IMPL_KEY %>" name='<%= randomNamespace + "postReplyBody0" %>' onChangeMethod='<%= randomNamespace + "0OnChange" %>' placeholder="type-your-comment-here" />
<liferay-ui:input-editor configKey="commentsEditor" contents="" data="<%= commentsEditorDisplayContext.getEditorData() %>" editorImpl="<%= EDITOR_IMPL_KEY %>" name='<%= randomNamespace + "postReplyBody0" %>' onChangeMethod='<%= randomNamespace + "0OnChange" %>' placeholder="type-your-comment-here" />

<aui:input name="postReplyBody0" type="hidden" />

Expand Down
Expand Up @@ -165,7 +165,7 @@ Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(locale, timeZo

<c:if test="<%= !hideControls && MBDiscussionPermission.contains(permissionChecker, company.getCompanyId(), scopeGroupId, permissionClassName, permissionClassPK, message.getMessageId(), message.getUserId(), ActionKeys.UPDATE_DISCUSSION) %>">
<div class="lfr-discussion-form lfr-discussion-form-edit" id="<%= namespace + randomNamespace %>editForm<%= index %>" style='<%= "display: none; max-width: " + ModelHintsConstants.TEXTAREA_DISPLAY_WIDTH + "px;" %>'>
<liferay-ui:input-editor autoCreate="<%= false %>" contents="<%= message.getBody() %>" data="<%= commentsEditorDisplayContext.getEditorData() %>" editorImpl="<%= EDITOR_TEXT_IMPL_KEY %>" name='<%= randomNamespace + "editReplyBody" + index %>' />
<liferay-ui:input-editor autoCreate="<%= false %>" configKey="commentsEditor" contents="<%= message.getBody() %>" data="<%= commentsEditorDisplayContext.getEditorData() %>" editorImpl="<%= EDITOR_TEXT_IMPL_KEY %>" name='<%= randomNamespace + "editReplyBody" + index %>' />

<aui:input name='<%= "editReplyBody" + index %>' type="hidden" value="<%= message.getBody() %>" />

Expand Down Expand Up @@ -293,7 +293,7 @@ Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(locale, timeZo
</div>

<div class="lfr-discussion-body">
<liferay-ui:input-editor autoCreate="<%= false %>" contents="" data="<%= commentsEditorDisplayContext.getEditorData() %>" editorImpl="<%= EDITOR_TEXT_IMPL_KEY %>" name='<%= randomNamespace + "postReplyBody" + index %>' onChangeMethod='<%= randomNamespace + index + "OnChange" %>' placeholder="type-your-comment-here" />
<liferay-ui:input-editor autoCreate="<%= false %>" configKey="commentsEditor" contents="" data="<%= commentsEditorDisplayContext.getEditorData() %>" editorImpl="<%= EDITOR_TEXT_IMPL_KEY %>" name='<%= randomNamespace + "postReplyBody" + index %>' onChangeMethod='<%= randomNamespace + index + "OnChange" %>' placeholder="type-your-comment-here" />

<aui:input name='<%= "postReplyBody" + index %>' type="hidden" />

Expand Down

0 comments on commit c1648ba

Please sign in to comment.