PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/app/client/comment.coffee

https://bitbucket.org/pierroweb/learn-addict
CoffeeScript | 50 lines | 40 code | 9 blank | 1 comment | 1 complexity | 1623e672b5da7a178d6858bc9e5c7a1c MD5 | raw file
  1. # Comment, CommentView, CommentList
  2. exports.Comment = Backbone.Model.extend(defaults: ->
  3. ??d: 0
  4. name: "donkey"
  5. image: "http://graph.facebook.com/219012/picture"
  6. user: "noUserId"
  7. to_user: "Marius"
  8. round_id: ""
  9. answer_id: ""
  10. content: "dzad azd zad "
  11. date: new Date
  12. score: 0
  13. mine: false
  14. )
  15. exports.CommentView = Backbone.View.extend(
  16. tagName: "li"
  17. template: _.template($("#comment-template").html())
  18. events:
  19. "click .rateComment": "rateComment"
  20. initialize: ->
  21. _.bindAll this, "render", "clear", "rateComment", "updateScore"
  22. @model.bind "clear", @clear
  23. @model.bind "change:score", @updateScore
  24. render: ->
  25. $(@el).html @template(@model.toJSON())
  26. this
  27. clear: ->
  28. @remove()
  29. rateComment: ->
  30. n = $('#nbrVotesComment span').text()
  31. if 1*n > 0 then $('#nbrVotesComment span').text(-1+1*n)
  32. rate =
  33. comment_id: @model.get("id")
  34. answer_id: @model.get("answer_id")
  35. round_id: @model.get("round_id")
  36. rated_user: @model.get("user")
  37. SS.server.app.rateComment rate, myChannel, (response) -> SS.client.app.displayFlash response
  38. updateScore: ->
  39. this.$('.scoreComment').html @model.get("score")
  40. )
  41. exports.CommentList = Backbone.Collection.extend(model: Comment)