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/new-organization.js
Joseph Schorr 3a68740ff7 Better handling of namespace validation to fix a number of issues
- Fixes a bug which allows for underscores at the beginning of namespaces: Fixes #1849
- Allows dots and dashes for newer Docker clients: Fixes #1188
- Has the UI display better messaging associated with namespace entry
2016-10-20 13:32:22 -04:00

102 lines
No EOL
2.8 KiB
JavaScript

(function() {
/**
* Page for creating a new organization.
*/
angular.module('quayPages').config(['pages', function(pages) {
pages.create('new-organization', 'new-organization.html', NewOrgCtrl, {
'newLayout': true,
'title': 'New Organization',
'description': 'Create a new organization to manage teams and permissions'
});
}]);
function NewOrgCtrl($scope, $routeParams, $timeout, $location, UserService, PlanService, ApiService, CookieService, Features) {
$scope.Features = Features;
$scope.holder = {};
$scope.org = {
'name': $routeParams['namespace'] || ''
};
UserService.updateUserIn($scope);
var requested = $routeParams['plan'];
if (Features.BILLING) {
// Load the list of plans.
PlanService.getPlans(function(plans) {
$scope.plans = plans;
$scope.holder.currentPlan = null;
if (requested) {
PlanService.getPlan(requested, function(plan) {
$scope.holder.currentPlan = plan;
});
}
});
}
$scope.signedIn = function() {
if (Features.BILLING) {
PlanService.handleNotedPlan();
}
};
$scope.signinStarted = function() {
if (Features.BILLING) {
PlanService.getMinimumPlan(1, true, function(plan) {
if (!plan) { return; }
PlanService.notePlan(plan.stripeId);
});
}
};
$scope.setPlan = function(plan) {
$scope.holder.currentPlan = plan;
};
$scope.createNewOrg = function() {
$scope.createError = null;
$scope.creating = true;
var org = $scope.org;
var data = {
'name': org.name,
'email': org.email
};
ApiService.createOrganization(data).then(function(created) {
$scope.created = created;
// Reset the organizations list.
UserService.load();
// Set the default namesapce to the organization.
CookieService.putPermanent('quay.namespace', org.name);
var showOrg = function() {
$scope.creating = false;
$location.path('/organization/' + org.name + '/');
};
// If the selected plan is free, simply move to the org page.
if (!Features.BILLING || $scope.holder.currentPlan.price == 0) {
showOrg();
return;
}
// Otherwise, show the subscribe for the plan.
$scope.creating = true;
var callbacks = {
'opened': function() { $scope.creating = true; },
'closed': showOrg,
'success': showOrg,
'failure': showOrg
};
PlanService.changePlan($scope, org.name, $scope.holder.currentPlan.stripeId, callbacks);
}, function(resp) {
$scope.creating = false;
$scope.createError = ApiService.getErrorMessage(resp);
});
};
}
})();