MeteorBCN #6

ViewModel

Template Html



          

Template Controller


            rating = new ReactiveVar 0

Template.rating.onCreated ->
  @subscribe 'chats'

Template.rating.helpers
  stars: ->
    for i in [1..5]
      index: i
      clazz: if i <= rating.get() then 'rated'

Template.rating.events
  'click .stars span': (event, template) ->
    rating.set event.currentTarget.dataset.no
  'click .update': (event, template) ->
    chatId = Router.getQueryParam('chatId')
    Meteor.call 'rateChat', chatId, rating.get()
    Router.go '/'