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/directives/ui/plans-display.js
Joseph Schorr 0a435fa1dc Fix Angular bug on plans page when using back button
Angular apparently tries to read the DOM that is being manipulated simultaneously by bootstrap, which results it a state inconsistency (since the DOM is changing) and an Angular failure. This change ensure that the modal call happens outside of the initial digest loop and therefore, appears to solve the problem (translation: who the heck knows why it works, but it does).

Fixes #1869
2016-09-23 15:35:19 -04:00

61 lines
No EOL
1.8 KiB
JavaScript

/**
* An element which displays the plans page content. Put into a directive for encapsulating the tab
* changing code.
*/
angular.module('quay').directive('plansDisplay', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/plans-display.html',
replace: false,
transclude: true,
restrict: 'C',
scope: {
},
controller: function($scope, $element, $routeParams, $timeout, UserService, PlanService, UIService) {
// Monitor any user changes and place the current user into the scope.
UserService.updateUserIn($scope);
// Watch for tab changes.
UIService.initializeTabs($scope, $element);
$scope.signedIn = function() {
$('#signinModal').modal('hide');
PlanService.handleNotedPlan();
};
$scope.qeStartTrial = function(plan) {
$scope.currentQEPlan = plan;
$('#tectonicManagerDialog').modal('show');
};
$scope.buyNow = function(plan) {
PlanService.notePlan(plan);
if ($scope.user && !$scope.user.anonymous) {
PlanService.handleNotedPlan();
} else {
$timeout(function() {
$('#signinModal').modal({});
}, 0);
}
};
// Load the list of plans.
PlanService.getPlans(function(plans) {
$scope.plans = plans;
for (var i = 0; i < $scope.plans.length; ++i) {
var plan = plans[i];
if (plan.privateRepos > 20 && !plan.plans_page_hidden) {
$scope.dropdownPlan = plan.stripeId;
break
}
}
if ($scope && $routeParams['trial-plan']) {
$scope.buyNow($routeParams['trial-plan']);
}
}, /* include the personal plan */ true);
}
};
return directiveDefinitionObject;
});