codecombat/app/views/account/PaymentsView.coffee

41 lines
1.2 KiB
CoffeeScript
Raw Normal View History

RootView = require 'views/core/RootView'
2014-11-25 14:09:29 -05:00
template = require 'templates/account/payments-view'
CocoCollection = require 'collections/CocoCollection'
Payment = require 'models/Payment'
SubscribeModal = require 'views/play/modal/SubscribeModal'
2014-11-25 14:09:29 -05:00
module.exports = class PaymentsView extends RootView
id: "payments-view"
template: template
events:
'click .start-subscription-button': 'onClickStartSubscription'
'click .end-subscription-button': 'onClickEndSubscription'
subscriptions:
'subscribe-modal:subscribed': 'onSubscribed'
2014-11-25 14:09:29 -05:00
constructor: (options) ->
super(options)
@payments = new CocoCollection([], { url: '/db/payment', model: Payment, comparator:'_id' })
2014-11-25 14:09:29 -05:00
@supermodel.loadCollection(@payments, 'payments')
getRenderData: ->
c = super()
c.payments = @payments
c.subscribed = me.get('stripe')?.planID
c.active = me.get('stripe')?.subscriptionID
c
onClickStartSubscription: (e) ->
@openModalView new SubscribeModal()
onSubscribed: ->
document.location.reload()
onClickEndSubscription: (e) ->
stripe = me.get('stripe')
delete stripe.planID
me.save()
@listenToOnce me, 'sync', -> document.location.reload()