mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-02-17 00:40:56 -05:00
Lightweight invoice purchases show description on PaymentsView
This commit is contained in:
parent
6916de6c8b
commit
3ad395ecb8
5 changed files with 40 additions and 8 deletions
7
app/collections/Payments.coffee
Normal file
7
app/collections/Payments.coffee
Normal file
|
@ -0,0 +1,7 @@
|
|||
Payment = require 'models/Payment'
|
||||
CocoCollection = require 'collections/CocoCollection'
|
||||
|
||||
module.exports = class Payments extends CocoCollection
|
||||
model: Payment
|
||||
url: '/db/payment'
|
||||
|
|
@ -10,7 +10,8 @@ block content
|
|||
a(href="/account", data-i18n="nav.account")
|
||||
li.active(data-i18n="account.payments")
|
||||
|
||||
if view.payments.models.length
|
||||
- console.log('render', view.payments.size())
|
||||
if view.payments.size()
|
||||
table.table.table-striped
|
||||
tr
|
||||
th(data-i18n="account.purchased")
|
||||
|
@ -21,7 +22,9 @@ block content
|
|||
for payment in view.payments.models
|
||||
- var service = payment.get('service')
|
||||
tr
|
||||
if payment.get('productID')
|
||||
if payment.get('productID') === 'custom'
|
||||
td= payment.get('description')
|
||||
else if payment.get('productID')
|
||||
td(data-i18n='account.gems')
|
||||
else
|
||||
td(data-i18n='subscribe.stripe_description')
|
||||
|
@ -32,4 +35,4 @@ block content
|
|||
else
|
||||
td(data-i18n="account.service_web")
|
||||
td $#{(payment.get('amount')/100).toFixed(2)}
|
||||
td= payment.get('gems')
|
||||
td= payment.get('gems') || '-'
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
RootView = require 'views/core/RootView'
|
||||
template = require 'templates/account/payments-view'
|
||||
CocoCollection = require 'collections/CocoCollection'
|
||||
Payment = require 'models/Payment'
|
||||
Payments = require 'collections/Payments'
|
||||
|
||||
module.exports = class PaymentsView extends RootView
|
||||
id: "payments-view"
|
||||
template: template
|
||||
|
||||
constructor: (options) ->
|
||||
super(options)
|
||||
@payments = new CocoCollection([], { url: '/db/payment', model: Payment, comparator:'_id' })
|
||||
@supermodel.loadCollection(@payments, 'payments', {cache: false})
|
||||
initialize: ->
|
||||
@payments = new Payments()
|
||||
@supermodel.trackRequest(@payments.fetch({cache: false}))
|
||||
|
|
|
@ -140,6 +140,13 @@ module.exports = {
|
|||
name: _.string.humanize(_id)
|
||||
}, attrs)
|
||||
return new ThangType(attrs)
|
||||
|
||||
makePayment: (attrs, sources={}) ->
|
||||
_id = _.uniqueId('payment_')
|
||||
attrs = _.extend({}, {
|
||||
_id
|
||||
}, attrs)
|
||||
return new ThangType(attrs)
|
||||
|
||||
}
|
||||
|
||||
|
|
16
test/app/views/account/PaymentsView.spec.coffee
Normal file
16
test/app/views/account/PaymentsView.spec.coffee
Normal file
|
@ -0,0 +1,16 @@
|
|||
PaymentsView = require 'views/account/PaymentsView'
|
||||
Payments = require 'collections/Payments'
|
||||
factories = require 'test/app/factories'
|
||||
|
||||
describe 'PaymentsView', ->
|
||||
|
||||
it 'displays the payment "description" if the payment\'s productID is "custom"', ->
|
||||
view = new PaymentsView()
|
||||
payment = factories.makePayment({productID: 'custom', description: 'Custom Description' })
|
||||
view.payments.fakeRequests[0].respondWith({
|
||||
status: 200
|
||||
responseText: new Payments([payment]).stringify()
|
||||
})
|
||||
view.render()
|
||||
expect(_.contains(view.$el.text(), 'Custom Description')).toBe(true)
|
||||
jasmine.demoEl(view.$('#site-content-area'))
|
Loading…
Reference in a new issue