Add support for org-based subscriptions
This commit is contained in:
parent
97a7cd23e7
commit
e356a10378
5 changed files with 109 additions and 35 deletions
|
@ -14,17 +14,6 @@ $.fn.clipboardCopy = function() {
|
|||
});
|
||||
};
|
||||
|
||||
function getRestUrl(args) {
|
||||
var url = '';
|
||||
for (var i = 0; i < arguments.length; ++i) {
|
||||
if (i > 0) {
|
||||
url += '/';
|
||||
}
|
||||
url += encodeURI(arguments[i])
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function HeaderCtrl($scope, $location, UserService, Restangular) {
|
||||
$scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) {
|
||||
$scope.user = currentUser;
|
||||
|
@ -716,7 +705,7 @@ function UserAdminCtrl($scope, $timeout, Restangular, PlanService, UserService,
|
|||
|
||||
$scope.planChanging = false;
|
||||
$scope.subscribe = function(planId) {
|
||||
PlanService.showSubscribeDialog($scope, planId, function() {
|
||||
PlanService.showSubscribeDialog($scope, planId, null, function() {
|
||||
// Subscribing.
|
||||
$scope.planChanging = true;
|
||||
}, function(plan) {
|
||||
|
@ -1035,7 +1024,7 @@ function NewRepoCtrl($scope, $location, $http, $timeout, UserService, Restangula
|
|||
};
|
||||
|
||||
$scope.upgradePlan = function() {
|
||||
PlanService.showSubscribeDialog($scope, $scope.planRequired.stripeId, function() {
|
||||
PlanService.showSubscribeDialog($scope, $scope.planRequired.stripeId, null, function() {
|
||||
// Subscribing.
|
||||
$scope.planChanging = true;
|
||||
}, function(plan) {
|
||||
|
@ -1203,6 +1192,7 @@ function OrgAdminCtrl($rootScope, $scope, Restangular, $routeParams, UserService
|
|||
};
|
||||
|
||||
var subscribedToPlan = function(sub) {
|
||||
$scope.planChanging = false;
|
||||
$scope.subscription = sub;
|
||||
PlanService.getPlan(sub.plan, function(subscribedPlan) {
|
||||
$scope.subscribedPlan = subscribedPlan;
|
||||
|
@ -1223,9 +1213,11 @@ function OrgAdminCtrl($rootScope, $scope, Restangular, $routeParams, UserService
|
|||
|
||||
var loadSubscription = function() {
|
||||
$scope.planLoading = true;
|
||||
UserService.getCurrentSubscription(subscribedToPlan, function() {
|
||||
|
||||
var getSubscription = Restangular.one(getRestUrl('organization', orgname, 'plan'));
|
||||
getSubscription.get().then(subscribedToPlan, function() {
|
||||
// Organization has no subscription.
|
||||
$scope.planLoading = false;
|
||||
subscribedToPlan({'plan': 'bus-free'});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1235,6 +1227,38 @@ function OrgAdminCtrl($rootScope, $scope, Restangular, $routeParams, UserService
|
|||
return 'success';
|
||||
};
|
||||
|
||||
$scope.subscribe = function(planId) {
|
||||
$scope.planChanging = true;
|
||||
PlanService.showSubscribeDialog($scope, planId, orgname, function() {
|
||||
// Subscribing.
|
||||
}, function(plan) {
|
||||
// Subscribed.
|
||||
subscribedToPlan(plan);
|
||||
}, function() {
|
||||
// Failure.
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.changeSubscription = function(planId) {
|
||||
$scope.planChanging = true;
|
||||
$scope.errorMessage = undefined;
|
||||
|
||||
var subscriptionDetails = {
|
||||
plan: planId,
|
||||
};
|
||||
|
||||
var changeSubscriptionRequest = Restangular.one(getRestUrl('organization', orgname, 'plan'));
|
||||
changeSubscriptionRequest.customPUT(subscriptionDetails).then(subscribedToPlan, function() {
|
||||
// Failure
|
||||
$scope.planChanging = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cancelSubscription = function() {
|
||||
$scope.changeSubscription('bus-free');
|
||||
};
|
||||
|
||||
loadSubscription();
|
||||
loadOrganization();
|
||||
}
|
||||
|
|
Reference in a new issue