diff --git a/services/web/app/views/subscriptions/dashboard.jade b/services/web/app/views/subscriptions/dashboard.jade index 06f801a143..d85be3f9e3 100644 --- a/services/web/app/views/subscriptions/dashboard.jade +++ b/services/web/app/views/subscriptions/dashboard.jade @@ -6,7 +6,7 @@ block scripts window.recomendedCurrency = '#{recomendedCurrency}' window.recurlyApiKey = "!{settings.apis.recurly.publicKey}" window.taxRate = #{taxRate} - + window.subscription = !{JSON.stringify(subscription)} @@ -36,11 +36,11 @@ mixin printPlans(plans) mixin printPlan(plan) block content - .content.content-alt - .container + .content.content-alt(ng-cloak) + .container(ng-controller="UserSubscriptionController") .row - .col-md-8.col-md-offset-2 - .card + .col-md-8.col-md-offset-2 {{view}} + .card(ng-if="view == 'overview'") .page-header h1 #{translate("your_subscription")} -if (groups.length != 0) @@ -56,12 +56,10 @@ block content a(href, ng-click="changePlan = true") !{translate("change_plan")}. p !{translate("next_payment_of_x_collectected_on_y", {paymentAmmount:"" + subscription.price + "", collectionDate:"" + subscription.nextPaymentDueAt + ""})} p.pull-right - - p: form(action="/user/subscription/cancel",method="post") - input(type="hidden", name="_csrf", value=csrfToken) + p a(href="/user/subscription/billing-details/edit").btn.btn-info #{translate("update_your_billing_details")} - |   - input(type="submit", value="Cancel your subscription").btn.btn-primary#cancelSubscription + p + a(href, ng-click="switchToCancelationView()").btn.btn-success !{translate("cancel_your_subscription")} when "canceled" p !{translate("currently_subscribed_to_plan", {planName:"" + subscription.name + ""})} p !{translate("subscription_canceled_and_terminate_on_x", {terminateDate:"" + subscription.nextPaymentDueAt + ""})} @@ -76,7 +74,7 @@ block content p !{translate("problem_with_subscription_contact_us")} -if(subscription.groupPlan) - a(href="/subscription/group").btn.btn-success !{translate("manage_group")} + a(href="/subscription/group").btn.btn-primary !{translate("manage_group")} @@ -107,6 +105,17 @@ block content + .card(ng-if="view == 'cancelation'") + .page-header + h1 #{translate("Cancel Subscription")} + div(ng-show="isMonthlyCollab") + span(ng-controller="ChangePlanFormController") downgrade to student for {{studentPrice}} + button(type="submit", ng-click="downgradeToStudent()", ng-disabled='inflight').btn.btn-success #{translate("change_to_this_plan")} + + div(ng-if="!isMonthlyCollab") + form(action="/user/subscription/cancel",method="post") + input(type="hidden", name="_csrf", value=csrfToken) + input(type="submit", value="Cancel your subscription").btn.btn-primary#cancelSubscription script(type="text/javascript"). $('#cancelSubscription').on("click", function() { ga('send', 'event', 'subscription-funnel', 'cancelation') diff --git a/services/web/public/coffee/main/subscription-dashboard.coffee b/services/web/public/coffee/main/subscription-dashboard.coffee index 5cf436fa9d..02c2fbdf5a 100644 --- a/services/web/public/coffee/main/subscription-dashboard.coffee +++ b/services/web/public/coffee/main/subscription-dashboard.coffee @@ -5,7 +5,7 @@ define [ setupReturly = _.once -> recurly?.configure window.recurlyApiKey - + PRICES = {} App.controller "CurrenyDropdownController", ($scope, MultiCurrencyPricing, $q)-> @@ -18,7 +18,7 @@ define [ App.controller "ChangePlanFormController", ($scope, $modal, MultiCurrencyPricing)-> setupReturly() - + console.log("init") taxRate = window.taxRate $scope.changePlan = -> @@ -37,10 +37,11 @@ define [ $scope.currencyCode = MultiCurrencyPricing.currencyCode - $scope.prices = {} + $scope.prices = PRICES $scope.refreshPrice = (planCode)-> if $scope.prices[planCode]? return + $scope.prices[planCode] = "..." pricing = recurly.Pricing() pricing.plan(planCode, { quantity: 1 }).currency(MultiCurrencyPricing.currencyCode).done (price)-> totalPriceExTax = parseFloat(price.next.total) @@ -71,4 +72,34 @@ define [ console.log "something went wrong changing plan" $scope.cancel = () -> - $modalInstance.dismiss('cancel') \ No newline at end of file + $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" \ No newline at end of file