overleaf/services/web/public/coffee/main/subscription-dashboard.coffee

105 lines
3.1 KiB
CoffeeScript
Raw Normal View History

define [
"base"
], (App)->
2014-09-05 10:47:08 -04:00
SUBSCRIPTION_URL = "/user/subscription/update"
setupReturly = _.once ->
recurly?.configure window.recurlyApiKey
PRICES = {}
2015-02-06 10:54:16 -05:00
App.controller "CurrenyDropdownController", ($scope, MultiCurrencyPricing, $q)->
2014-09-05 10:47:08 -04:00
$scope.plans = MultiCurrencyPricing.plans
$scope.currencyCode = MultiCurrencyPricing.currencyCode
$scope.changeCurrency = (newCurrency)->
2014-09-05 10:47:08 -04:00
MultiCurrencyPricing.currencyCode = newCurrency
App.controller "ChangePlanFormController", ($scope, $modal, MultiCurrencyPricing)->
setupReturly()
console.log("init")
2015-02-06 10:54:16 -05:00
taxRate = window.taxRate
$scope.changePlan = ->
$modal.open(
templateUrl: "confirmChangePlanModalTemplate"
controller: "ConfirmChangePlanController"
scope: $scope
)
2014-09-05 10:47:08 -04:00
$scope.$watch "pricing.currencyCode", ->
$scope.currencyCode = MultiCurrencyPricing.currencyCode
$scope.pricing = MultiCurrencyPricing
$scope.plans = MultiCurrencyPricing.plans
2015-02-06 10:54:16 -05:00
$scope.currencySymbol = MultiCurrencyPricing.plans[MultiCurrencyPricing.currencyCode].symbol
2014-09-05 10:47:08 -04:00
$scope.currencyCode = MultiCurrencyPricing.currencyCode
$scope.prices = PRICES
2015-02-06 10:54:16 -05:00
$scope.refreshPrice = (planCode)->
if $scope.prices[planCode]?
return
$scope.prices[planCode] = "..."
2015-02-06 10:54:16 -05:00
pricing = recurly.Pricing()
2015-02-06 12:08:42 -05:00
pricing.plan(planCode, { quantity: 1 }).currency(MultiCurrencyPricing.currencyCode).done (price)->
2015-02-06 10:54:16 -05:00
totalPriceExTax = parseFloat(price.next.total)
$scope.$evalAsync () ->
taxAmmount = totalPriceExTax * taxRate
if isNaN(taxAmmount)
taxAmmount = 0
$scope.prices[planCode] = $scope.currencySymbol + (totalPriceExTax + taxAmmount)
2015-02-06 10:54:16 -05:00
price = ""
App.controller "ConfirmChangePlanController", ($scope, $modalInstance, $http)->
$scope.confirmChangePlan = ->
body =
plan_code: $scope.plan.planCode
_csrf : window.csrfToken
$scope.inflight = true
2014-09-05 10:47:08 -04:00
$http.post(SUBSCRIPTION_URL, body)
.success ->
location.reload()
.error ->
console.log "something went wrong changing plan"
$scope.cancel = () ->
$modalInstance.dismiss('cancel')
App.controller "UserSubscriptionController", ($scope, MultiCurrencyPricing, $http) ->
$scope.view = 'overview'
$scope.isMonthlyCollab = subscription?.planCode?.indexOf("collaborator") != -1 and subscription?.planCode?.indexOf("ann") == -1
setupReturly()
recurly.Pricing().plan('student', { quantity: 1 }).currency(MultiCurrencyPricing.currencyCode).done (price)->
totalPriceExTax = parseFloat(price.next.total)
$scope.$evalAsync () ->
taxAmmount = totalPriceExTax * taxRate
if isNaN(taxAmmount)
taxAmmount = 0
$scope.currencySymbol = MultiCurrencyPricing.plans[MultiCurrencyPricing.currencyCode].symbol
$scope.studentPrice = $scope.currencySymbol + (totalPriceExTax + taxAmmount)
$scope.downgradeToStudent = ->
body =
plan_code: 'student'
_csrf : window.csrfToken
$scope.inflight = true
$http.post(SUBSCRIPTION_URL, body)
.success ->
location.reload()
.error ->
console.log "something went wrong changing plan"
$scope.switchToCancelationView = ->
$scope.view = "cancelation"