Skip to content

Commit

Permalink
Merge pull request #2744 from SCADA-LTS/fix/#2607_Fixed_hide_unnamed_…
Browse files Browse the repository at this point in the history
…watchlist_in_form_profile_user_for_other_lang_2

- Rebranching issue #2607 fixed hide unnamed watchlist in form profil…
  • Loading branch information
Limraj authored Oct 30, 2023
2 parents 41554fe + 0ec5348 commit a0671e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
15 changes: 10 additions & 5 deletions WebContent/WEB-INF/jsp/usersProfiles.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
var watchlists;
var views;
var adminUser;
var keyTranslations;
function init() {
UsersProfilesDwr.getInitData(function(data) {
Expand Down Expand Up @@ -79,9 +80,10 @@
var wlhtml = "";
watchlists = data.watchlists;
keyTranslations = data.keyTranslations;
if (watchlists != null){
for (i=0; i<watchlists.length; i++) {
if(isUnnamedWatchList(watchlists[i].name))
if(isUnnamedWatchList(keyTranslations, watchlists[i].name))
continue;
id = watchlists[i].id;
wlhtml += '<label for="wllist'+ id +'"> '+ watchlists[i].name +'</label><br/>';
Expand Down Expand Up @@ -172,7 +174,7 @@
if(watchlists != null) {
for (i=0; i<watchlists.length; i++) {
if(isUnnamedWatchList(watchlists[i].name))
if(isUnnamedWatchList(keyTranslations, watchlists[i].name))
continue;
$set("wl"+ watchlists[i].id, "0");
}
Expand Down Expand Up @@ -222,7 +224,7 @@
var wlval;
if (watchlists != null ){
for (i=0; i<watchlists.length; i++) {
if(isUnnamedWatchList(watchlists[i].name))
if(isUnnamedWatchList(keyTranslations, watchlists[i].name))
continue;
wlval = $get("wl"+ watchlists[i].id);
Expand Down Expand Up @@ -318,8 +320,11 @@
}
}
function isUnnamedWatchList(wl) {
return wl == '<fmt:message key="common.newName"/>' // skip unnamed lists
function isUnnamedWatchList(keyTranslations, wl) {
if (keyTranslations) {
return keyTranslations.includes(wl); // skip unnamed lists
}
return false;
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions src/br/org/scadabr/web/dwr/UsersProfilesDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.servlet.http.HttpServletRequest;

import com.serotonin.mango.vo.User;
import com.serotonin.mango.web.mvc.controller.ScadaLocaleUtils;
import org.directwebremoting.WebContextFactory;

import br.org.scadabr.api.exception.DAOException;
Expand Down Expand Up @@ -84,6 +85,7 @@ public Map<String, Object> getInitData() {
.map(toView())
.collect(Collectors.toList());
initData.put("views", views);
initData.put("keyTranslations", ScadaLocaleUtils.getTranslationsForKey("common.newName"));

return initData;
}
Expand Down
16 changes: 16 additions & 0 deletions src/com/serotonin/mango/web/mvc/controller/ScadaLocaleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,20 @@ private static HttpServletRequest getRequestFromWebContext() {
return webContext.getHttpServletRequest();
return null;
}

public static List<Locale> getLocales() {
List<Locale> languages = new ArrayList<>();
for (KeyValuePair key : getLanguages())
languages.add(Locale.forLanguageTag(key.getKey()));
return languages;
}

public static List<String> getTranslationsForKey(String key){
List<Locale> locales = getLocales();
List<String> keyTranslations = new ArrayList<>();
for (Locale locale : locales) {
keyTranslations.add(LocalizableMessage.getMessage(getResourceBundleByLocale(locale),key));
}
return keyTranslations;
}
}

0 comments on commit a0671e5

Please sign in to comment.