(function () { "use strict"; angular.module('streamApp').controller("contactController", ContactController); ContactController.$inject = ['$scope', 'contactService', 'userService', '$location', '$window']; function ContactController($scope, contactService, userService, $location, $window) { $('.waiting').hide(); $scope.model = {}; userService.getProfile().then(function (data) { $scope.model.email = data.Email; $scope.model.name = data.Name; }).catch(); $scope.sendKey = function (keyEvent) { if (keyEvent.which === 13) $scope.send(); }; let once = true; $scope.send = function () { if (once) { $scope.submitted = true; if (!$scope.model.name || $scope.model.name.length < 2) { $scope.message = "Name must be at least 2 characters."; return; } // server side validated - keep it simple on the client if (!$scope.model.email || $scope.model.email.length < 4) { $scope.message = "Email is not valid."; return; } if (!$scope.model.content || $scope.model.content.length < 5) { $scope.message = "Oops - what is your question?"; return; } if ($scope.model.content.length > 3499) { $scope.message = "Message must be less than 3,500 characters."; return; } once = false; contactService.request($scope.model.email, $scope.model.name, $scope.model.content).then(() => { $scope.sentSuccessful = true; } ).catch(() => { $scope.message = "We had issues processing your request. Please make sure your email is valid, and try again."; once = true; }); } $scope.continue = function () { $window.history.back(); }; }; } })();