github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/notifybox.js (about)

     1  mciModule.factory('notificationService', function($rootScope) {
     2    var notifier = {};
     3    notifier.notifications = {};
     4    notifier.pushNotification = function(msg, destination, type) {
     5      // default is 'error'
     6      var type = type || "error"
     7      if (!this.notifications[destination] || this.notifications[destination].length === 0) {
     8          this.notifications[destination] = [];
     9      }
    10      if (_.pluck(this.notifications[destination], "msg").indexOf(msg) == -1) {
    11        this.notifications[destination].push({msg:msg, type:type});
    12        this.broadcastNotification();
    13      }
    14    };
    15  
    16    notifier.broadcastNotification = function() {
    17      $rootScope.$broadcast('broadcastNotification');
    18    };
    19  
    20    notifier.clear = function(destination) {
    21      notifier.notifications[destination] = [];
    22    };
    23    return notifier;
    24  });
    25  
    26  mciModule.controller('NotifyBoxCtrl', ['$scope','notificationService',function($scope, notificationService) {
    27    $scope.$on('broadcastNotification', function() {
    28      if (notificationService.notifications[$scope.destination]){
    29      $('#'+$scope.destination+'.alert.error-flash').show();
    30        $scope.notifications = notificationService.notifications[$scope.destination];
    31      }
    32    });
    33    $scope.close = function($event) {
    34      notificationService.clear($scope.destination);
    35      $($event.currentTarget).parents('#'+$scope.destination).hide();
    36    }
    37    $scope.notificationsForDest = function(destination){
    38      return notificationService.notifications[destination] || [];
    39    }
    40    $scope.notificationBoxClass = function(notification){
    41      // given a notification, look at its type and determine which CSS class 
    42      // should be used for the box to contain it when displayed
    43      var classes = {
    44          "success":"alert-success",
    45          "info":"alert-info",
    46          "warning":"alert-warning",
    47          "error":"alert-danger",
    48      };
    49      if(!notification['type'] || !(notification['type'] in classes)){
    50          return classes['error'];
    51      }
    52      return classes[notification['type']];
    53    }
    54  }]);
    55  
    56  mciModule.directive('notifyBox', function() {
    57    return {
    58      restrict: 'E',
    59      replace: true,
    60      templateUrl: '/static/partials/notifybox.html'
    61    };
    62  });