mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-29 15:27:14 +00:00
Merge branches 'design2015' and 'design2015' of ssh://sapsailing.com/home/trac/git into design2015
# By Steffen Schaefer # Via Steffen Schaefer * 'design2015' of ssh://sapsailing.com/home/trac/git: Bug 2795: Fix for IE Bug 2795: Added language chooser as select box if there are > 2 locales available # By Steffen Schaefer # Via Steffen Schaefer * 'design2015' of ssh://sapsailing.com/home/trac/git: Bug 2795: Fix for IE Bug 2795: Added language chooser as select box if there are > 2 locales available
This commit is contained in:
commit
e3ca5d50a4
2 files changed
+100
-23
No files matched your search
+72
-23
@@ -1,14 +1,17 @@
|
||||
package com.sap.sailing.gwt.home.client.shared.footer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.dom.client.DivElement;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.logical.shared.ValueChangeEvent;
|
||||
import com.google.gwt.http.client.UrlBuilder;
|
||||
import com.google.gwt.i18n.client.LocaleInfo;
|
||||
import com.google.gwt.text.shared.Renderer;
|
||||
import com.google.gwt.uibinder.client.UiBinder;
|
||||
import com.google.gwt.uibinder.client.UiField;
|
||||
import com.google.gwt.uibinder.client.UiHandler;
|
||||
@@ -16,11 +19,13 @@ import com.google.gwt.user.client.Window;
|
||||
import com.google.gwt.user.client.Window.Location;
|
||||
import com.google.gwt.user.client.ui.Anchor;
|
||||
import com.google.gwt.user.client.ui.Composite;
|
||||
import com.google.gwt.user.client.ui.ValueListBox;
|
||||
import com.google.gwt.user.client.ui.Widget;
|
||||
import com.sap.sailing.gwt.home.client.app.HomePlacesNavigator;
|
||||
import com.sap.sailing.gwt.home.client.app.PlaceNavigation;
|
||||
import com.sap.sailing.gwt.home.client.place.whatsnew.WhatsNewPlace;
|
||||
import com.sap.sailing.gwt.home.client.place.whatsnew.WhatsNewPlace.WhatsNewNavigationTabs;
|
||||
import com.sap.sse.common.Util.Pair;
|
||||
|
||||
public class Footer extends Composite {
|
||||
private static FooterPanelUiBinder uiBinder = GWT.create(FooterPanelUiBinder.class);
|
||||
@@ -30,17 +35,32 @@ public class Footer extends Composite {
|
||||
|
||||
@UiField Anchor changeLanguageLink;
|
||||
@UiField DivElement languageSelectionDiv;
|
||||
@UiField(provided = true) ValueListBox<Pair<String, String>> changeLanguageList = new ValueListBox<Pair<String,String>>(new Renderer<Pair<String, String>>() {
|
||||
@Override
|
||||
public String render(Pair<String, String> object) {
|
||||
if(object == null) {
|
||||
return "";
|
||||
}
|
||||
if(object.getB() != null) {
|
||||
return object.getB();
|
||||
}
|
||||
return object.getA();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Pair<String, String> object, Appendable appendable) throws IOException {
|
||||
appendable.append(render(object));
|
||||
}
|
||||
});
|
||||
|
||||
private String otherLanguage;
|
||||
private final LocaleInfo currentLocale = LocaleInfo.getCurrentLocale();
|
||||
|
||||
private final Map<String, String> localeAndLanguages;
|
||||
|
||||
@UiField(provided = true)
|
||||
final PlaceNavigation<WhatsNewPlace> releaseNotesNavigation;
|
||||
|
||||
public Footer(final HomePlacesNavigator navigator) {
|
||||
localeAndLanguages = new HashMap<String, String>();
|
||||
localeAndLanguages.put("en", "English");
|
||||
localeAndLanguages.put("de", "Deutsch");
|
||||
|
||||
FooterResources.INSTANCE.css().ensureInjected();
|
||||
releaseNotesNavigation = navigator.getWhatsNewNavigation(WhatsNewNavigationTabs.SailingAnalytics);
|
||||
|
||||
@@ -51,26 +71,55 @@ public class Footer extends Composite {
|
||||
|
||||
@UiHandler("changeLanguageLink")
|
||||
public void changeLanguage(ClickEvent e) {
|
||||
String selectedLanguage = changeLanguageLink.getText();
|
||||
String selectedLocale = null;
|
||||
for (Entry<String, String> entry: localeAndLanguages.entrySet()) {
|
||||
if (entry.getValue().equals(selectedLanguage)) {
|
||||
selectedLocale = entry.getKey();
|
||||
}
|
||||
if(otherLanguage != null) {
|
||||
UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", otherLanguage);
|
||||
Window.Location.replace(builder.buildString());
|
||||
}
|
||||
if(selectedLocale != null) {
|
||||
UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", selectedLocale);
|
||||
Window.Location.replace(builder.buildString());
|
||||
}
|
||||
|
||||
@UiHandler("changeLanguageList")
|
||||
void onListSelection(ValueChangeEvent<Pair<String, String>> event) {
|
||||
String selectedLocaleName = event.getValue().getA();
|
||||
if(!currentLocale.getLocaleName().equals(selectedLocaleName)) {
|
||||
UrlBuilder builder = Location.createUrlBuilder().setParameter("locale", selectedLocaleName);
|
||||
Window.Location.replace(builder.buildString());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
LocaleInfo currentLocale = LocaleInfo.getCurrentLocale();
|
||||
HashMap<String, String> languagesToSelectFrom = new HashMap<String, String>(localeAndLanguages);
|
||||
languagesToSelectFrom.remove(currentLocale.getLocaleName());
|
||||
|
||||
if(languagesToSelectFrom.size() == 1) {
|
||||
changeLanguageLink.setText(languagesToSelectFrom.values().iterator().next());
|
||||
Set<String> availableLocales = new HashSet<String>(Arrays.asList(LocaleInfo.getAvailableLocaleNames()));
|
||||
availableLocales.remove("default");
|
||||
|
||||
if(availableLocales.size() <= 1) {
|
||||
// only current language (or removed default) available
|
||||
changeLanguageLink.removeFromParent();
|
||||
changeLanguageList.removeFromParent();
|
||||
languageSelectionDiv.removeFromParent();
|
||||
return;
|
||||
}
|
||||
if(availableLocales.size() == 2) {
|
||||
changeLanguageList.removeFromParent();
|
||||
// current language + one we can switch to
|
||||
for(String localeName : availableLocales) {
|
||||
if(!currentLocale.getLocaleName().equals(localeName)) {
|
||||
otherLanguage = localeName;
|
||||
changeLanguageLink.setText(LocaleInfo.getLocaleNativeDisplayName(otherLanguage));
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
changeLanguageLink.removeFromParent();
|
||||
Set<Pair<String, String>> values = new HashSet<>();
|
||||
Pair<String, String> selectedValue = null;
|
||||
for(String localeName : availableLocales) {
|
||||
Pair<String, String> value = new Pair<String, String>(localeName, LocaleInfo.getLocaleNativeDisplayName(localeName));
|
||||
values.add(value);
|
||||
if(currentLocale.getLocaleName().equals(localeName)) {
|
||||
selectedValue = value;
|
||||
}
|
||||
}
|
||||
changeLanguageList.setValue(selectedValue);
|
||||
changeLanguageList.setAcceptableValues(values);
|
||||
}
|
||||
}
|
||||
+28
@@ -5,6 +5,33 @@
|
||||
<ui:with field="res" type="com.sap.sailing.gwt.common.client.SharedResources" />
|
||||
<ui:with field="local_res" type="com.sap.sailing.gwt.home.client.shared.footer.FooterResources" />
|
||||
<ui:with field="releaseNotesNavigation" type="com.sap.sailing.gwt.home.client.app.PlaceNavigation" />
|
||||
<ui:style gss="true">
|
||||
.languageSelect::-ms-expand {
|
||||
display: none;
|
||||
}
|
||||
.languageSelect {
|
||||
-webkit-appearance: none;
|
||||
-moz-appearance: none;
|
||||
-ms-appearance: none;
|
||||
appearance: none;
|
||||
|
||||
margin-top: 25px;
|
||||
color: #efaa00;
|
||||
line-height: 1.5em;
|
||||
height: 1.5em;
|
||||
display: inline-block;
|
||||
border: transparent;
|
||||
cursor: pointer;
|
||||
padding-right: 1.2em;
|
||||
background: #333;
|
||||
cursor: pointer;
|
||||
|
||||
background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZlcnNpb249JzEuMScgaGVpZ2h0PScxOHB4JyB3aWR0aD0nMTZweCc+PHRleHQgeD0nMCcgeT0nMTUnIGZpbGw9JyNlZmFhMDAnIGZvbnQtc2l6ZT0nMTYnPiYjOTY2MDs8L3RleHQ+PC9zdmc+");
|
||||
background-position: right center;
|
||||
background-repeat: no-repeat;
|
||||
|
||||
}
|
||||
</ui:style>
|
||||
<g:HTMLPanel tag="footer" addStyleNames="{local_res.css.sitefooter}">
|
||||
<!-- Website footer-->
|
||||
<div class="{res.mediaCss.grid}">
|
||||
@@ -33,6 +60,7 @@
|
||||
<div ui:field="languageSelectionDiv" class="{res.mediaCss.small12} {res.mediaCss.medium3} {res.mediaCss.columns} {local_res.css.sitefooter_language}">
|
||||
<span><ui:text from='{i18n.footerLanguage}' />:</span>
|
||||
<g:Anchor ui:field="changeLanguageLink" styleName="{local_res.css.sitefooter_language_link}" />
|
||||
<g:ValueListBox addStyleNames="{style.languageSelect}" ui:field="changeLanguageList" />
|
||||
</div>
|
||||
</div>
|
||||
</g:HTMLPanel>
|
||||
|
||||
Reference in new issue
Block a user