This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/pages/update-user.js
josephschorr 45b1148118 Merge pull request #2086 from coreos-inc/user-info
Add collection of user metadata: name and company
2016-11-09 13:15:07 -05:00

85 lines
No EOL
2.1 KiB
JavaScript

(function() {
/**
* Update user page.
*/
angular.module('quayPages').config(['pages', function(pages) {
pages.create('update-user', 'update-user.html', UpdateUserCtrl, {
'title': 'Confirm Username'
});
}]);
function UpdateUserCtrl($scope, UserService, $location, ApiService) {
$scope.state = 'loading';
$scope.metadata = {};
UserService.updateUserIn($scope, function(user) {
if (!user.anonymous) {
if (!user.prompts || !user.prompts.length) {
$location.path('/');
return;
}
$scope.state = 'editing';
$scope.username = user.username;
}
});
var confirmUsername = function(username) {
if (username == $scope.user.username) {
$scope.state = 'confirmed';
return;
}
$scope.state = 'confirming';
var params = {
'username': username
};
ApiService.getUserInformation(null, params).then(function() {
$scope.state = 'existing';
}, function(resp) {
if (resp.status == 404) {
$scope.state = 'confirmed';
} else {
$scope.state = 'error';
}
});
};
$scope.updateUser = function(data) {
$scope.state = 'updating';
ApiService.changeUserDetails(data).then(function() {
UserService.load(function(updated) {
if (updated.prompts.length) {
$scope.state = 'editing';
} else {
$location.url('/');
}
});
}, ApiService.errorDisplay('Could not update user information'));
};
$scope.hasPrompt = function(user, prompt_name) {
if (!user.prompts) {
return false;
}
for (var i = 0; i < user.prompts.length; ++i) {
if (user.prompts[i] == prompt_name) {
return true;
}
}
return false;
};
$scope.$watch('username', function(username) {
if (!username) {
$scope.state = 'editing';
return;
}
confirmUsername(username);
});
}
})();