change plan has multi currency view

This commit is contained in:
Henry Oswald 2014-09-05 15:47:08 +01:00
parent 08e61efeb6
commit ff0365c157
3 changed files with 83 additions and 35 deletions

View file

@ -1,5 +1,7 @@
extends ../layout extends ../layout
block scripts
script(type='text/javascript').
window.recurlyPublicToken = '#{settings.apis.recurly.publicKey}'
mixin printPlan(plan) mixin printPlan(plan)
@ -9,9 +11,9 @@ mixin printPlan(plan)
strong #{plan.name} strong #{plan.name}
td td
-if (plan.annual) -if (plan.annual)
| $#{plan.price / 100} / #{translate("year")} | {{plans[currencyCode][plan.planCode.replace("-annual","")]['annual']}} / #{translate("year")}
-else -else
| $#{plan.price / 100} / #{translate("month")} | {{plans[currencyCode][plan.planCode]['monthly']}} / #{translate("month")}
td td
-if (subscription.state == "free-trial") -if (subscription.state == "free-trial")
a(href="/user/subscription/new?planCode=#{plan.planCode}").btn.btn-success #{translate("subscribe_to_this_plan")} a(href="/user/subscription/new?planCode=#{plan.planCode}").btn.btn-success #{translate("subscribe_to_this_plan")}
@ -66,7 +68,22 @@ block content
-if(subscription.groupPlan) -if(subscription.groupPlan)
a(href="/subscription/group").btn.btn-success !{translate("manage_group")} a(href="/subscription/group").btn.btn-success !{translate("manage_group")}
div(ng-show="changePlan", ng-cloak) span(ng-controller="CurrenyDropdownController")
.dropdown
a.btn.btn-primary.dropdown-toggle#currenyDropdown(
href="#",
data-toggle="dropdown"
)
| {{currencyCode}} ({{plans[currencyCode]['symbol']}})
ul.dropdown-menu(role="menu")
li(ng-repeat="(currency, value) in plans", dropdown-toggle)
a(
href,
ng-click="changeCurreny(currency)"
) {{currency}} ({{value['symbol']}})
div(ng-hide="changePlan", ng-cloak)
hr hr
h2 !{translate("change_plan")} h2 !{translate("change_plan")}
p: table.table p: table.table

View file

@ -2,30 +2,22 @@ define [
"base" "base"
"libs/recurly-3.0.5" "libs/recurly-3.0.5"
], (App, recurly) -> ], (App, recurly) ->
App.controller "PlansController", ($scope, $modal, event_tracking, abTestManager) ->
App.factory "MultiCurrencyPricing", () ->
recurly.configure(window.recurlyPublicToken); recurly.configure(window.recurlyPublicToken);
pricing = recurly.Pricing() pricing = recurly.Pricing()
window.pricing = pricing window.pricing = pricing
currencyCode = pricing.items.currency
$scope.currencyCode = pricing.items.currency
pricing.on "set.currency", (currency)-> pricing.on "set.currency", (currency)->
$scope.currencyCode = pricing.items.currency currencyCode = pricing.items.currency
buckets = [
{ bucketName:"30d", queryString: "_free_trial", trial_len:30 }
{ bucketName:"14d", queryString: "_free_trial_14_days", trial_len:14 }
]
bucket = abTestManager.getABTestBucket "trial_len", buckets
$scope.trial_len = bucket.trial_len currencyCode:currencyCode
$scope.planQueryString = bucket.queryString plans:
$scope.ui =
view: "monthly"
$scope.plans =
USD: USD:
symbol: "$" symbol: "$"
student: student:
@ -41,25 +33,46 @@ define [
EUR: EUR:
symbol: "" symbol: ""
student: student:
monthly: "8" monthly: "7"
annual: "80" annual: "70"
collaborator: collaborator:
monthly: "€15" monthly: "€12"
annual: "€180" annual: "€144"
professional: professional:
monthly: "30" monthly: "25"
annual: "€360" annual: "€300"
GBP: GBP:
symbol: "£" symbol: "£"
student: student:
monthly: "£8" monthly: "£6"
annual: "£80" annual: "£60"
collaborator: collaborator:
monthly: "£15" monthly: "£10"
annual: "£180" annual: "£120"
professional: professional:
monthly: "£30" monthly: "£22"
annual: "£360" annual: "£264"
App.controller "PlansController", ($scope, $modal, event_tracking, abTestManager, MultiCurrencyPricing) ->
buckets = [
{ bucketName:"30d", queryString: "_free_trial", trial_len:30 }
{ bucketName:"14d", queryString: "_free_trial_14_days", trial_len:14 }
]
bucket = abTestManager.getABTestBucket "trial_len", buckets
$scope.trial_len = bucket.trial_len
$scope.planQueryString = bucket.queryString
$scope.ui =
view: "monthly"
$scope.plans = MultiCurrencyPricing.plans
$scope.currencyCode = MultiCurrencyPricing.currencyCode
$scope.changeCurreny = (newCurrency)-> $scope.changeCurreny = (newCurrency)->
$scope.currencyCode = newCurrency $scope.currencyCode = newCurrency

View file

@ -1,9 +1,19 @@
define [ define [
"base" "base"
], (App)-> ], (App)->
MESSAGES_URL = "/user/subscription/update" SUBSCRIPTION_URL = "/user/subscription/update"
App.controller "ChangePlanFormController", ($scope, $modal)->
App.controller "CurrenyDropdownController", ($scope, MultiCurrencyPricing)->
$scope.plans = MultiCurrencyPricing.plans
$scope.currencyCode = MultiCurrencyPricing.currencyCode
$scope.changeCurreny = (newCurrency)->
MultiCurrencyPricing.currencyCode = newCurrency
App.controller "ChangePlanFormController", ($scope, $modal, MultiCurrencyPricing)->
$scope.changePlan = -> $scope.changePlan = ->
$modal.open( $modal.open(
@ -12,6 +22,14 @@ define [
scope: $scope scope: $scope
) )
$scope.$watch "pricing.currencyCode", ->
$scope.currencyCode = MultiCurrencyPricing.currencyCode
$scope.pricing = MultiCurrencyPricing
$scope.plans = MultiCurrencyPricing.plans
$scope.currencyCode = MultiCurrencyPricing.currencyCode
@ -25,7 +43,7 @@ define [
$scope.inflight = true $scope.inflight = true
$http.post(MESSAGES_URL, body) $http.post(SUBSCRIPTION_URL, body)
.success -> .success ->
location.reload() location.reload()
.error -> .error ->