2014-08-27 07:31:01 -04:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App)->
|
2014-09-05 10:47:08 -04:00
|
|
|
SUBSCRIPTION_URL = "/user/subscription/update"
|
2015-02-06 11:54:11 -05:00
|
|
|
|
|
|
|
setupReturly = _.once ->
|
|
|
|
recurly?.configure window.recurlyApiKey
|
2015-12-08 10:45:52 -05:00
|
|
|
PRICES = {}
|
2014-08-27 07:31:01 -04:00
|
|
|
|
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
|
|
|
|
|
2014-10-13 11:27:27 -04:00
|
|
|
$scope.changeCurrency = (newCurrency)->
|
2014-09-05 10:47:08 -04:00
|
|
|
MultiCurrencyPricing.currencyCode = newCurrency
|
|
|
|
|
|
|
|
|
|
|
|
App.controller "ChangePlanFormController", ($scope, $modal, MultiCurrencyPricing)->
|
2015-02-06 11:54:11 -05:00
|
|
|
setupReturly()
|
2015-12-08 10:45:52 -05:00
|
|
|
console.log("init")
|
2015-02-06 10:54:16 -05:00
|
|
|
taxRate = window.taxRate
|
|
|
|
|
2014-08-27 07:31:01 -04:00
|
|
|
$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
|
|
|
|
|
2015-12-08 10:45:52 -05:00
|
|
|
$scope.prices = PRICES
|
2015-02-06 10:54:16 -05:00
|
|
|
$scope.refreshPrice = (planCode)->
|
|
|
|
if $scope.prices[planCode]?
|
|
|
|
return
|
2015-12-08 10:45:52 -05:00
|
|
|
$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)
|
2015-02-06 11:54:11 -05:00
|
|
|
$scope.$evalAsync () ->
|
2015-02-22 13:35:59 -05:00
|
|
|
taxAmmount = totalPriceExTax * taxRate
|
|
|
|
if isNaN(taxAmmount)
|
|
|
|
taxAmmount = 0
|
|
|
|
$scope.prices[planCode] = $scope.currencySymbol + (totalPriceExTax + taxAmmount)
|
2015-02-06 11:54:11 -05:00
|
|
|
|
2015-02-06 10:54:16 -05:00
|
|
|
price = ""
|
2014-08-27 07:31:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2014-08-27 07:31:01 -04:00
|
|
|
.success ->
|
|
|
|
location.reload()
|
|
|
|
.error ->
|
|
|
|
console.log "something went wrong changing plan"
|
|
|
|
|
|
|
|
$scope.cancel = () ->
|
2015-12-08 10:45:52 -05:00
|
|
|
$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"
|