digitalbazaar/bedrock-angular-alert

Name: bedrock-angular-alert

Owner: Digital Bazaar, Inc.

Description: Bedrock AngularJS Alerts

Created: 2015-01-21 22:21:53.0

Updated: 2017-09-09 01:33:45.0

Pushed: 2017-11-06 17:43:20.0

Homepage: null

Size: 35

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

bedrock-angular-alert

An AngularJS module that provides a service for managing alerts (errors, warnings, feedback information, etc.) for bedrock-angular and directives for displaying those alerts.

Quick Examples
 display all logged alerts -->
 br-alerts br-fixed="true"></div>

 custom directive that uses brAlertService -->
directive/>
s
lar.module('example', ['bedrock.alert']).directive('myDirective', factory);

ngInject */
tion factory(brAlertService) {
turn {
restrict: 'E',
scope: {},
template: '<button ng-click="errorOccurred()">Error</button>',
link: function(scope, element) {
  brAlertService.add('info', 'myDirective loaded.');

  scope.errorOccurred = function(err) {
    // add a feedback error; if the scope is destroyed, remove the error
    brAlertService.add('error', err, {scope: scope});
  };
}


Setup
r install bedrock-angular-alert

Installation of the module followed by a restart of your bedrock server is sufficient to make the module available to your application.

To manually add bedrock-angular-alert as a dependency:

lar.module('myapp', ['bedrock.alert']);
API
brAlertService.category

An object that stores the available alert categories: FEEDBACK and BACKGROUND.

brAlertService.log

A categorized log of alerts. brAlertService.log is an object where each entry has a key from brAlertService.category and a value that is an array of alerts that have been added for that category.

brAlertService.on(event, listener)

Adds a listener for the given type of event. The valid event types are: add, remove, and clear. The add event is emitted when an alert is added, remove is emitted when an alert is removed, and clear is emitted when alerts of a particular type and/or category are cleared.

brAlertService.removeListener(event, listener)

Removes a particular event listener.

brAlertService.add(type, value, [options])

Adds an alert to the log.

The alert type may be error, warning, or info.

The value can be a string, an Error instance, or an object with an html property set to custom html to be displayed, for example, by a br-alerts directive.

If options are provided, they may include a category from brAlertService.category and/or a scope. If no category is given, the default, brAlertService.category.FEEDBACK will be used. If a scope is given, then when the scope is destroyed, the alert will be removed. This is useful for removing feedback generated from UI elements that can be destroyed. For example, a modal that generates feedback alerts may be closed, and if the alerts were added using the modal's scope, the alerts will be automatically removed.

brAlertService.remove(type, value)

Removes the given alert, regardless of which category it is in.

brAlertService.clear([type], [category])

Clears all alerts of a given type or all alerts of a given type in a particular category.

brAlertService.clearFeedback([type])

Clears all feedback alerts or feedback alerts of a particular type.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.