Remove some code duplication by moving the robot and team creation dialogs to the create service

This commit is contained in:
Joseph Schorr 2015-04-08 11:54:04 -04:00
parent 4b64236d8e
commit 7bdd7c5f82
4 changed files with 48 additions and 62 deletions

View file

@ -188,25 +188,12 @@ angular.module('quay').directive('headerBar', function () {
$scope.createRobot = function(context) {
var namespace = $scope.getNamespace(context);
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
var isorg = UserService.isOrganization(namespace);
bootbox.prompt('Enter the name of the new robot account', function(robotname) {
if (!robotname) { return; }
var regex = new RegExp(ROBOT_PATTERN);
if (!regex.test(robotname)) {
bootbox.alert('Invalid robot account name');
return;
CreateService.askCreateRobot(function(created) {
if (isorg) {
$location.url('/organization/' + namespace + '?tab=robots');
} else {
$location.url('/user/' + namespace + '?tab=robots');
}
CreateService.createRobotAccount(ApiService, isorg, namespace, robotname, function(created) {
if (isorg) {
$location.url('/organization/' + namespace + '?tab=robots');
} else {
$location.url('/user/' + namespace + '?tab=robots');
}
});
});
};
@ -214,18 +201,8 @@ angular.module('quay').directive('headerBar', function () {
var namespace = $scope.getNamespace(context);
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
bootbox.prompt('Enter the name of the new team', function(teamname) {
if (!teamname) { return; }
var regex = new RegExp(TEAM_PATTERN);
if (!regex.test(teamname)) {
bootbox.alert('Invalid team name');
return;
}
CreateService.createOrganizationTeam(ApiService, namespace, teamname, function(created) {
CreateService.askCreateTeam(function(created) {
$location.url('/organization/' + namespace + '/teams/' + teamname);
});
});
};
}