NAME
Mojolicious::Plugin::Notifications::Alertify - Event notifications using Alertify.js
SYNOPSIS
# Register the engine
plugin Notifications => {
Alertify => {
base_class => 'bootstrap'
}
};
# In the template
%= notifications 'Alertify'
DESCRIPTION
This plugin is a notification engine using Alertify.js.
If this does not suit your needs, you can easily write your own engine.
METHODS
Mojolicious::Plugin::Notifications::Alertify inherits all methods from Mojolicious::Plugin::Notifications::Engine and implements or overrides the following.
register
plugin Notifications => {
Alertify => {
base_class => 'bootstrap'
}
};
Called when registering the main plugin. All parameters under the key Alertify
are passed to the registration.
Accepts the following parameters:
- base_class
-
The theme for all alertify notifications. Defaults to
bootstrap
. See the Alertify.js documentation for more information on themes. - base_timeout
-
The base timeout for all alertify notifications. Defaults to
5000 ms
. Set to0
for no timeout.
HELPERS
notify
# In controllers
$c->notify(warn => 'Something went wrong');
$c->notify(success => { timeout => 2000 } => 'Everything went fine');
$c->notify(success => { ok => 'http://example.com/ok' } => 'Everything went fine');
Notify the user on certain events.
See the documentation for your chosen theme at Alertify.js to see, which notification types are presupported.
In addition to types and messages, the timeout
can be defined in a hash reference.
In case an ok
or cancel
parameter is passed, this will create a confirmation notification. The ok
and cancel
URLs will receive a POST request, once the buttons are pressed. In case an ok_label
is passed, this will be the label for the confirmation button. In case a cancel_label
is passed, this will be the label for the cancelation button. The POST will have a csrf_token parameter to validate.
Confirmation is EXPERIMENTAL!
notifications
# In templates
%= notifications 'alertify';
%= notifications 'alertify', 'bootstrap', -no_include, -no_css
Include alertify notifications in your template.
If you want to use a class different to the defined base class, you can pass this as a string attribute.
If you don't want to include the javascript and css assets for Alertify.js
, append -no_include
. If you just don't want to render the stylesheet tag for the inclusion of the CSS, append -no_css
.
All notifications are also rendered in a <noscript />
tag, following the notation described in the HTML engine.
EXPORTABLE FUNCTIONS
notify_alertify
use Mojolicious::Plugin::Notifications::Alertify qw/notify_alertify/;
notify_alertify(warn => { timeout => 5000 } => 'This is a warning')
# alertify.log("This is a warning","warn",5000);
Returns the notification as an Alertify.js JavaScript snippet.
Accepts the controller as an optional first parameter, the notification type, a hash reference with parameters, and the message. In case the parameters include ok
or cancel
routes, a confirmation notification is used.
If the first parameter is a Mojolicious::Controller object, and the notification is a confirmation, the requests will have a csrf_token parameter to validate.
Confirmation is EXPERIMENTAL!
SEE ALSO
AVAILABILITY
https://github.com/Akron/Mojolicious-Plugin-Notifications
COPYRIGHT AND LICENSE
Mojolicious::Plugin::Notifications::Alertify
Copyright (C) 2014-2018, Nils Diewald.
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Alertify.js (bundled)
Copyright (c) Fabien Doiron
See https://github.com/fabien-d/alertify.js for further information.
Licensed under the terms of the MIT License.