annual-upgrade.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. import App from '../base'
  13. import { debugConsole } from '@/utils/debugging'
  14. export default App.controller('AnnualUpgradeController', [
  15. '$scope',
  16. '$http',
  17. function ($scope, $http) {
  18. const MESSAGES_URL = '/user/subscription/upgrade-annual'
  19. $scope.upgradeComplete = false
  20. const savings = {
  21. student: '19.2',
  22. collaborator: '36',
  23. }
  24. $scope.$watch($scope.planName, function () {
  25. $scope.yearlySaving = savings[$scope.planName]
  26. if ($scope.planName === 'annual') {
  27. return ($scope.upgradeComplete = true)
  28. }
  29. })
  30. return ($scope.completeAnnualUpgrade = function () {
  31. const body = {
  32. planName: $scope.planName,
  33. _csrf: window.csrfToken,
  34. }
  35. $scope.inflight = true
  36. return $http
  37. .post(MESSAGES_URL, body)
  38. .then(() => ($scope.upgradeComplete = true))
  39. .catch(err =>
  40. debugConsole.error('something went wrong changing plan', err)
  41. )
  42. })
  43. },
  44. ])