(function () { "use strict"; var TimelineInvitationController = function ($scope, $location, $routeParams, $window, sharingService, timelineService) { $scope.model = {}; $scope.buttonText = 'Invite'; $scope.complete = false; $scope.id = $routeParams.id; timelineService.get($scope.id).then(timeline => $scope.timeline = timeline); $scope.requestConnection = function () { $scope.model.newConnection = !$scope.model.newConnection; }; sharingService.getContacts().then((connections) => { $scope.model.connections = connections.data; $scope.model.loaded = true; $scope.model.newConnection = !$scope.model.connections || !$scope.model.connections.length; }); $scope.model = { requestConfirmationText: '', people: [ { newConnection: true, id: 1, invited: () => $scope.invited(1) }, { newConnection: true, id: 2, invited: () => $scope.invited(2) }, { newConnection: true, id: 3, invited: () => $scope.invited(3) } ] }; function refreshAsked() { timelineService.getInvitedNew($scope.id) .then((requests) => { $scope.requests = requests; $scope.model.existingRequests = !!requests.length; }); } $scope.invited = function (id) { $scope.model.invited = true; refreshAsked(); if ($scope.model.people.length > 1) { 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.id}`); $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()); }; $scope.callbackFirst = () => { $location.url(`/nextSteps/${$scope.id}`); }; if ($routeParams.edit) { $scope.next = () => $window.history.back(); } refreshAsked(); }; TimelineInvitationController.$inject = ['$scope', '$location', '$routeParams', '$window', 'sharingService', 'timelineService']; angular.module('streamApp').controller('timelineInvitationsController', TimelineInvitationController); })();