User notifications can be generated from any component through Finsemble's Notification API.
You add notifications from within code, essentially calling on the Notification API to deliver a notification. Delivered notifications are displayed through an HTML template that you can customize. A system-wide default template can be installed. You can also specify which template to use when you send the notification. Notifications can be classified by topic.
Notifications are called from FSBL.UserNotification.alert.
In the following example, the message "My what a fine notification!" is sent only once. "my-tracking-identifier"
is
used to make sure the message is unique. In this example, the default template is overridden with the URL parameter.
FSBL.UserNotification.alert("dev", "ONCE-SINCE-STARTUP", "my-tracking-identifier", "My what a fine notification!", {
url: "/mytemplate.html",
});
The default notification template is located in src/components/notification/notification.html. If this is missing, a
very basic built-in template is used. You can change the location of the default template in the manifest with the
notificationURL
parameter:
"finsemble": {
"applicationRoot": "https://localhost:3375",
"moduleRoot": "https://localhost:3375/finsemble/",
"notificationURL": "https://localhost:3375/components/notification/notification.html",
...
When sending a string as your notification message, the template will automatically drop the contents of the string into
the .notification-description
selector. You can optionally send an object as your notification containing multiple
fields to replace in the template. For instance, if you wanted to set both title and description you would use the
following:
FSBL.UserNotification.alert("dev", "ONCE-SINCE-STARTUP", "my-tracking-identifier", {
description: "My what a fine notification!",
title: "Extra! Extra!",
});
The .notification-description
tag will be changed to "My what a fine notification!" and the .notification-title
tag
will be changed to "Extra! Extra!".
For advanced information about notifications, check out the Notification API documentation.