Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
PLF-7947 Connect button is no longer present on the profile card (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
nttuyen authored and mbensalem committed Aug 24, 2018
1 parent 129e57c commit 39ca871
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright (C) 2018 eXo Platform SAS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.exoplatform.platform.component;

import org.exoplatform.social.core.relationship.model.Relationship;
import org.exoplatform.social.core.relationship.model.Relationship.Type;
import org.exoplatform.social.webui.Utils;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIComponent;
import org.exoplatform.webui.core.UIPortletApplication;
import org.exoplatform.webui.event.Event;
import org.exoplatform.webui.event.EventListener;

@ComponentConfig(
template = "app:/groovy/platformNavigation/portlet/UIUserNavigationPortlet/UIRelationshipAction.gtmpl",
events = {
@EventConfig(listeners = UIRelationshipAction.ConnectActionListener.class),
@EventConfig(listeners = UIRelationshipAction.CancelActionListener.class),
@EventConfig(listeners = UIRelationshipAction.AcceptActionListener.class),
@EventConfig(listeners = UIRelationshipAction.DenyActionListener.class),
@EventConfig(listeners = UIRelationshipAction.DisconnectActionListener.class)
}
)
public class UIRelationshipAction extends UIComponent {

public UIRelationshipAction() {
}

public static abstract class AbstractActionListener extends EventListener<UIRelationshipAction> {
protected Relationship relationship = null;
protected String msgKey = "UIRelationshipAction.label.ConnectNotExisting";
@Override
public void execute(Event<UIRelationshipAction> event) {
UIRelationshipAction uiAction = event.getSource();
relationship = Utils.getRelationshipManager().get(Utils.getOwnerIdentity(), Utils.getViewerIdentity());
if (isValid(event)) {
doAction(event);
} else {
uiAction.getAncestorOfType(UIPortletApplication.class).addMessage(new ApplicationMessage(msgKey, new String[]{}, ApplicationMessage.WARNING));
}
//
event.getRequestContext().addUIComponentToUpdateByAjax(uiAction.getParent());
}
protected boolean isValid(Event<UIRelationshipAction> event) {
return (relationship != null);
}
protected abstract void doAction(Event<UIRelationshipAction> event);
}

public static class ConnectActionListener extends AbstractActionListener {
@Override
protected boolean isValid(Event<UIRelationshipAction> event) {
msgKey = "UIRelationshipAction.label.ConnectionExisted";
return (relationship == null);
}
@Override
protected void doAction(Event<UIRelationshipAction> event) {// sender --> owner
Utils.getRelationshipManager().inviteToConnect(Utils.getViewerIdentity(), Utils.getOwnerIdentity());
}
}

public static class CancelActionListener extends AbstractActionListener {
@Override
protected void doAction(Event<UIRelationshipAction> event) {
Utils.getRelationshipManager().deny(relationship.getReceiver(), relationship.getSender());
}
}

public static class AcceptActionListener extends AbstractActionListener {
@Override
protected boolean isValid(Event<UIRelationshipAction> event) {
return super.isValid(event) && (relationship.getStatus() != Type.IGNORED);
}

@Override
protected void doAction(Event<UIRelationshipAction> event) {
Utils.getRelationshipManager().confirm(relationship.getReceiver(), relationship.getSender());
Utils.updateWorkingWorkSpace();
}
}

public static class DenyActionListener extends AbstractActionListener {
@Override
protected boolean isValid(Event<UIRelationshipAction> event) {
return super.isValid(event);
}

@Override
protected void doAction(Event<UIRelationshipAction> event) {
Utils.getRelationshipManager().deny(relationship.getReceiver(), relationship.getSender());
Utils.updateWorkingWorkSpace();
}
}

public static class DisconnectActionListener extends AbstractActionListener {
@Override
protected void doAction(Event<UIRelationshipAction> event) {
Utils.getRelationshipManager().delete(relationship);
Utils.updateWorkingWorkSpace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public UIUserNavigationPortlet() throws Exception {
addChild(uiBanner);
uiAvatarBanner = createUIComponent(UIBannerAvatarUploader.class, null, null);
addChild(uiAvatarBanner);

UIRelationshipAction uiAction = createUIComponent(UIRelationshipAction.class, null, null);
addChild(uiAction);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@
<UIBannerUploader>Upload an Image</UIBannerUploader>
</title>
</UIPopupBannerUploader>
<UIRelationshipAction>
<action>
<AcceptRequest>Accept</AcceptRequest>
<Deny>Deny</Deny>
<RemoveConnection>Disconnect</RemoveConnection>
<CancelRequest>Cancel Request</CancelRequest>
</action>
<label>
<Connect>Connect</Connect>
<ConnectNotExisting>Invitation was canceled by someone else.</ConnectNotExisting>
<ConnectionExisted>Invitation was established by someone else.</ConnectionExisted>
</label>
</UIRelationshipAction>
</bundle>
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@
<UIBannerUploader>Ajouter une Photo</UIBannerUploader>
</title>
</UIPopupBannerUploader>
<UIRelationshipAction>
<action>
<AcceptRequest>Accepter la demande</AcceptRequest>
<Deny>Refuser</Deny>
<RemoveConnection>D\u00E9connexion</RemoveConnection>
<CancelRequest>Annuler la demande</CancelRequest>
</action>
<label>
<Connect>Se connecter</Connect>
<ConnectNotExisting>L'invitation a \u00E9t\u00E9 annul\u00E9e par une autre personne</ConnectNotExisting>
<ConnectionExisted>L'invitation a \u00E9t\u00E9 \u00E9tablie par quelqu'un d'autre.</ConnectionExisted>
</label>
</UIRelationshipAction>
</bundle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<%
import org.exoplatform.social.webui.Utils;
import org.exoplatform.social.core.relationship.model.Relationship.Type;

def viewerIdentity = Utils.getViewerIdentity();// current login user
def ownerIdentity = Utils.getOwnerIdentity();

_ctx.getRequestContext().getJavascriptManager().require("SHARED/bts_modal");
%>
<div class="uiRelationshipAction" id="<%=uicomponent.getId();%>">
<div class="user-actions pull-right">
<%
if (!ownerIdentity.equals(viewerIdentity)) {
def relationship = Utils.getRelationshipManager().get(viewerIdentity, ownerIdentity);
def status = (relationship != null) ? relationship.getStatus() : null;

if(status == null) {
%>
<button type="button" class="btn btn-default" onclick="<%=uicomponent.event("Connect")%>">
<i class="uiIconSocConnectUser"></i>
<span><%=_ctx.appRes("UIRelationshipAction.label.Connect")%></span>
</button>
<%
} else if(status == Type.PENDING) {//PENDING
if(relationship.getSender().equals(viewerIdentity)) {
%>
<button type="button" class="btn" onclick="<%=uicomponent.event("Cancel")%>">
<i class="uiIconClose"></i>
<span><%=_ctx.appRes("UIRelationshipAction.action.CancelRequest")%></span>
</button>
<%
} else {
%>
<div class="btn-group btnStatusAnswer">
<button type="button" class="btn btn-default" onclick="<%=uicomponent.event("Accept")%>">
<%=_ctx.appRes("UIRelationshipAction.action.AcceptRequest")%>
</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<li><a href="javascript: void(0)" onclick="<%=uicomponent.event("Deny")%>">
<%=_ctx.appRes("UIRelationshipAction.action.Deny")%>
</a></li>
</ul>
</div>
<div class="btn statusAnswer" data-toggle="modal" data-target="#popStatusAnswer">
<i class="uiIconClock"></i>
<div id="popStatusAnswer" class="popStatusAnswer modal" tabindex="-1" role="dialog">
<div onclick="<%=uicomponent.event("Accept")%>"><%=_ctx.appRes("UIRelationshipAction.action.AcceptRequest")%></div>
<hr/>
<div onclick="<%=uicomponent.event("Deny")%>"><%=_ctx.appRes("UIRelationshipAction.action.Deny")%></div>
</div>
</div>
<%
}
}
}
%>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ if (uicomponent.isProfileOwner()) {
</li>
<% } %>
</ul>
</div>
</div>

<% uicomponent.renderChild(org.exoplatform.platform.component.UIRelationshipAction.class); %>
</div>

<ul class="nav nav-tabs userNavigation" style="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
MORE_LABEL : "",
initNavigation : function(moreLabel) {
UIUserNavigation.MORE_LABEL = moreLabel;


var $popupStatus = $('.uiRelationshipAction .popStatusAnswer');
var $parent = $popupStatus.parent();
$popupStatus.on('show.bs.modal', function() {
$('body').append($popupStatus);
}).on('hide.bs.modal', function() {
$parent.append($popupStatus);
});
$popupStatus.find('div').click(function() {
$(this).parent().modal('hide');
return false;
});

//
function autoMoveApps(){
var _w = $(window).outerWidth();
Expand Down

0 comments on commit 39ca871

Please sign in to comment.