mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user