Some refactoring, and make possible to remove own comments
parent
9a190cf474
commit
e7f5f57424
@ -0,0 +1,4 @@
|
|||||||
|
class AsciiIo.Views.Base extends Backbone.View
|
||||||
|
|
||||||
|
current_user: ->
|
||||||
|
AsciiIo.current_user
|
@ -1,10 +1,28 @@
|
|||||||
class AsciiIo.Views.CommentEntry extends Backbone.View
|
class AsciiIo.Views.CommentEntry extends AsciiIo.Views.Base
|
||||||
|
|
||||||
template: JST['backbone/templates/comments/show']
|
template: JST['backbone/templates/comments/show']
|
||||||
tagName: 'li'
|
tagName: 'li'
|
||||||
className: 'comment'
|
className: 'comment'
|
||||||
|
|
||||||
render: ->
|
events:
|
||||||
$(@el).html(@template(@model.toJSON()))
|
'click .remove': 'removeComment'
|
||||||
|
|
||||||
|
initialize:(options) ->
|
||||||
|
@collection = options.collection
|
||||||
|
|
||||||
|
render: ->
|
||||||
|
context = _.extend(@model.toJSON(), { show_remove_link: @showRemoveLink() })
|
||||||
|
$(@el).html @template(context)
|
||||||
this
|
this
|
||||||
|
|
||||||
|
showRemoveLink: ->
|
||||||
|
@current_user() && ( @current_user().id == @model.user().id )
|
||||||
|
|
||||||
|
removeComment: (event) ->
|
||||||
|
event.preventDefault()
|
||||||
|
@model.destroy
|
||||||
|
wait: true
|
||||||
|
success: =>
|
||||||
|
$(this.el).slideUp("slow", =>
|
||||||
|
this.remove()
|
||||||
|
)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
jQuery(document).ready(function(){
|
jQuery(document).ready(function(){
|
||||||
AsciiIo.current_user = <%= raw current_user.to_json(:only => [:nickname, :avatar_url]) %>;
|
AsciiIo.current_user = <%= raw current_user.to_json(:only => [:id, :nickname, :avatar_url]) %>;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue