pyc-website
main website for pyc inc.
git clone https://9o.is/git/pyc-website.git
ngAlert.js
(1094B)
1 /**
2 * Helper module for ui-bootstrap alert.
3 * Listens for 2 events:
4 *
5 * 1. alertClear: clears all alerts.
6 * 2. alertDialog: sets a message for Alert Box
7 *
8 * Message example:
9 *
10 * {
11 * type: "danger",
12 * msg: "<span>The world is going to explode!</span>"
13 * }
14 */
15 angular.module("ngAlert", ['ui.bootstrap'])
16 .controller('AlertCtrl', ['$scope', '$timeout', function($scope, $timeout) {
17 $scope.alerts = [];
18
19 $scope.addAlert = function(alert) {
20 $scope.alerts = [];
21 $scope.alerts.push({type: alert.msg_type, msg: alert.msg});
22
23 if(alert.hasOwnProperty('timeout')) {
24 $timeout($scope.clearAlerts(), alert.timeout);
25 }
26 };
27
28 $scope.closeAlert = function(index) {
29 $scope.alerts.splice(index, 1);
30 };
31
32 $scope.clearAlerts = function() {
33 $scope.alerts = [];
34 };
35 }])
36 .controller('AlertMainCtrl', ['$scope', '$controller', function($scope, $controller) {
37 $controller('AlertCtrl', {$scope: $scope});
38
39 $scope.$on('alertDialog', function(event, alert) {
40 $scope.addAlert(alert);
41 });
42
43 $scope.$on('alertClear', function() {
44 $scope.clearAlerts();
45 });
46
47 }]);