Rich content in desktop notifications [message #1806461] |
Thu, 09 May 2019 08:06  |
Eclipse User |
|
|
|
Hi,
Is it possible to include richer content (eg icons, buttons, html content) in the desktop notification - triggered by ClientSession.get().getDesktop().addNotification() - such as in a popup?
In the example from the page https://scout.bsi-software.com/widgets/?dl=widget-desktop I can see that you can include only simple text in the notification. But when, for example, I click "View source on GitHub" there, it displays notification "Opening a new window automatically was blocked by the browser" with an additional "Open manually" button. This would indicate that there is some method to add additional elements to the notification.
|
|
|
Re: Rich content in desktop notifications [message #1806557 is a reply to message #1806461] |
Fri, 10 May 2019 06:59   |
Eclipse User |
|
|
|
Hi Krzysztof
Yes, when you take a look at the JavaScript source-code in PopupBlockerHandler#showNotification, you'll see that a "variant" of DesktopNotification.js is created instead of the regular Notification:
notification = scout.create('DesktopNotification:PopupBlocker', {
parent: desktop,
linkUrl: linkUrl,
preserveOpener: this.preserveOpener
});
This instantiates the class PopupBlockerDesktopNotification.js, where the _render function creates the HTML you mentioned in your post.
In a Scout Java application you could use a @ModelVariant to mark a specific Notification class, like this:
@ModelVariant("Special")
class SpecialDesktopNotification extends DesktopNotification {
public SpecialDesktopNotification(IStatus status, long duration, boolean closable) {
super(status, duration, closable);
}
}
And add the notification like this:
DesktopNotification notification = new SpecialDesktopNotification(status, duration, closeable);
ClientSession.get().getDesktop().addNotification(notification);
In your *.ui.html project you need to add a JavaScript class "SpecialDesktopNotification.js" that extends DesktopNotification.js and register it in your module.js. Scout finds and instantiates this class by name-magic. In that class you can override the _render or _renderMessage function and implement whatever you need. A very simple approach could override _renderMessage and simply add the message from the status object as HTML, without encoding HTML as DesktopNotification.js does. Example:
scout.SpecialDesktopNotification.prototype._renderMessage = function() {
var html = scout.nvl(this.status.message, '');
this.$messageText.html(html);
};
André
|
|
|
|
|
|
Re: Rich content in desktop notifications [message #1835339 is a reply to message #1835257] |
Tue, 01 December 2020 02:58  |
Eclipse User |
|
|
|
Hi Krzysztof
You can pass a special "app link handler" to the constructor of your DesktopNotification instance. Something like this:
IStatus status = new Status(HTML.span("Click me").appLink("myRef").toHtml(), IStatus.INFO);
IDesktopNotification notification = new DesktopNotification(status, IDesktopNotification.INFINITE_DURATION, true, true, ref -> MessageBoxes.createOk().withBody("You clicked this link: " + ref).show());
desktop.addNotification(notification);
Regards,
Beat
|
|
|
Powered by
FUDForum. Page generated in 0.03197 seconds