2014-11-28 20:49:41 -05:00
|
|
|
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'
|
2014-12-03 19:11:46 -05:00
|
|
|
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
|
|
|
|
|
2014-12-03 19:11:46 -05:00
|
|
|
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)
|
2014-12-03 22:43:57 -05:00
|
|
|
@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
|
2014-12-03 19:11:46 -05:00
|
|
|
c.subscribed = me.get('stripe')?.planID
|
|
|
|
c.active = me.get('stripe')?.subscriptionID
|
|
|
|
c
|
|
|
|
|
|
|
|
onClickStartSubscription: (e) ->
|
|
|
|
@openModalView new SubscribeModal()
|
2014-12-04 17:23:43 -05:00
|
|
|
window.tracker?.trackEvent 'Show subscription modal', category: 'Subscription', label: 'payments view'
|
2014-12-05 00:14:22 -05:00
|
|
|
window.tracker?.trackPageView "subscription/show-modal", ['Google Analytics']
|
2014-12-03 19:11:46 -05:00
|
|
|
|
|
|
|
onSubscribed: ->
|
|
|
|
document.location.reload()
|
|
|
|
|
|
|
|
onClickEndSubscription: (e) ->
|
2014-12-05 17:11:38 -05:00
|
|
|
stripe = _.clone(me.get('stripe'))
|
2014-12-03 19:11:46 -05:00
|
|
|
delete stripe.planID
|
2014-12-05 17:11:38 -05:00
|
|
|
me.set('stripe', stripe)
|
|
|
|
me.patch({headers: {'X-Change-Plan': 'true'}})
|
2014-12-03 19:11:46 -05:00
|
|
|
@listenToOnce me, 'sync', -> document.location.reload()
|