2014-11-12 12:40:55 -05:00
|
|
|
ModalView = require 'views/kinds/ModalView'
|
|
|
|
template = require 'templates/play/modal/buy-gems-modal'
|
|
|
|
|
|
|
|
module.exports = class BuyGemsModal extends ModalView
|
|
|
|
id: 'buy-gems-modal'
|
|
|
|
template: template
|
|
|
|
plain: true
|
|
|
|
|
2014-11-12 13:23:43 -05:00
|
|
|
products: [
|
|
|
|
{ price: '$4.99', gems: 5000, id: 'gems_5' }
|
|
|
|
{ price: '$9.99', gems: 11000, id: 'gems_10' }
|
|
|
|
{ price: '$19.99', gems: 25000, id: 'gems_20' }
|
|
|
|
]
|
|
|
|
|
|
|
|
subscriptions:
|
2014-11-12 13:37:09 -05:00
|
|
|
'ipad:products': 'onIPadProducts'
|
2014-11-12 13:23:43 -05:00
|
|
|
'ipad:iap-complete': 'onIAPComplete'
|
2014-11-12 12:40:55 -05:00
|
|
|
|
2014-11-12 13:23:43 -05:00
|
|
|
events:
|
|
|
|
'click button.product': 'onClickProductButton'
|
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super(options)
|
2014-11-12 13:37:09 -05:00
|
|
|
if application.isIPadApp
|
|
|
|
@products = []
|
|
|
|
Backbone.Mediator.publish 'buy-gems-modal:update-products'
|
2014-11-12 13:23:43 -05:00
|
|
|
|
2014-11-12 12:40:55 -05:00
|
|
|
getRenderData: ->
|
|
|
|
c = super()
|
2014-11-12 13:37:09 -05:00
|
|
|
c.products = @products
|
2014-11-12 12:40:55 -05:00
|
|
|
return c
|
|
|
|
|
2014-11-12 13:37:09 -05:00
|
|
|
onIPadProducts: (e) ->
|
|
|
|
@products = e.products
|
|
|
|
@render()
|
2014-11-12 12:40:55 -05:00
|
|
|
|
|
|
|
onClickProductButton: (e) ->
|
|
|
|
productID = $(e.target).closest('button.product').val()
|
2014-11-12 13:37:09 -05:00
|
|
|
console.log 'purchasing', _.find @products, { id: productID }
|
2014-11-12 12:40:55 -05:00
|
|
|
|
|
|
|
if application.isIPadApp
|
2014-11-12 13:23:43 -05:00
|
|
|
Backbone.Mediator.publish 'buy-gems-modal:purchase-initiated', { productID: productID }
|
2014-11-12 12:40:55 -05:00
|
|
|
|
|
|
|
else
|
2014-11-12 13:23:43 -05:00
|
|
|
@$el.find('.modal-body').append($('<div class="alert alert-danger">Not implemented</div>'))
|
|
|
|
|
|
|
|
onIAPComplete: (e) ->
|
|
|
|
purchased = me.get('purchased') ? {}
|
|
|
|
purchased.gems ?= 0
|
|
|
|
purchased.gems += e.gems
|
|
|
|
me.set('purchased', purchased)
|
|
|
|
@hide()
|