/app/client/comment.coffee
CoffeeScript | 50 lines | 40 code | 9 blank | 1 comment | 1 complexity | 1623e672b5da7a178d6858bc9e5c7a1c MD5 | raw file
- # Comment, CommentView, CommentList
- exports.Comment = Backbone.Model.extend(defaults: ->
- ??d: 0
- name: "donkey"
- image: "http://graph.facebook.com/219012/picture"
- user: "noUserId"
- to_user: "Marius"
- round_id: ""
- answer_id: ""
- content: "dzad azd zad "
- date: new Date
- score: 0
- mine: false
- )
- exports.CommentView = Backbone.View.extend(
- tagName: "li"
- template: _.template($("#comment-template").html())
- events:
- "click .rateComment": "rateComment"
-
- initialize: ->
- _.bindAll this, "render", "clear", "rateComment", "updateScore"
- @model.bind "clear", @clear
- @model.bind "change:score", @updateScore
- render: ->
- $(@el).html @template(@model.toJSON())
- this
-
- clear: ->
- @remove()
-
- rateComment: ->
- n = $('#nbrVotesComment span').text()
- if 1*n > 0 then $('#nbrVotesComment span').text(-1+1*n)
- rate =
- comment_id: @model.get("id")
- answer_id: @model.get("answer_id")
- round_id: @model.get("round_id")
- rated_user: @model.get("user")
- SS.server.app.rateComment rate, myChannel, (response) -> SS.client.app.displayFlash response
-
- updateScore: ->
- this.$('.scoreComment').html @model.get("score")
- )
- exports.CommentList = Backbone.Collection.extend(model: Comment)