diff --git a/src/assets/scripts/profile/profile.controller.js b/src/assets/scripts/profile/profile.controller.js index 09eec0a..2c0ddc9 100644 --- a/src/assets/scripts/profile/profile.controller.js +++ b/src/assets/scripts/profile/profile.controller.js @@ -1,6 +1,6 @@ import visas from './visa.type'; /** @ngInject */ -const ProfileController = ($scope, ProfileService, UserService) => { +const ProfileController = ($scope, $timeout, ProfileService, UserService) => { // Load visas in the scope $scope.visas = visas; @@ -24,12 +24,32 @@ const ProfileController = ($scope, ProfileService, UserService) => { * * v1.0 non selective update */ - $scope.updateProfile = () => { + $scope.updateProfile = (ProfileForm) => { + // Trigger validation flag. + $scope.submitted = true; + + // If form is invalid, return and show validation errors. + if (ProfileForm.$invalid) { + return; + } + + ProfileService.updateUserProfile($scope.user.id, $scope.userUpdated) .then((result)=>{ console.log(result); + $scope.messages = 'Your profile has been updated!'; + }) + .catch((err)=> { + console.log(err); + $scope.messages = 'Oops, we received your request, but there was an error processing it.'; }) - .catch((err)=> {console.log(err)}) + .finally(() => { + // Hide status messages after three seconds. + $timeout(() => { + $scope.messages = null; + }, 3000); + }); + } }); diff --git a/src/assets/scripts/profile/profile.html b/src/assets/scripts/profile/profile.html index db2caf4..f1e34d4 100644 --- a/src/assets/scripts/profile/profile.html +++ b/src/assets/scripts/profile/profile.html @@ -29,12 +29,14 @@