Here's my component:
payment-history.coffee
`import Ember from 'ember'`
PaymentHistoryComponent = Ember.Component.extend({
years:
current:
value: 20
#value: moment().year()
selected: ()->
this.value == @get('years.active.value')
next:
value: 25
#value: moment().year() + 1
selected: ()->
this.value == @get('years.active.value')
active:
value: 19
#value: moment().year()
claimsByYear: Ember.computed('years.active.value', ->
self = this
@get('payments').filter((payment) ->
payment.datePaid.indexOf(self.get('years.active.value')) > -1
)
)
actions:
showYear: (year)->
@set('years.active.value', year)
})
`export default PaymentHistoryComponent`
Here's my template:
payment-history.hbs
<button {{ action 'showYear' years.current.value }} class='button {{ if year.current.selected '' 'secondary'}}'>
{{ t 'payBills.paymentHistory1' }} {{ years.current.value }} {{ t 'payBills.paymentHistory2'}}
</button>
<button {{ action 'showYear' years.next.value }} class='button {{ if selected '' 'secondary'}}'>
{{ t 'payBills.paymentHistory1' }} {{ years.next.value }} {{ t 'payBills.paymentHistory2'}}
</button>
<table class="tabular-data">
<tbody>
{{#each claimsByYear as |payment|}}
<tr>
<td class="date-paid">
<span class="label">{{ t 'claims.payments.makePayment.datePaid' }}</span>
<strong>{{format-date payment.datePaid 'L'}}</strong>
</td>
<td>
<span class="label">{{ t 'claims.payments.makePayment.amountPaid' }}</span>
<strong>{{currency payment.amountPaid 2}}</strong>
</td>
</tr>
{{/each}}
</tbody>
</table>
Note that there are two buttons. I'd like to apply a class of secondary to a button if it is not currently selected. I've tried changing the selected attribute of the years models based on whether a given year is selected, but nothing has worked. I can't upgrade to a newer version of Ember, either, so I need to figure out how to do this in version 1.13. Does anyone know of a possible solution?