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);
|
|
|
|
|
|
2016-10-10 17:51:44 -04:00
|
|
|
EditProfileController.$inject = ['$scope', '$http', '$location', 'UsersService', 'Authentication', 'Notification'];
|
2016-02-11 22:34:20 -03:00
|
|
|
|
2016-10-10 17:51:44 -04:00
|
|
|
function EditProfileController($scope, $http, $location, UsersService, Authentication, Notification) {
|
2016-02-11 22:34:20 -03:00
|
|
|
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) {
|
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-04-29 17:20:03 -04:00
|
|
|
var user = new UsersService(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-10-10 17:51:44 -04:00
|
|
|
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Edit profile successful!' });
|
2015-08-05 00:40:54 -04:00
|
|
|
Authentication.user = response;
|
|
|
|
|
}, function (response) {
|
2016-10-10 17:51:44 -04:00
|
|
|
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Edit profile failed!' });
|
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
|
|
|
}());
|