2015-04-02 20:34:41 +00:00
|
|
|
/**
|
|
|
|
* Displays a panel for converting the current user to an organization.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('convertUserToOrg', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
priority: 0,
|
|
|
|
templateUrl: '/static/directives/convert-user-to-org.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: true,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'user': '=user'
|
|
|
|
},
|
2015-05-05 16:38:35 +00:00
|
|
|
controller: function($scope, $element, Features, PlanService, Config, ApiService, CookieService, UserService) {
|
2015-04-02 20:34:41 +00:00
|
|
|
$scope.convertStep = 0;
|
2015-05-05 16:37:19 +00:00
|
|
|
$scope.org = {};
|
2015-05-05 18:59:31 +00:00
|
|
|
$scope.loading = false;
|
2015-04-02 20:34:41 +00:00
|
|
|
|
|
|
|
$scope.showConvertForm = function() {
|
|
|
|
if (Features.BILLING) {
|
|
|
|
PlanService.getMatchingBusinessPlan(function(plan) {
|
|
|
|
$scope.org.plan = plan;
|
|
|
|
});
|
|
|
|
|
|
|
|
PlanService.getPlans(function(plans) {
|
|
|
|
$scope.orgPlans = plans;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.convertStep = 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.convertToOrg = function() {
|
|
|
|
$('#reallyconvertModal').modal({});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.reallyConvert = function() {
|
|
|
|
if (Config.AUTHENTICATION_TYPE != 'Database') { return; }
|
|
|
|
|
|
|
|
$scope.loading = true;
|
|
|
|
|
2015-05-07 20:28:58 +00:00
|
|
|
var errorHandler = ApiService.errorDisplay(function() {
|
|
|
|
$scope.loading = false;
|
|
|
|
});
|
|
|
|
|
2015-04-02 20:34:41 +00:00
|
|
|
var data = {
|
|
|
|
'adminUser': $scope.org.adminUser,
|
|
|
|
'adminPassword': $scope.org.adminPassword,
|
|
|
|
'plan': $scope.org.plan ? $scope.org.plan.stripeId : ''
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.convertUserToOrganization(data).then(function(resp) {
|
2015-05-05 18:59:31 +00:00
|
|
|
CookieService.putPermanent('quay.namespace', $scope.user.username);
|
2015-04-02 20:34:41 +00:00
|
|
|
UserService.load();
|
|
|
|
$location.path('/');
|
2015-05-07 20:28:58 +00:00
|
|
|
}, errorHandler);
|
2015-04-02 20:34:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
|
|
|
});
|