From 217bb517c51d76ef7dcd4a3b30dd0793d2b19668 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio.bekerle@tugraz.at> Date: Wed, 7 Aug 2019 11:03:07 +0200 Subject: [PATCH] Add notification send function with alert fallback --- packages/common/notification.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 packages/common/notification.js diff --git a/packages/common/notification.js b/packages/common/notification.js new file mode 100644 index 00000000..9df57b21 --- /dev/null +++ b/packages/common/notification.js @@ -0,0 +1,32 @@ +/** + * Sends a notification via the event + * + * For type see: https://bulma.io/documentation/elements/notification/#colors + * + * example options: + * + * { + * "summary": "Item deleted", + * "body": "Item foo was deleted!", + * "type": "info", + * "timeout": 5, + * } + * + * @param options + */ +function send(options) { + const event = new CustomEvent("vpu-notification-send", { + bubbles: true, + cancelable: true, + detail: options, + }); + + const result = window.dispatchEvent(event); + + // true means the event was not handled + if (result) { + alert((options.summary !== undefined && options.summary !== "" ? options.summary + ": " : "") + options.body) + } +} + +export { send }; -- GitLab