(function () { "use strict"; var InvitationController = function ($scope, $location, $routeParams, $window, sharingService, userService, timelineService) { $scope.model = {}; $scope.buttonText = 'Invite'; $scope.requestConnection = function () { $scope.model.newConnection = !$scope.model.newConnection; }; userService.planCount().then(count => { $scope.left = count; $scope.model = { requestConfirmationText: '', people: [] }; let max = count; for (var i = 0; i < max; i++) { let id = i; $scope.model.people.push({ newConnection: true, id, invited: () => $scope.invited(id) }); }; }); function refreshAsked() { sharingService.getOutstandingInvitations().then(function (data) { $scope.requests = data.data.map(x => { x.UpdatedAt = labelDate(x.UpdatedAt, 0); return x; }); }); } $scope.invited = function (id) { $scope.left--; if ($scope.left <= 0) $scope.model.people = []; $scope.model.invited = true; refreshAsked(); if ($scope.model.people.length > 0) { let index = $scope.model.people.findIndex(person => person.id === id); if (index > -1) { $scope.model.people.splice(index, 1); } } }; $scope.askForHelp = () => $scope.model.askForHelp = true; $scope.next = () => $location.url(`/timelines`); $scope.message = "Your invitations have been sent."; $scope.callback = () => { $('.upload').show(); timelineService.invite($scope.id, $scope.model.connections.filter(s => s.selected).map(s => s.Id)) .then(() => { $('.upload').hide(); $scope.complete = true; }).catch (() => $('.upload').hide()); }; refreshAsked(); }; InvitationController.$inject = ['$scope', '$location', '$routeParams', '$window', 'sharingService', 'userService', 'timelineService']; angular.module('streamApp').controller('invitationsController', InvitationController); })();