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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-152229 Replace and deprecate listSelect with new getSelectedOptionValues utility #2199

Closed
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 @@ -371,7 +371,7 @@ announcementsPortletInstanceConfiguration = ParameterMapUtil.setParameterMap(Ann
if (currentScopeGroupIds && selectedScopeGroupIds) {
selectedScopeGroupIds.setAttribute(
'value',
Liferay.Util.listSelect(currentScopeGroupIds)
Liferay.Util.getSelectedOptionValues(currentScopeGroupIds)
);
}

Expand All @@ -385,7 +385,9 @@ announcementsPortletInstanceConfiguration = ParameterMapUtil.setParameterMap(Ann
if (currentScopeOrganizationIds && selectedScopeOrganizationIds) {
selectedScopeOrganizationIds.setAttribute(
'value',
Liferay.Util.listSelect(currentScopeOrganizationIds)
Liferay.Util.getSelectedOptionValues(
currentScopeOrganizationIds
)
);
}

Expand All @@ -399,7 +401,7 @@ announcementsPortletInstanceConfiguration = ParameterMapUtil.setParameterMap(Ann
if (currentScopeRoleIds && selectedScopeRoleIds) {
selectedScopeRoleIds.setAttribute(
'value',
Liferay.Util.listSelect(currentScopeRoleIds)
Liferay.Util.getSelectedOptionValues(currentScopeRoleIds)
);
}

Expand All @@ -413,7 +415,7 @@ announcementsPortletInstanceConfiguration = ParameterMapUtil.setParameterMap(Ann
if (currentScopeUserGroupIds && selectedScopeUserGroupIds) {
selectedScopeUserGroupIds.setAttribute(
'value',
Liferay.Util.listSelect(currentScopeUserGroupIds)
Liferay.Util.getSelectedOptionValues(currentScopeUserGroupIds)
);
}

Expand Down
Expand Up @@ -77,7 +77,7 @@

Liferay.Util.postForm(form, {
data: {
assetVocabularyIds: Liferay.Util.listSelect(
assetVocabularyIds: Liferay.Util.getSelectedOptionValues(
Liferay.Util.getFormElement(form, 'currentAssetVocabularyIds')
),
},
Expand Down
Expand Up @@ -111,7 +111,7 @@ renderResponse.setTitle(assetListDisplayContext.getAssetListEntryTitle());
%>

Liferay.Util.setFormValues(form, {
classTypeIds<%= className %>: Liferay.Util.listSelect(
classTypeIds<%= className %>: Liferay.Util.getSelectedOptionValues(
Liferay.Util.getFormElement(
form,
'<%= className %>currentClassTypeIds'
Expand All @@ -131,7 +131,7 @@ renderResponse.setTitle(assetListDisplayContext.getAssetListEntryTitle());
if (currentClassNameIdsSelect) {
Liferay.Util.postForm(form, {
data: {
classNameIds: Liferay.Util.listSelect(
classNameIds: Liferay.Util.getSelectedOptionValues(
currentClassNameIdsSelect
),
},
Expand Down
Expand Up @@ -74,7 +74,7 @@ List<AssetRendererFactory<?>> classTypesAssetRendererFactories = new ArrayList<>
%>

Liferay.Util.setFormValues(form, {
classTypeIds<%= className %>: Liferay.Util.listSelect(
classTypeIds<%= className %>: Liferay.Util.getSelectedOptionValues(
Liferay.Util.getFormElement(
form,
'<%= className %>currentClassTypeIds'
Expand All @@ -98,10 +98,10 @@ List<AssetRendererFactory<?>> classTypesAssetRendererFactories = new ArrayList<>
if (currentClassNameIdsSelect && currentMetadataFieldsInput) {
Liferay.Util.postForm(form, {
data: {
classNameIds: Liferay.Util.listSelect(
classNameIds: Liferay.Util.getSelectedOptionValues(
currentClassNameIdsSelect
),
metadataFields: Liferay.Util.listSelect(
metadataFields: Liferay.Util.getSelectedOptionValues(
currentMetadataFieldsInput
),
},
Expand All @@ -110,7 +110,7 @@ List<AssetRendererFactory<?>> classTypesAssetRendererFactories = new ArrayList<>
else if (currentMetadataFieldsInput) {
Liferay.Util.postForm(form, {
data: {
metadataFields: Liferay.Util.listSelect(
metadataFields: Liferay.Util.getSelectedOptionValues(
currentMetadataFieldsInput
),
},
Expand Down
Expand Up @@ -276,7 +276,9 @@ catch (NoSuchFolderException nsfe) {
);

if (currentFolderColumns && folderColumns) {
folderColumns.value = Util.listSelect(currentFolderColumns);
folderColumns.value = Util.getSelectedOptionValues(
currentFolderColumns
);
}

var currentEntryColumns = form.querySelector(
Expand All @@ -287,7 +289,9 @@ catch (NoSuchFolderException nsfe) {
);

if (currentEntryColumns && entryColumns) {
entryColumns.value = Util.listSelect(currentEntryColumns);
entryColumns.value = Util.getSelectedOptionValues(
currentEntryColumns
);
}

submitForm(form);
Expand Down
Expand Up @@ -90,7 +90,7 @@ ContentDashboardAdminConfigurationDisplayContext contentDashboardAdminConfigurat
var form = document.<portlet:namespace />fm;
Liferay.Util.postForm(form, {
data: {
assetVocabularyIds: Liferay.Util.listSelect(
assetVocabularyIds: Liferay.Util.getSelectedOptionValues(
Liferay.Util.getFormElement(form, 'currentAssetVocabularyIds')
),
},
Expand Down
Expand Up @@ -246,10 +246,10 @@ DLPortletInstanceSettingsHelper dlPortletInstanceSettingsHelper = new DLPortletI

Util.postForm(form, {
data: {
displayViews: Util.listSelect(
displayViews: Util.getSelectedOptionValues(
Util.getFormElement(form, 'currentDisplayViews')
),
entryColumns: Util.listSelect(
entryColumns: Util.getSelectedOptionValues(
Util.getFormElement(form, 'currentEntryColumns')
),
},
Expand Down
Expand Up @@ -164,7 +164,7 @@ IGConfigurationDisplayContext igConfigurationDisplayContext = (IGConfigurationDi

Liferay.Util.postForm(form, {
data: {
mimeTypes: Liferay.Util.listSelect(
mimeTypes: Liferay.Util.getSelectedOptionValues(
Liferay.Util.getFormElement(form, 'currentMimeTypes')
),
},
Expand Down
Expand Up @@ -489,6 +489,9 @@
return Util.listCheckboxesExcept(form, except, name, true);
},

/**
* @deprecated As of Cavanaugh (7.4.x), replaced by `import {getSelectedOptionValues} from 'frontend-js-web';`
*/
listSelect(select, delimeter) {
select = Util.getElement(select);

Expand Down
Expand Up @@ -105,6 +105,7 @@ export {default as inBrowserView} from './liferay/util/in_browser_view';
export {default as isObject} from './liferay/util/is_object';
export {default as isPhone} from './liferay/util/is_phone';
export {default as isTablet} from './liferay/util/is_tablet';
export {default as getSelectedOptionValues} from './liferay/util/get_selected_option_values';
export {default as navigate} from './liferay/util/navigate.es';
export {default as normalizeFriendlyURL} from './liferay/util/normalize_friendly_url';
export {default as removeEntitySelection} from './liferay/util/remove_entity_selection';
Expand Down
Expand Up @@ -61,6 +61,7 @@ import getLexiconIconTpl from './util/get_lexicon_icon_template';
import getOpener from './util/get_opener';
import getPortletId from './util/get_portlet_id';
import getPortletNamespace from './util/get_portlet_namespace.es';
import getSelectedOptionValues from './util/get_selected_option_values';
import getTop from './util/get_top';
import getURLWithSessionId from './util/get_url_with_session_id';
import getWindow from './util/get_window';
Expand Down Expand Up @@ -251,6 +252,8 @@ Liferay.Util.isPhone = isPhone;
*/
Liferay.Util.isTablet = isTablet;

Liferay.Util.getSelectedOptionValues = getSelectedOptionValues;

Liferay.Util.navigate = navigate;
Liferay.Util.ns = ns;
Liferay.Util.objectToFormData = objectToFormData;
Expand Down
Expand Up @@ -349,6 +349,11 @@ declare module Liferay {

export function getWindow(windowId?: string): Window;

export function getSelectedOptionValues(
select: HTMLSelectElement,
delimiter?: string
): string;

/**
* Performs navigation to the given url. If SPA is enabled, it will route the
* request through the SPA engine. If not, it will simple change the document
Expand Down
@@ -0,0 +1,29 @@
/**
* 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.
*/

export default function getSelectedOptionValues(select, delimiter = ',') {
const optionsArray = Array.from(select.getElementsByTagName('option'));

return optionsArray
.reduce((previous, item) => {
const {value} = item;

if (value) {
previous.push(value);
}

return previous;
}, [])
.join(delimiter);
}
Expand Up @@ -97,7 +97,7 @@ long[] classNameIdValues = StringUtil.split(ParamUtil.getString(request, "classN
if (classNameIds && currentClassNameIds) {
classNameIds.setAttribute(
'value',
Liferay.Util.listSelect(currentClassNameIds)
Liferay.Util.getSelectedOptionValues(currentClassNameIds)
);
}

Expand Down
Expand Up @@ -76,7 +76,7 @@ for (AssetRendererFactory<?> assetRendererFactory : assetEntriesSearchFacet.getA

data[
'<%= assetEntriesSearchFacet.getClassName() + "assetTypes" %>'
] = Liferay.Util.listSelect(currentAssetTypes);
] = Liferay.Util.getSelectedOptionValues(currentAssetTypes);

Liferay.Util.postForm(form, {data: data});
});
Expand Down
Expand Up @@ -124,7 +124,7 @@ TypeFacetPortletPreferences typeFacetPortletPreferences = new com.liferay.portal

data[
'<%= PortletPreferencesJspUtil.getInputName(TypeFacetPortletPreferences.PREFERENCE_KEY_ASSET_TYPES) %>'
] = Liferay.Util.listSelect(currentAssetTypes);
] = Liferay.Util.getSelectedOptionValues(currentAssetTypes);

Liferay.Util.postForm(form, {data: data});
});
Expand Down
Expand Up @@ -137,7 +137,7 @@

if (currentLanguageIdsElement) {
Liferay.Util.setFormValues(form, {
<%= PropsKeys.LOCALES %>: Liferay.Util.listSelect(
<%= PropsKeys.LOCALES %>: Liferay.Util.getSelectedOptionValues(
currentLanguageIdsElement
),
});
Expand Down
Expand Up @@ -87,7 +87,9 @@
if (currentLanguageIdsInput) {
Liferay.Util.postForm(form, {
data: {
languageIds: Liferay.Util.listSelect(currentLanguageIdsInput),
languageIds: Liferay.Util.getSelectedOptionValues(
currentLanguageIdsInput
),
},
});
}
Expand Down
Expand Up @@ -97,11 +97,11 @@ rightList = ListUtil.sort(rightList, new KeyValuePairComparator(false, true));
);

Liferay.after('inputmoveboxes:moveItem', (event) => {
socialBookmarksTypes.value = Util.listSelect(currentTypes);
socialBookmarksTypes.value = Util.getSelectedOptionValues(currentTypes);
});

Liferay.after('inputmoveboxes:orderItem', (event) => {
socialBookmarksTypes.value = Util.listSelect(currentTypes);
socialBookmarksTypes.value = Util.getSelectedOptionValues(currentTypes);
});
})();
</script>
Expand Up @@ -141,8 +141,12 @@
if (availableVisibleNodes && currentVisibleNodes) {
Liferay.Util.postForm(form, {
data: {
hiddenNodes: Liferay.Util.listSelect(availableVisibleNodes),
visibleNodes: Liferay.Util.listSelect(currentVisibleNodes),
hiddenNodes: Liferay.Util.getSelectedOptionValues(
availableVisibleNodes
),
visibleNodes: Liferay.Util.getSelectedOptionValues(
currentVisibleNodes
),
},
});
}
Expand Down