Skip to content

Commit

Permalink
Migrate v2 usages in roles/roles-admin-web
Browse files Browse the repository at this point in the history
The <clay:management-toolbar-v2 /> tag has been replaced with the
<clay:management-toolbar /> tag (which uses clay v3).

**Test plan**:
- From the global menu, select the **Control Panel** tab
- Navigate to **Roles**
- Make sure you can:
    - Create and delete Regular Roles
    - Create and delete Site Roles
    - Create and delete Organization Roles
    - Create and delete Asset Library Roles
    - Create and delete Account Roles
- Create a Regular Role
- Select (click) the Regular Role you created previously
- Navigate to the **Assignees** tab
- Make sure you can add assignees from this role
- Make sure you can remove assignees from this role
  • Loading branch information
Julien Castelain committed Feb 24, 2021
1 parent dc44ecb commit 90f89fe
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.liferay.frontend.taglib.clay.servlet.taglib.util.DropdownItemList;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.ViewTypeItem;
import com.liferay.frontend.taglib.clay.servlet.taglib.util.ViewTypeItemList;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.dao.search.EmptyOnClickRowChecker;
import com.liferay.portal.kernel.dao.search.SearchContainer;
Expand Down Expand Up @@ -115,10 +114,7 @@ public List<DropdownItem> getActionDropdownItems() throws Exception {
() -> {
DropdownItem dropdownItem = new DropdownItem();

dropdownItem.setHref(
StringBundler.concat(
"javascript:", _renderResponse.getNamespace(),
"unsetRoleAssignments();"));
dropdownItem.putData("action", "unsetRoleAssignments");
dropdownItem.setIcon("times-circle");
dropdownItem.setLabel(
LanguageUtil.get(_httpServletRequest, "remove"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,44 @@ renderResponse.setTitle(role.getTitle(locale));
navigationItems="<%= roleDisplayContext.getRoleAssignmentsNavigationItems(portletURL) %>"
/>

<clay:management-toolbar-v2
<portlet:actionURL name="editRoleAssignments" var="editRoleAssignmentsURL">
<portlet:param name="mvcPath" value="/edit_role_assignments.jsp" />
<portlet:param name="tabs1" value="assignees" />
</portlet:actionURL>

<portlet:renderURL var="selectAssigneesURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
<portlet:param name="mvcPath" value="/select_assignees.jsp" />
<portlet:param name="tabs2" value="<%= tabs2 %>" />
<portlet:param name="tabs3" value="available" />
<portlet:param name="redirect" value="<%= currentURL %>" />
<portlet:param name="roleId" value="<%= String.valueOf(roleId) %>" />
<portlet:param name="displayStyle" value="<%= displayStyle %>" />
</portlet:renderURL>

<%
HashMap<String, Object> additionalProps = HashMapBuilder.<String, Object>put(
"assigneeType", HtmlUtil.escapeJS(tabs2)
).put(
"editRoleAssignmentsURL", editRoleAssignmentsURL.toString()
).put(
"modalSegmentState", RolesAdminWebKeys.MODAL_SEGMENT_STATE
).put(
"portletURL", portletURL.toString()
).put(
"roleName", role.getName()
).put(
"selectAssigneesURL", selectAssigneesURL.toString()
).build();
%>

<clay:management-toolbar
actionDropdownItems="<%= editRoleAssignmentsManagementToolbarDisplayContext.getActionDropdownItems() %>"
additionalProps="<%= additionalProps %>"
clearResultsURL="<%= editRoleAssignmentsManagementToolbarDisplayContext.getClearResultsURL() %>"
componentId="editRoleAssignmentsManagementToolbar"
creationMenu="<%= editRoleAssignmentsManagementToolbarDisplayContext.getCreationMenu() %>"
filterDropdownItems="<%= editRoleAssignmentsManagementToolbarDisplayContext.getFilterDropdownItems() %>"
itemsTotal="<%= searchContainer.getTotal() %>"
propsTransformer="js/EditRoleAssignmentsManagementToolbarPropsTransformer"
searchActionURL="<%= editRoleAssignmentsManagementToolbarDisplayContext.getSearchActionURL() %>"
searchContainerId="assigneesSearch"
searchFormName="searchFm"
Expand Down Expand Up @@ -118,105 +150,7 @@ renderResponse.setTitle(role.getTitle(locale));
</c:choose>
</aui:form>

<portlet:actionURL name="editRoleAssignments" var="editRoleAssignmentsURL">
<portlet:param name="mvcPath" value="/edit_role_assignments.jsp" />
<portlet:param name="tabs1" value="assignees" />
</portlet:actionURL>

<aui:script sandbox="<%= true %>">
var form = document.<portlet:namespace />fm;

var addAssignees = function (event) {
Liferay.Util.openSelectionModal({
multiple: true,
onSelect: function (selectedItem) {
if (selectedItem) {
var assignmentsRedirect = Liferay.Util.PortletURL.createPortletURL(
'<%= portletURL.toString() %>',
{
tabs2: selectedItem.type,
}
);

var data = {
redirect: assignmentsRedirect.toString(),
};

if (selectedItem.type == 'segments') {
data.addSegmentsEntryIds = selectedItem.value;
}
else if (selectedItem.type === 'users') {
data.addUserIds = selectedItem.value;
}
else {
data.addGroupIds = selectedItem.value;
}

Liferay.Util.postForm(form, {
data: data,
url: '<%= editRoleAssignmentsURL %>',
});
}
},
selectEventName: '<portlet:namespace />selectAssignees',
title:
'<liferay-ui:message arguments="<%= HtmlUtil.escape(role.getName()) %>" key="add-assignees-to-x" />',

<portlet:renderURL var="selectAssigneesURL" windowState="<%= LiferayWindowState.POP_UP.toString() %>">
<portlet:param name="mvcPath" value="/select_assignees.jsp" />
<portlet:param name="tabs2" value="<%= tabs2 %>" />
<portlet:param name="tabs3" value="available" />
<portlet:param name="redirect" value="<%= currentURL %>" />
<portlet:param name="roleId" value="<%= String.valueOf(roleId) %>" />
<portlet:param name="displayStyle" value="<%= displayStyle %>" />
</portlet:renderURL>

url: '<%= selectAssigneesURL %>',
});
};

<portlet:namespace />unsetRoleAssignments = function () {
var assigneeType = '<%= HtmlUtil.escapeJS(tabs2) %>';
var ids = Liferay.Util.listCheckedExcept(
form,
'<portlet:namespace />allRowIds'
);

var data = {
assignmentsRedirect: '<%= portletURL.toString() %>',
};

if (assigneeType == 'segments') {
data.removeSegmentsEntryIds = ids;
}
else if (assigneeType === 'users') {
data.removeUserIds = ids;
}
else {
data.removeGroupIds = ids;
}

Liferay.Util.postForm(form, {
data: data,
url: '<%= editRoleAssignmentsURL %>',
});
};

Liferay.componentReady('editRoleAssignmentsManagementToolbar').then(
(managementToolbar) => {
managementToolbar.on('creationButtonClicked', addAssignees);
}
);

var state = window.sessionStorage.getItem(
'<%= RolesAdminWebKeys.MODAL_SEGMENT_STATE %>'
);

if (state == 'open') {
window.sessionStorage.removeItem(
'<%= RolesAdminWebKeys.MODAL_SEGMENT_STATE %>'
);

addAssignees();
}
</aui:script>
<liferay-frontend:component
context="<%= additionalProps %>"
module="js/EditRoleAssignments"
/>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ page import="com.liferay.portal.kernel.exception.RoleNameException" %><%@
page import="com.liferay.portal.kernel.exception.RolePermissionsException" %><%@
page import="com.liferay.portal.kernel.exception.SystemException" %><%@
page import="com.liferay.portal.kernel.language.LanguageUtil" %><%@
page import="com.liferay.portal.kernel.language.UnicodeLanguageUtil" %><%@
page import="com.liferay.portal.kernel.model.Group" %><%@
page import="com.liferay.portal.kernel.model.GroupConstants" %><%@
page import="com.liferay.portal.kernel.model.Organization" %><%@
Expand Down Expand Up @@ -144,6 +143,7 @@ page import="com.liferay.users.admin.kernel.util.UsersAdminUtil" %>
<%@ page import="java.util.ArrayList" %><%@
page import="java.util.Collections" %><%@
page import="java.util.HashMap" %><%@
page import="java.util.HashSet" %><%@
page import="java.util.List" %><%@
page import="java.util.Map" %><%@
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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.
*/

import addAssignees from './add_assignees';

export default function EditRoleAssignments({
editRoleAssignmentsURL,
modalSegmentState,
namespace,
portletURL,
roleName,
selectAssigneesURL,
}) {
const checkSessionStorage = () => {
const state = window.sessionStorage.getItem(modalSegmentState);

if (state === 'open') {
window.sessionStorage.removeItem(modalSegmentState);

addAssignees({
editRoleAssignmentsURL,
portletNamespace: namespace,
portletURL,
roleName,
selectAssigneesURL,
});
}
};

window.addEventListener('load', checkSessionStorage);

return {
dispose() {
window.removeEventListener('load', checkSessionStorage);
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* 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.
*/

/**
* 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.
*/

import {postForm} from 'frontend-js-web';

import addAssignees from './add_assignees';

export default function propsTransformer({
additionalProps: {
assigneeType,
editRoleAssignmentsURL,
portletURL,
roleName,
selectAssigneesURL,
},
portletNamespace,
...otherProps
}) {
const unsetRoleAssignments = () => {
const form = document.getElementById(`${portletNamespace}fm`);

if (!form) {
return;
}

// var assigneeType = '<%= HtmlUtil.escapeJS(tabs2) %>';

const ids = Liferay.Util.listCheckedExcept(
form,
`${portletNamespace}allRowIds`
);

const data = {
assignmentsRedirect: portletURL,
};

if (assigneeType === 'segments') {
data.removeSegmentsEntryIds = ids;
}
else if (assigneeType === 'users') {
data.removeUserIds = ids;
}
else {
data.removeGroupIds = ids;
}

postForm(form, {
data,
url: editRoleAssignmentsURL,
});
};

return {
...otherProps,
onActionButtonClick(event, {item}) {
const action = item.data?.action;

if (action === 'unsetRoleAssignments') {
unsetRoleAssignments();
}
},
onCreateButtonClick() {
addAssignees({
editRoleAssignmentsURL,
portletNamespace,
portletURL,
roleName,
selectAssigneesURL,
});
},
};
}
Loading

0 comments on commit 90f89fe

Please sign in to comment.