Skip to content
Tom Taylor edited this page Nov 12, 2015 · 9 revisions

Notify is the authoring tool's notifications API, and has been designed to simplify the process of presenting information to the user at runtime.

API

All Notify plugins adhere to a very straightforward API, so you don't need to learn how to use each one individually (with the exception of some custom configuration settings).

All Notify plugins are stored on the Notify object, and referenced as follows: Origin.Notify.PLUGIN_NAME(DATA_OBJECT), where PLUGIN_NAME is the plugin you want to call (e.g. alert, console), and DATA_OBJECT is an object that defines the configuration data for your alert.

As a minimum, all Notify plugins support the following:

{
  type: String // Varies per plugin, but usually values like error, info etc.
  text: String // The text to display
  callback: Function // Called upon completion (i.e. popup closed or timed out)
}

Notification Types

By default, Notify comes with two types: alert and console.

Alert

Notify's alert is intended as a replacement for window.alert and window.confirm, giving you a nicely styled dialogue box with a plethora of configurable options, most notably the ability to categorise your alert into a number of different sub-types.

As it's powered by SweetAlert, you're able to use any settings that are defined in the SweetAlert documentation. Just set these on the data object you pass when calling Notify.

Model Data

In addition to the defaults specified above, all alerts can be passed the following attributes in the data object:

{
  type: String // supports 'warning', 'error', 'success' and 'info'
  title: String // Text shown as the popup title
}
// See below for some useful SweetAlert options, check the documentation for the full list
{
  allowEscapeKey: Boolean // Dismiss the modal by pressing Esc
  customClass: String // Will be applied as a CSS class
  allowOutsideClick: Boolean // Dismiss popup by clicking outside it
  showConfirmButton	Boolean // Show 'OK/Confirm'-button
  confirmButtonText	String // 'Confirm'-button text label
  confirmButtonColor	String // 'Confirm'-button bg colour (HEX value)
  closeOnConfirm	Boolean // Keep popup open even after 'Confirm'-button clicked
  showCancelButton	Boolean	// Show 'Cancel' button
  cancelButtonText	String // 'Cancel'-button text label
  closeOnCancel: Boolean // Closes popup on cancel button click
  timer: Number // Auto-close popup after set milliseconds
  html: Boolean	// set to true to disable escaping of title/text values
}

Aliases

To make the process of displaying the SweetAlert popups a bit more straightforward, we've created a number of aliases, which specify certain default options. These aliases are as follows:

alert

This is the basic alert, and comparable to the window.alert. If no type is specified, the user is shown a simple popup with a single button to dismiss it. The popup can have a title, description, and callback function.

Can also be called by passing a string, rather than the data object: Origin.Notify.alert("Hello world!");

Alert sub-types

In addition to the plain alert popups, you can also set the type to: success, info, or error to add some more appropriate styling. All other functionality remains the same as the standard alert.

confirm

A straight replacement for window.confirm, displaying a simple popup with an 'are you sure'-type title, and 'yes'/'no' buttons (all text values can be localised).

warning

An extension of confirm, this provides the same functionality, with the exception of the title, which must be specifically set (does also work without a title). The styling for this type also differs from the generic confirm type.

Console

This plugin just provides a hook into the 'window.console' object, so should be familiar. Its purpose is to allow for other code to listen out for logging events (still TODO).

Example Usage

Example alerts

Origin.Notify.alert({
  title: "Popup title",
  text: "Main popup message."
});

or using the shorthand:

Origin.Notify.alert("Main popup message.");
Origin.Notify.alert({
  type: "success",
  title: "Plugin uploaded",
  text: "The plugin was uploaded successfully!"
});

Origin.Notify.alert({
  type: "error",
  title: "Oops!",
  text: "An error occurred."
});

Example confirm

Origin.Notify.confirm({
  title: "This will override the default title",
  text: "Leaving now will discard any unsaved data."
});

Shorthand:

Origin.Notify.confirm("Leaving now will discard any unsaved data.");

Example warning

Origin.Notify.alert({
  type: "warning",
  title: "This will override the default title",
  text: "Leaving now will discard any unsaved data."
});

Extending Notify

Notify comes with a few handy plugins from the get-go, but it's been designed with pluggability in mind, so you can easily write your own plugin to meet your own needs.

To register a plugin for use with Notify, you need to call Notify's register function:

Origin.Notify.register(NAME String, TO_CALL Function);

NAME is the name used to call your plugin. This will be set on the Notify object (e.g. Notify.alert, Notify.console), so single words are preferable.

TO_CALL is the function to be called. This function should accept an object, and comply with the data specification in the API section above.

Clone this wiki locally