Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java @ 212:e3ea3c74b7f5
Fixed the function to toggle the language and added a warning dialog that informs the user about the creation of a new session.
flys-client/trunk@1652 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 07 Apr 2011 10:33:48 +0000 |
parents | b92281182c6b |
children | 0ba7c43e7b62 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java Tue Apr 05 08:13:48 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/MainMenu.java Thu Apr 07 10:33:48 2011 +0000 @@ -5,6 +5,8 @@ import com.google.gwt.user.client.Window; import com.smartgwt.client.types.Alignment; +import com.smartgwt.client.util.BooleanCallback; +import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; @@ -89,13 +91,20 @@ language.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { - LocaleInfo info = LocaleInfo.getCurrentLocale(); - String currentLocale = info.getLocaleName(); - String newLocale = currentLocale.equals("de") ? "en" : "de"; + LocaleInfo info = LocaleInfo.getCurrentLocale(); + final String currentLocale = info.getLocaleName(); + final String newLocale = currentLocale.equals("de") + ? "en" + : "de"; - // XXX Maybe we should inform the user about fact, that we will - // loose the work of the current session. - switchLanguage(currentLocale, newLocale); + SC.confirm(messages.warning(), messages.warning_language(), + new BooleanCallback() { + public void execute(Boolean value) { + if (value) { + switchLanguage(currentLocale, newLocale); + } + } + }); } }); @@ -220,27 +229,28 @@ protected void switchLanguage(String currentLocale, String newLocale) { String newLocation = Window.Location.getHref(); + String oldLocation = newLocation; + + if (newLocation.endsWith("/")) { + newLocation = newLocation.substring(0, newLocation.length()-1); + } + + String replace = null; + String replaceWith = null; + if (newLocation.indexOf("&locale=") >= 0) { - String replace = currentLocale.equals("de") - ? "&locale=de" - : "&locale=en"; - - String replaceWith = newLocale.equals("de") + replace = currentLocale.equals("de") ? "&locale=de" : "&locale=en"; - newLocation = newLocation.replace(replace, replaceWith); + replaceWith = "&locale=" + newLocale; } else if (newLocation.indexOf("?locale=") >= 0) { - String replace = currentLocale.equals("de") + replace = currentLocale.equals("de") ? "?locale=de" : "?locale=en"; - String replaceWith = currentLocale.equals("de") - ? "?locale=de" - : "?locale=en"; - - newLocation = newLocation.replace(replace, replaceWith); + replaceWith = "?locale=" + newLocale; } else { newLocation += newLocation.indexOf("?") >= 0 @@ -248,6 +258,10 @@ : "?locale=" + newLocale; } + if (replace != null && replaceWith != null) { + newLocation = newLocation.replace(replace, replaceWith); + } + Window.open(newLocation, "_self", ""); } }