(function () { "use strict"; var QuestionAskController = function ($scope, $location, $routeParams, userService, sharingService) { $scope.model = { newConnection: false, requestConfirmationText: ''}; $scope.requestConnection = function () { $scope.model.newConnection = !$scope.model.newConnection; }; userService.getAskedQuestion($routeParams.id).then((prompt) => $scope.prompt = prompt ).then(() => { sharingService.getContacts().then((connections) => { $scope.model.connections = connections.data || []; $scope.model.newConnection = !$scope.model.connections.length; let prompt = $scope.prompt; $scope.model.connections.map(connection => { connection.selected = prompt.askeds && prompt.askeds.some(({Id}) => Id === connection.Id); return connection; }); }); }); $scope.callback = () => $scope.isAsked = $scope.model.connections.some(x => x.selected); $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.invited = function () { $scope.model.invited = true; }; }; QuestionAskController.$inject = ['$scope', '$location', '$routeParams', 'userService', 'sharingService']; angular.module('streamApp').controller('questionAskController', QuestionAskController); })();