Support the additional stripe callbacks

This commit is contained in:
Joseph Schorr 2013-11-08 20:32:56 -05:00
parent 68e1658849
commit 0f473a3a82
3 changed files with 49 additions and 41 deletions

View file

@ -212,23 +212,31 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
createSubscriptionRequest.customPUT(subscriptionDetails).then(success, failure);
};
planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, started, success, failure) {
planService.changePlan = function($scope, orgname, planId, hasExistingSubscription, callbacks) {
if (!hasExistingSubscription) {
planService.showSubscribeDialog($scope, orgname, planId, started, success, failure);
planService.showSubscribeDialog($scope, orgname, planId, callbacks);
return;
}
started();
planService.setSubscription(orgname, planId, success, failure);
if (callbacks['started']) {
callbacks['started']();
}
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
};
planService.showSubscribeDialog = function($scope, orgname, planId, started, success, failure) {
planService.showSubscribeDialog = function($scope, orgname, planId, callbacks) {
if (callbacks['opening']) {
callbacks['opening']();
}
var submitToken = function(token) {
mixpanel.track('plan_subscribe');
$scope.$apply(function() {
started();
planService.setSubscription(orgname, planId, success, failure);
if (callbacks['started']) {
callbacks['started']();
}
planService.setSubscription(orgname, planId, callbacks['success'], callbacks['failure']);
});
};
@ -255,7 +263,9 @@ quayApp = angular.module('quay', ['restangular', 'angularMoment', 'angulartics',
description: 'Up to ' + planDetails.privateRepos + ' private repositories',
panelLabel: 'Subscribe',
token: submitToken,
image: 'static/img/quay-icon-stripe.png'
image: 'static/img/quay-icon-stripe.png',
opened: function() { $scope.$apply(function() { callbacks['opened']() }); },
closed: function() { $scope.$apply(function() { callbacks['closed']() }); }
});
});
};
@ -629,16 +639,16 @@ quayApp.directive('planManager', function () {
$scope.changeSubscription = function(planId) {
if ($scope.planChanging) { return; }
PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, function() {
// Started.
$scope.planChanging = true;
}, function(sub) {
// Success.
subscribedToPlan(sub);
}, function() {
// Failure.
$scope.planChanging = false;
});
var callbacks = {
'opening': function() { $scope.planChanging = true; },
'started': function() { $scope.planChanging = true; },
'opened': function() { $scope.planChanging = true; },
'closed': function() { $scope.planChanging = false; },
'success': subscribedToPlan,
'failure': function() { $scope.planChanging = false; }
};
PlanService.changePlan($scope, $scope.organization, planId, hasSubscription, callbacks);
};
$scope.cancelSubscription = function() {