Source: site/notifications.js

// Generated by CoffeeScript 1.12.7

/**
 * Notifications
 * @module
 */
'use strict';
var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

app.directive('notifications', [
  '$sce', '$route', '$rootScope', 'constantService', 'routerService', 'messageService', 'modelService', function($sce, $route, $rootScope, constants, router, messages, models) {
    return {
      restrict: 'E',
      templateUrl: 'site/notifications.html',
      scope: {
        close: '&'
      },
      link: function($scope) {
        var state;
        $scope.party = models.Login.user;
        router.http(router.controllers.getNotifications).then(function(res) {
          var i, len, n, ref;
          ref = $scope.notifications = res.data;
          for (i = 0, len = ref.length; i < len; i++) {
            n = ref[i];
            n.html = $sce.trustAsHtml(n.html);
          }
          models.Login.user.notifications = 0;
        }, function(res) {
          messages.addError({
            type: 'red',
            body: 'An error occurred retrieving your notifications',
            report: res
          });
        });
        state = [constants.notice.AuthorizeExpiring, constants.notice.AuthorizeExpired, constants.notice.AuthorizeChildExpiring, constants.notice.AuthorizeChildExpired];
        $scope.deletable = function(n) {
          var ref;
          return !(ref = n.notice, indexOf.call(state, ref) >= 0);
        };
        $scope["delete"] = function(n) {
          router.http(router.controllers.deleteNotification, [n.id]).then(function() {
            n.deleted = true;
          });
        };
        $scope.deleteAll = function() {
          router.http(router.controllers.deleteNotifications).then(function() {
            var i, len, n, ref;
            ref = $scope.notifications;
            for (i = 0, len = ref.length; i < len; i++) {
              n = ref[i];
              if ($scope.deletable(n)) {
                n.deleted = true;
              }
            }
          });
        };
        $scope.settings = function() {
          if ($route.current.controller === 'party/edit') {
            $scope.close();
            $rootScope.$broadcast('wizard-activate', 'notifications');
          }
        };
      }
    };
  }
]);

//# sourceMappingURL=notifications.js.map