(function () { "use strict"; var QuestionAskController = function ($scope, $location, $routeParams, userService, $timeout) { $scope.invited = function () { $timeout(processInvite, 0); }; $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) } ] }; userService.getPromptToAsk($routeParams.id).then((prompt) => $scope.prompt = prompt ); $scope.ask = function () { let promptId = $scope.prompt.promptId; userService.askQuestion(promptId, $scope.model.connections.filter(c => c.selected).map(c => c.Id)).then(() => $location.url('question/' + promptId + '/asked') ).catch(() => $scope.model.error = "We had an issue saving your request. Don't worry - we are on it. Please try again later."); }; $scope.buttonText = 'Invite to Answer Question'; function refreshPrompt() { userService.getAskedQuestion($routeParams.id).then((prompt) => $scope.prompt = prompt ); } $scope.invited = function (id) { $scope.model.invited = true; refreshPrompt(); 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); } } }; }; QuestionAskController.$inject = ['$scope', '$location', '$routeParams', 'userService', '$timeout']; angular.module('streamApp').controller('questionFirstAskController', QuestionAskController); })();