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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-115862 When publishing the default language count the input as translated #1346

Closed
Closed
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 @@ -77,6 +77,8 @@ class JournalPortlet extends PortletBase {
this._onLocaleChange.bind(this)
);

this._selectedLanguageId = this.defaultLanguageId;

this._setupSidebar();
}

Expand All @@ -96,6 +98,27 @@ class JournalPortlet extends PortletBase {
this._localeChangedHandler.detach();
}

/**
* Clean the input if the language is not considered translated when
* submitting the form
* @param {string} name of the input
*/
_cleanInputIfNeeded(name) {
const inputComponent = Liferay.component(this.ns(name));
const translatedLanguages = inputComponent.get('translatedLanguages');

if (
!translatedLanguages.has(this._selectedLanguageId) &&
this._selectedLanguageId !== this.defaultLanguageId
) {
inputComponent.updateInput('');

const form = Liferay.Form.get(this.ns('fm1'));

form.removeRule(this.ns(name), 'required');
}
}

/**
* Query an input by its name
* @param {string} name
Expand Down Expand Up @@ -135,6 +158,8 @@ class JournalPortlet extends PortletBase {
_onLocaleChange(event) {
const selectedLanguageId = event.item.getAttribute('data-value');

this._selectedLanguageId = selectedLanguageId;

if (selectedLanguageId) {
this._updateLocalizableInput(
'descriptionMapAsXML',
Expand Down Expand Up @@ -211,6 +236,9 @@ class JournalPortlet extends PortletBase {

const form = this._getInputByName(this.ns('fm1'));

this._cleanInputIfNeeded('titleMapAsXML');
this._cleanInputIfNeeded('descriptionMapAsXML');

submitForm(form);
}

Expand Down Expand Up @@ -322,6 +350,7 @@ class JournalPortlet extends PortletBase {
}

JournalPortlet.STATE = {
_selectedLanguageId: Config.internal().string(),
defaultLanguageId: Config.string(),
};

Expand Down