diff options
author | Artur Signell <artur@vaadin.com> | 2014-12-19 01:50:32 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-01-02 16:40:29 +0200 |
commit | 26832b6947266ce5cffd92558c23e6556278038d (patch) | |
tree | 6e550fb5dc1510c22b5d76e097970a0f97e4c31d /client/src | |
parent | fea60eaea2c791766be9f17ff2900739b32bf576 (diff) | |
download | vaadin-framework-26832b6947266ce5cffd92558c23e6556278038d.tar.gz vaadin-framework-26832b6947266ce5cffd92558c23e6556278038d.zip |
Option for rendering Calendar event captions as HTML (#9030)
Change-Id: Ib7f6e67c242449e58a10359c596489fea2f679f6
Diffstat (limited to 'client/src')
5 files changed, 59 insertions, 8 deletions
diff --git a/client/src/com/vaadin/client/ui/VCalendar.java b/client/src/com/vaadin/client/ui/VCalendar.java index c59a78108c..08d4351931 100644 --- a/client/src/com/vaadin/client/ui/VCalendar.java +++ b/client/src/com/vaadin/client/ui/VCalendar.java @@ -1342,6 +1342,7 @@ public class VCalendar extends Composite implements VHasDropHandler { private MouseEventListener mouseEventListener; private boolean forwardNavigationEnabled = true; private boolean backwardNavigationEnabled = true; + private boolean eventCaptionAsHtml = false; /** * Get the listener that listen to mouse events @@ -1467,4 +1468,33 @@ public class VCalendar extends Composite implements VHasDropHandler { public void setDropHandler(CalendarDropHandler dropHandler) { this.dropHandler = dropHandler; } + + /** + * Sets whether the event captions are rendered as HTML. + * <p> + * If set to true, the captions are rendered in the browser as HTML and the + * developer is responsible for ensuring no harmful HTML is used. If set to + * false, the caption is rendered in the browser as plain text. + * <p> + * The default is false, i.e. to render that caption as plain text. + * + * @param captionAsHtml + * true if the captions are rendered as HTML, false if rendered + * as plain text + */ + public void setEventCaptionAsHtml(boolean eventCaptionAsHtml) { + this.eventCaptionAsHtml = eventCaptionAsHtml; + } + + /** + * Checks whether event captions are rendered as HTML + * <p> + * The default is false, i.e. to render that caption as plain text. + * + * @return true if the captions are rendered as HTML, false if rendered as + * plain text + */ + public boolean isEventCaptionAsHtml() { + return eventCaptionAsHtml; + } } diff --git a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java index 8f5e9d9a59..8c92ef1233 100644 --- a/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java +++ b/client/src/com/vaadin/client/ui/calendar/CalendarConnector.java @@ -345,6 +345,8 @@ public class CalendarConnector extends AbstractComponentConnector implements widget.setEventMoveAllowed(hasEventListener(CalendarEventId.EVENTMOVE)); widget.setEventResizeAllowed(hasEventListener(CalendarEventId.EVENTRESIZE)); + widget.setEventCaptionAsHtml(state.eventCaptionAsHtml); + List<CalendarState.Day> days = state.days; List<CalendarState.Event> events = state.events; diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java index 3b168b636c..8b08e9bc7a 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCellDayEvent.java @@ -184,14 +184,20 @@ public class DateCellDayEvent extends FocusableHTML implements */ private void updateCaptions(boolean bigMode) { String innerHtml; - String escapedCaption = Util.escapeHTML(calendarEvent.getCaption()); String timeAsText = calendarEvent.getTimeAsText(); + String htmlOrText; + + if (dateCell.weekgrid.getCalendar().isEventCaptionAsHtml()) { + htmlOrText = calendarEvent.getCaption(); + } else { + htmlOrText = Util.escapeHTML(calendarEvent.getCaption()); + } + if (bigMode) { - innerHtml = "<span>" + timeAsText + "</span><br />" - + escapedCaption; + innerHtml = "<span>" + timeAsText + "</span><br />" + htmlOrText; } else { innerHtml = "<span>" + timeAsText + "<span>:</span></span> " - + escapedCaption; + + htmlOrText; } caption.setInnerHTML(innerHtml); eventContent.setInnerHTML(""); diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/MonthEventLabel.java b/client/src/com/vaadin/client/ui/calendar/schedule/MonthEventLabel.java index 6fc2e430cd..31e600c8f9 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/MonthEventLabel.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/MonthEventLabel.java @@ -20,6 +20,7 @@ import java.util.Date; import com.google.gwt.event.dom.client.ContextMenuEvent; import com.google.gwt.event.dom.client.ContextMenuHandler; import com.google.gwt.user.client.ui.HTML; +import com.vaadin.client.Util; import com.vaadin.client.ui.VCalendar; /** @@ -75,7 +76,8 @@ public class MonthEventLabel extends HTML implements HasTooltipKey { * Set the caption of the event label * * @param caption - * The caption string, can be HTML + * The caption string, can be HTML if + * {@link VCalendar#isEventCaptionAsHtml()} is true */ public void setCaption(String caption) { this.caption = caption; @@ -87,13 +89,20 @@ public class MonthEventLabel extends HTML implements HasTooltipKey { */ private void renderCaption() { StringBuilder html = new StringBuilder(); + String textOrHtml; + if (calendar.isEventCaptionAsHtml()) { + textOrHtml = caption; + } else { + textOrHtml = Util.escapeHTML(caption); + } + if (caption != null && time != null) { html.append("<span class=\"" + STYLENAME + "-time\">"); html.append(calendar.getTimeFormat().format(time)); html.append("</span> "); - html.append(caption); + html.append(textOrHtml); } else if (caption != null) { - html.append(caption); + html.append(textOrHtml); } else if (time != null) { html.append("<span class=\"" + STYLENAME + "-time\">"); html.append(calendar.getTimeFormat().format(time)); diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/WeeklyLongEvents.java b/client/src/com/vaadin/client/ui/calendar/schedule/WeeklyLongEvents.java index bd833e06a0..9488c8835a 100644 --- a/client/src/com/vaadin/client/ui/calendar/schedule/WeeklyLongEvents.java +++ b/client/src/com/vaadin/client/ui/calendar/schedule/WeeklyLongEvents.java @@ -102,7 +102,11 @@ public class WeeklyLongEvents extends HorizontalPanel implements HasTooltipKey { eventLabel.addStyleDependentName(extraStyle + "-all-day"); } if (!started) { - eventLabel.setText(calendarEvent.getCaption()); + if (calendar.isEventCaptionAsHtml()) { + eventLabel.setHTML(calendarEvent.getCaption()); + } else { + eventLabel.setText(calendarEvent.getCaption()); + } started = true; } } |