Give regular users a delete button. If they click it, their post will be revised to

say it was deleted.
This commit is contained in:
Robin Ward
2013-02-07 15:12:55 -05:00
parent af11547108
commit 084a873b91
16 changed files with 183 additions and 34 deletions

View File

@@ -155,7 +155,9 @@ Discourse.Utilities =
# Takes raw input and cooks it to display nicely (mostly markdown)
cook: (raw, opts) ->
cook: (raw, opts=null) ->
opts ||= {}
# Make sure we've got a string
return "" unless raw

View File

@@ -299,14 +299,15 @@ Discourse.TopicController = Ember.ObjectController.extend Discourse.Presence,
@get('controllers.modal')?.show(view)
false
recoverPost: (post) ->
post.set('deleted_at', null)
post.recover()
deletePost: (post) ->
deleted = !!post.get('deleted_at')
if deleted
post.set('deleted_at', null)
if post.get('user_id') is Discourse.get('currentUser.id')
post.set('cooked', Discourse.Utilities.cook(Em.String.i18n("post.deleted_by_author")))
post.set('can_delete', false)
else
post.set('deleted_at', new Date())
post.delete =>
# nada
post.delete()

View File

@@ -153,8 +153,11 @@ window.Discourse.Post = Ember.Object.extend Discourse.Presence,
error: (result) -> error?(result)
recover: ->
$.ajax "/posts/#{@get('id')}/recover", type: 'PUT', cache: false
delete: (complete) ->
$.ajax "/posts/#{@get('id')}", type: 'DELETE', success: (result) -> complete()
$.ajax "/posts/#{@get('id')}", type: 'DELETE', success: (result) -> complete?()
# Update the properties of this post from an obj, ignoring cooked as we should already
# have that rendered.

View File

@@ -26,7 +26,7 @@ window.Discourse.PostMenuView = Ember.View.extend Discourse.Presence,
# Trigger re rendering
needsToRender: (->
@rerender()
).observes('post.deleted_at', 'post.flagsAvailable.@each', 'post.url', 'post.bookmarked', 'post.reply_count', 'post.replyBelowUrl')
).observes('post.deleted_at', 'post.flagsAvailable.@each', 'post.url', 'post.bookmarked', 'post.reply_count', 'post.replyBelowUrl', 'post.can_delete')
# Replies Button
renderReplies: (post, buffer) ->
@@ -49,11 +49,14 @@ window.Discourse.PostMenuView = Ember.View.extend Discourse.Presence,
# Delete button
renderDelete: (post, buffer) ->
return unless post.get('can_delete')
title = if post.get('deleted_at') then Em.String.i18n("post.controls.undelete") else Em.String.i18n("post.controls.delete")
buffer.push("<button title=\"#{title}\" data-action=\"delete\"><i class=\"icon-trash\"></i></button>")
if post.get('deleted_at')
if post.get('can_recover')
buffer.push("<button title=\"#{Em.String.i18n("post.controls.undelete")}\" data-action=\"recover\"><i class=\"icon-undo\"></i></button>")
else if post.get('can_delete')
buffer.push("<button title=\"#{Em.String.i18n("post.controls.delete")}\" data-action=\"delete\"><i class=\"icon-trash\"></i></button>")
clickRecover: -> @get('controller').recoverPost(@get('post'))
clickDelete: -> @get('controller').deletePost(@get('post'))
# Like button