diff options
author | Artur Signell <artur@vaadin.com> | 2015-06-25 00:06:17 +0300 |
---|---|---|
committer | Denis Anisimov <denis@vaadin.com> | 2015-06-26 16:15:08 +0000 |
commit | b541e8e4e9346971f33025135619120166aac425 (patch) | |
tree | 4672b921c4ce1dd53fcf8d50c90115b23bf9e9da /client | |
parent | 579d08c4c810e7b2c11e810648fb95622243e0c4 (diff) | |
download | vaadin-framework-b541e8e4e9346971f33025135619120166aac425.tar.gz vaadin-framework-b541e8e4e9346971f33025135619120166aac425.zip |
Fix incorrect system notifications with details styling (#18340)
Change-Id: Ia0d36147eb4ed9f170123771ac2674df584e6a4b
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/ApplicationConnection.java | 83 | ||||
-rw-r--r-- | client/src/com/vaadin/client/ui/VNotification.java | 82 |
2 files changed, 91 insertions, 74 deletions
diff --git a/client/src/com/vaadin/client/ApplicationConnection.java b/client/src/com/vaadin/client/ApplicationConnection.java index 90fc9b2668..628559dd2a 100644 --- a/client/src/com/vaadin/client/ApplicationConnection.java +++ b/client/src/com/vaadin/client/ApplicationConnection.java @@ -90,7 +90,6 @@ import com.vaadin.client.ui.Icon; import com.vaadin.client.ui.ImageIcon; import com.vaadin.client.ui.VContextMenu; import com.vaadin.client.ui.VNotification; -import com.vaadin.client.ui.VNotification.HideEvent; import com.vaadin.client.ui.VOverlay; import com.vaadin.client.ui.dd.VDragAndDropManager; import com.vaadin.client.ui.ui.UIConnector; @@ -1234,7 +1233,7 @@ public class ApplicationConnection implements HasHandlers { * Shows the communication error notification. * * @param details - * Optional details for debugging. + * Optional details. * @param statusCode * The status code returned for the request * @@ -1248,7 +1247,7 @@ public class ApplicationConnection implements HasHandlers { * Shows the authentication error notification. * * @param details - * Optional details for debugging. + * Optional details. */ protected void showAuthenticationError(String details) { getLogger().severe("Authentication error: " + details); @@ -1259,7 +1258,7 @@ public class ApplicationConnection implements HasHandlers { * Shows the session expiration notification. * * @param details - * Optional details for debugging. + * Optional details. */ public void showSessionExpiredError(String details) { getLogger().severe("Session expired: " + details); @@ -1270,59 +1269,13 @@ public class ApplicationConnection implements HasHandlers { * Shows an error notification. * * @param details - * Optional details for debugging. + * Optional details. * @param message * An ErrorMessage describing the error. */ protected void showError(String details, ErrorMessage message) { - showError(details, message.getCaption(), message.getMessage(), - message.getUrl()); - } - - /** - * Shows the error notification. - * - * @param details - * Optional details for debugging. - */ - private void showError(String details, String caption, String message, - String url) { - - StringBuilder html = new StringBuilder(); - if (caption != null) { - html.append("<h1 class='"); - html.append(VNotification.getDependentStyle(this, - VNotification.CAPTION)); - html.append("'>"); - html.append(caption); - html.append("</h1>"); - } - if (message != null) { - html.append("<p class='"); - html.append(VNotification.getDependentStyle(this, - VNotification.DESCRIPTION)); - html.append("'>"); - html.append(message); - html.append("</p>"); - } - - if (html.length() > 0) { - - // Add error description - if (details != null) { - html.append("<p><i style=\"font-size:0.7em\">"); - html.append(details); - html.append("</i></p>"); - } - - VNotification n = VNotification.createNotification(1000 * 60 * 45, - uIConnector.getWidget()); - n.addEventListener(new NotificationRedirect(url)); - n.show(html.toString(), VNotification.CENTERED_TOP, - VNotification.STYLE_SYSTEM); - } else { - redirect(url); - } + VNotification.showError(this, message.getCaption(), + message.getMessage(), details, message.getUrl()); } protected void startRequest() { @@ -1769,9 +1722,10 @@ public class ApplicationConnection implements HasHandlers { if (meta.containsKey("appError")) { ValueMap error = meta.getValueMap("appError"); - showError(error.getString("details"), + VNotification.showError(ApplicationConnection.this, error.getString("caption"), error.getString("message"), + error.getString("details"), error.getString("url")); setApplicationRunning(false); @@ -2747,7 +2701,7 @@ public class ApplicationConnection implements HasHandlers { } // Redirect browser, null reloads current page - private static native void redirect(String url) + public static native void redirect(String url) /*-{ if (url) { $wnd.location = url; @@ -3366,25 +3320,6 @@ public class ApplicationConnection implements HasHandlers { + getUIConnector().getActiveTheme(); } - /** - * Listens for Notification hide event, and redirects. Used for system - * messages, such as session expired. - * - */ - private class NotificationRedirect implements VNotification.EventListener { - String url; - - NotificationRedirect(String url) { - this.url = url; - } - - @Override - public void notificationHidden(HideEvent event) { - redirect(url); - } - - } - /* Extended title handling */ private final VTooltip tooltip; diff --git a/client/src/com/vaadin/client/ui/VNotification.java b/client/src/com/vaadin/client/ui/VNotification.java index 4f0c2eb625..2f68976471 100644 --- a/client/src/com/vaadin/client/ui/VNotification.java +++ b/client/src/com/vaadin/client/ui/VNotification.java @@ -65,6 +65,7 @@ public class VNotification extends VOverlay { public static final String CAPTION = "caption"; public static final String DESCRIPTION = "description"; + public static final String DETAILS = "details"; /** * Position that is only accessible for assistive devices, invisible for @@ -597,4 +598,85 @@ public class VNotification extends VOverlay { DOM.addEventPreview(notification); } } + + /** + * Shows an error notification and redirects the user to the given URL when + * she clicks on the notification. + * + * If both message and caption are null, redirects the user to the url + * immediately + * + * @param connection + * A reference to the ApplicationConnection + * @param caption + * The caption for the error or null to exclude the caption + * @param message + * The message for the error or null to exclude the message + * @param details + * A details message or null to exclude the details + * @param url + * A url to redirect to after the user clicks the error + * notification + */ + public static void showError(ApplicationConnection connection, + String caption, String message, String details, String url) { + + StringBuilder html = new StringBuilder(); + if (caption != null) { + html.append("<h1 class='"); + html.append(getDependentStyle(connection, CAPTION)); + html.append("'>"); + html.append(caption); + html.append("</h1>"); + } + if (message != null) { + html.append("<p class='"); + html.append(getDependentStyle(connection, DESCRIPTION)); + html.append("'>"); + html.append(message); + html.append("</p>"); + } + + if (html.length() > 0) { + + // Add error description + if (details != null) { + html.append("<p class='"); + html.append(getDependentStyle(connection, DETAILS)); + html.append("'>"); + html.append("<i style=\"font-size:0.7em\">"); + html.append(details); + html.append("</i></p>"); + } + + VNotification n = VNotification.createNotification(1000 * 60 * 45, + connection.getUIConnector().getWidget()); + n.addEventListener(new NotificationRedirect(url)); + n.show(html.toString(), VNotification.CENTERED_TOP, + VNotification.STYLE_SYSTEM); + } else { + ApplicationConnection.redirect(url); + } + } + + /** + * Listens for Notification hide event, and redirects. Used for system + * messages, such as session expired. + * + */ + private static class NotificationRedirect implements + VNotification.EventListener { + String url; + + NotificationRedirect(String url) { + this.url = url; + } + + @Override + public void notificationHidden(HideEvent event) { + ApplicationConnection.redirect(url); + } + + } + } |