From 90f89fef729a68c2bf57afa9a358999f794d52e7 Mon Sep 17 00:00:00 2001 From: Julien Castelain Date: Wed, 24 Feb 2021 17:31:43 +0100 Subject: [PATCH] Migrate v2 usages in roles/roles-admin-web The tag has been replaced with the 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 --- ...nmentsManagementToolbarDisplayContext.java | 6 +- .../resources/edit_role_assignments.jsp | 142 +++++------------- .../resources/META-INF/resources/init.jsp | 2 +- .../resources/js/EditRoleAssignments.js | 48 ++++++ ...nmentsManagementToolbarPropsTransformer.js | 97 ++++++++++++ ...wRolesManagementToolbarPropsTransformer.js | 60 ++++++++ .../META-INF/resources/js/add_assignees.js | 65 ++++++++ .../META-INF/resources/select_assignees.jsp | 9 +- .../resources/select_organization_role.jspf | 3 +- .../resources/select_regular_role.jspf | 2 +- .../META-INF/resources/select_site_role.jspf | 3 +- .../resources/META-INF/resources/view.jsp | 65 ++------ 12 files changed, 329 insertions(+), 173 deletions(-) create mode 100644 modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignments.js create mode 100644 modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignmentsManagementToolbarPropsTransformer.js create mode 100644 modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/ViewRolesManagementToolbarPropsTransformer.js create mode 100644 modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/add_assignees.js diff --git a/modules/apps/roles/roles-admin-web/src/main/java/com/liferay/roles/admin/web/internal/display/context/EditRoleAssignmentsManagementToolbarDisplayContext.java b/modules/apps/roles/roles-admin-web/src/main/java/com/liferay/roles/admin/web/internal/display/context/EditRoleAssignmentsManagementToolbarDisplayContext.java index 7779a90b7b2532..194256810931c2 100644 --- a/modules/apps/roles/roles-admin-web/src/main/java/com/liferay/roles/admin/web/internal/display/context/EditRoleAssignmentsManagementToolbarDisplayContext.java +++ b/modules/apps/roles/roles-admin-web/src/main/java/com/liferay/roles/admin/web/internal/display/context/EditRoleAssignmentsManagementToolbarDisplayContext.java @@ -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; @@ -115,10 +114,7 @@ public List 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")); diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/edit_role_assignments.jsp b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/edit_role_assignments.jsp index 8f8817b3a6fcaa..e4082bbb5c497b 100644 --- a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/edit_role_assignments.jsp +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/edit_role_assignments.jsp @@ -56,12 +56,44 @@ renderResponse.setTitle(role.getTitle(locale)); navigationItems="<%= roleDisplayContext.getRoleAssignmentsNavigationItems(portletURL) %>" /> - + + + + + + + + + + + + + +<% +HashMap additionalProps = HashMapBuilder.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(); +%> + + - - - - - - - var form = document.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: 'selectAssignees', - title: - '', - - - - - - - - - - - url: '<%= selectAssigneesURL %>', - }); - }; - - unsetRoleAssignments = function () { - var assigneeType = '<%= HtmlUtil.escapeJS(tabs2) %>'; - var ids = Liferay.Util.listCheckedExcept( - form, - '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(); - } - \ No newline at end of file + \ No newline at end of file diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/init.jsp b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/init.jsp index 64ad38a422ea4a..2daba862ea88a5 100644 --- a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/init.jsp +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/init.jsp @@ -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" %><%@ @@ -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" %><%@ diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignments.js b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignments.js new file mode 100644 index 00000000000000..0126ceba90237e --- /dev/null +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignments.js @@ -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); + }, + }; +} diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignmentsManagementToolbarPropsTransformer.js b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignmentsManagementToolbarPropsTransformer.js new file mode 100644 index 00000000000000..77dabba73079ca --- /dev/null +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/EditRoleAssignmentsManagementToolbarPropsTransformer.js @@ -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, + }); + }, + }; +} diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/ViewRolesManagementToolbarPropsTransformer.js b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/ViewRolesManagementToolbarPropsTransformer.js new file mode 100644 index 00000000000000..009a6ace6975bc --- /dev/null +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/ViewRolesManagementToolbarPropsTransformer.js @@ -0,0 +1,60 @@ +/** + * 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'; + +export default function propsTransformer({ + additionalProps: {deleteRolesURL}, + portletNamespace, + ...otherProps +}) { + const deleteRoles = () => { + const form = document.getElementById(`${portletNamespace}fm`); + + if (!form) { + return; + } + + const deleteRoleIds = Liferay.Util.listCheckedExcept( + form, + `${portletNamespace}allRowIds` + ); + + if ( + confirm( + Liferay.Language.get( + 'are-you-sure-you-want-to-delete-this-role' + ) + ) + ) { + postForm(form, { + data: { + deleteRoleIds, + }, + url: deleteRolesURL, + }); + } + }; + + return { + ...otherProps, + onActionButtonClick(event, {item}) { + const action = item.data?.action; + + if (action === 'deleteRoles') { + deleteRoles(); + } + }, + }; +} diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/add_assignees.js b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/add_assignees.js new file mode 100644 index 00000000000000..45b06d230003c6 --- /dev/null +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/js/add_assignees.js @@ -0,0 +1,65 @@ +/** + * 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 {createPortletURL, openSelectionModal, postForm} from 'frontend-js-web'; + +export default function addAssignees({ + editRoleAssignmentsURL, + portletNamespace, + portletURL, + roleName, + selectAssigneesURL, +}) { + openSelectionModal({ + multiple: true, + onSelect(selectedItem) { + if (selectedItem) { + const form = document.getElementById(`${portletNamespace}fm`); + + if (!form) { + return; + } + + const assignmentsRedirect = createPortletURL(portletURL, { + tabs2: selectedItem.type, + }); + + const 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; + } + + postForm(form, { + data, + url: editRoleAssignmentsURL, + }); + } + }, + selectEventName: `${portletNamespace}selectAssignees`, + title: Liferay.Util.sub( + Liferay.Language.get('add-assignees-to-x'), + roleName + ), + url: selectAssigneesURL, + }); +} diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_assignees.jsp b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_assignees.jsp index c83bbab700b5c5..4243ddfc5ee112 100644 --- a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_assignees.jsp +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_assignees.jsp @@ -47,7 +47,7 @@ PortletURL portletURL = editRoleAssignmentsManagementToolbarDisplayContext.getPo navigationItems="<%= roleDisplayContext.getSelectAssigneesNavigationItems(portletURL) %>" /> - - - \ No newline at end of file + \ No newline at end of file diff --git a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_organization_role.jspf b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_organization_role.jspf index 352e974cd7e1dc..dde6062bb58cd8 100644 --- a/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_organization_role.jspf +++ b/modules/apps/roles/roles-admin-web/src/main/resources/META-INF/resources/select_organization_role.jspf @@ -66,9 +66,10 @@ else { } %> - roleSearchContainer = selectRoleManagementToolbarDisplayContext.getRoleSearchContainer(filterManageableRoles); %> - roleSearchContainer = selectRoleManagementToolbarDisplayContext.getRoleSearchContainer(filterManageableRoles, groupId); %> - - + + + + - - - - var deleteRoles = function (deleteRoleIds) { - var form = document.fm; - - var p_p_lifecycle = form.p_p_lifecycle; - - if (p_p_lifecycle) { - p_p_lifecycle.value = '1'; - } - - if ( - confirm( - '<%= UnicodeLanguageUtil.get(request, "are-you-sure-you-want-to-delete-this-role") %>' - ) - ) { - Liferay.Util.postForm(form, { - data: { - deleteRoleIds: deleteRoleIds, - }, - - - - - - url: '<%= deleteRolesURL %>', - }); - } - }; - - var ACTIONS = { - deleteRoles: deleteRoles, - }; - - Liferay.componentReady('viewRolesManagementToolbar').then( - (managementToolbar) => { - managementToolbar.on('actionItemClicked', (event) => { - var itemData = event.data.item.data; - - if (itemData && itemData.action && ACTIONS[itemData.action]) { - ACTIONS[itemData.action]( - Liferay.Util.listCheckedExcept( - document.fm, - 'allRowIds' - ) - ); - } - }); - } - ); - \ No newline at end of file + \ No newline at end of file