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

Mark selected language as active in dropdown #35588

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1371,8 +1371,10 @@ hqDefine("cloudcare/js/formplayer/menus/views", [
this.languageOptionsEnabled = options.languageOptionsEnabled;
},
templateContext: function () {
const currentLang = UsersModels.getCurrentUser().displayOptions.language;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be better to put this in MenuDropdownView.childViewOptions so UsersModels.getCurrentUser() only need the be called once. And maybe only if languageOptionsEnabled is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCurrentUser is cached actually, so it shouldn't be a problem to call it more than once:

var userInstance;
self.getCurrentUser = function () {
if (!userInstance) {
userInstance = new self.CurrentUser();
}
return userInstance;
};

return {
languageOptionsEnabled: this.languageOptionsEnabled,
isLangSelected: this.options.model.get('lang_code') === currentLang,
};
},
onKeyActionChangeLang: function (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@

<script type="text/template" id="language-option-template">
<% if (languageOptionsEnabled) { %>
<a tabindex="0" class="lang dropdown-item" id="<%- lang_code %>"><%- lang_label %></a>
<a
tabindex="0"
class="lang dropdown-item <% if (isLangSelected) { %>active<% } %>"
id="<%- lang_code %>"
>
<%- lang_label %>
</a>
<% } %>
</script>