Some fixes for loading iPad gem products.

This commit is contained in:
Nick Winter 2014-11-12 20:21:14 -08:00
parent ed8285248f
commit 4fe6fd3020

View file

@ -5,17 +5,17 @@ module.exports = class BuyGemsModal extends ModalView
id: 'buy-gems-modal'
template: template
plain: true
products: [
originalProducts: [
{ price: '$4.99', gems: 5000, id: 'gems_5', i18n: 'buy_gems.few_gems' }
{ price: '$9.99', gems: 11000, id: 'gems_10', i18n: 'buy_gems.pile_gems' }
{ price: '$19.99', gems: 25000, id: 'gems_20', i18n: 'buy_gems.chest_gems' }
]
subscriptions:
'ipad:products': 'onIPadProducts'
'ipad:iap-complete': 'onIAPComplete'
events:
'click .product button': 'onClickProductButton'
@ -23,34 +23,36 @@ module.exports = class BuyGemsModal extends ModalView
super(options)
if application.isIPadApp
@products = []
Backbone.Mediator.publish 'buy-gems-modal:update-products'
Backbone.Mediator.publish 'buy-gems-modal:update-products'
else
@products = @originalProducts
getRenderData: ->
c = super()
c.products = @products
return c
onIPadProducts: (e) ->
newProducts = []
for iapProduct in e.products
localProduct = _.find @products, { id: iapProduct.id }
localProduct = _.find @originalProducts, { id: iapProduct.id }
continue unless localProduct
localProduct.price = iapProduct.price
newProducts.push localProduct
@products = newProducts
@products = _.sortBy newProducts, 'gems'
@render()
onClickProductButton: (e) ->
productID = $(e.target).closest('button.product').val()
console.log 'purchasing', _.find @products, { id: productID }
if application.isIPadApp
Backbone.Mediator.publish 'buy-gems-modal:purchase-initiated', { productID: productID }
else
application.tracker?.trackEvent 'Started purchase', {productID:productID}, ['Google Analytics']
alert('Not yet implemented, but thanks for trying!')
onIAPComplete: (e) ->
product = _.find @products, { id: e.productID }
purchased = me.get('purchased') ? {}
@ -58,4 +60,4 @@ module.exports = class BuyGemsModal extends ModalView
purchased.gems ?= 0
purchased.gems += product.gems
me.set('purchased', purchased)
@hide()
@hide()