all files / js/employer/ employer.controller.js

11.76% Statements 2/17
0% Branches 0/4
0% Functions 0/5
11.76% Lines 2/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                                                                                             
/**
 * Created by cklimkowsky on 2/24/15.
 */
angular
    .module('coopEval')
    .controller('EmployerController', EmployerController);
 
function EmployerController($scope, $rootScope, $location, employerService) {
 
    $scope.credentials = {
        username: '',
        password: ''
    };
 
    if ($location.path() == '/employers') {
        // On the Overview page, get the student's co-op history
        employerService.getPlacementData()
            .success(function (result) {
                $scope.overviewData = result;
            });
    }
 
    $scope.login = function (credentials) {
        employerService.login(credentials)
            .success(function () {
                $rootScope.userType='Employer';
                delete $rootScope.message;
 
                $location.path('/employers');
            })
            .error(function () {
                $location.path('/employers/login');
 
                var errorContent;
                if($scope.credentials.username == undefined) {
                    errorContent = 'Your username is invalid. Please ensure you entered the correct email address.';
                } else {
                    errorContent = 'Your log-in information is incorrect.';
                }
 
                // Todo: Error handling - get error from server to be more specifc?
                $rootScope.message = {
                    type: 'danger',
                    content: errorContent,
                    location: $location.path()
                };
            })
    }
}