2016-02-11 22:34:20 -03:00
|
|
|
(function () {
|
|
|
|
|
'use strict';
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2016-02-11 22:34:20 -03:00
|
|
|
angular
|
|
|
|
|
.module('users')
|
|
|
|
|
.controller('EditProfileController', EditProfileController);
|
|
|
|
|
|
|
|
|
|
EditProfileController.$inject = ['$scope', '$http', '$location', 'Users', 'Authentication'];
|
|
|
|
|
|
|
|
|
|
function EditProfileController($scope, $http, $location, Users, Authentication) {
|
|
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
|
|
vm.user = Authentication.user;
|
|
|
|
|
vm.updateUserProfile = updateUserProfile;
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-07-25 16:53:11 -04:00
|
|
|
// Update a user profile
|
2016-02-11 22:34:20 -03:00
|
|
|
function updateUserProfile(isValid) {
|
|
|
|
|
vm.success = vm.error = null;
|
2014-11-10 23:12:33 +02:00
|
|
|
|
2015-08-05 00:40:54 -04:00
|
|
|
if (!isValid) {
|
2016-02-11 22:34:20 -03:00
|
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.userForm');
|
2015-08-05 00:40:54 -04:00
|
|
|
|
|
|
|
|
return false;
|
2015-07-25 16:53:11 -04:00
|
|
|
}
|
2015-08-05 00:40:54 -04:00
|
|
|
|
2016-02-11 22:34:20 -03:00
|
|
|
var user = new Users(vm.user);
|
2015-08-05 00:40:54 -04:00
|
|
|
|
|
|
|
|
user.$update(function (response) {
|
2016-02-11 22:34:20 -03:00
|
|
|
$scope.$broadcast('show-errors-reset', 'vm.userForm');
|
2015-08-05 00:40:54 -04:00
|
|
|
|
2016-02-11 22:34:20 -03:00
|
|
|
vm.success = true;
|
2015-08-05 00:40:54 -04:00
|
|
|
Authentication.user = response;
|
|
|
|
|
}, function (response) {
|
2016-02-11 22:34:20 -03:00
|
|
|
vm.error = response.data.message;
|
2015-08-05 00:40:54 -04:00
|
|
|
});
|
2016-02-11 22:34:20 -03:00
|
|
|
}
|
2015-07-25 16:53:11 -04:00
|
|
|
}
|
2015-12-10 20:31:51 +01:00
|
|
|
}());
|