discourse/app/assets/javascripts/admin/models/flagged_post.js.coffee

82 lines
1.7 KiB
CoffeeScript
Raw Normal View History

2013-02-05 14:16:51 -05:00
window.Discourse.FlaggedPost = Discourse.Post.extend
flaggers: (->
r = []
@post_actions.each (a)=>
r.push(@userLookup[a.user_id])
r
).property()
messages: (->
r = []
@post_actions.each (a)=>
if a.message
r.push
user: @userLookup[a.user_id]
message: a.message
r
).property()
2013-02-07 10:45:24 -05:00
2013-02-05 14:16:51 -05:00
lastFlagged: (->
@post_actions[0].created_at
).property()
user: (->
@userLookup[@user_id]
).property()
topicHidden: (->
@get('topic_visible') == 'f'
).property('topic_hidden')
deletePost: ->
promise = new RSVP.Promise()
if @get('post_number') == "1"
$.ajax "/t/#{@topic_id}",
type: 'DELETE'
cache: false
success: ->
promise.resolve()
error: (e)->
promise.reject()
else
$.ajax "/posts/#{@id}",
type: 'DELETE'
cache: false
success: ->
promise.resolve()
error: (e)->
promise.reject()
2013-02-05 14:16:51 -05:00
clearFlags: ->
promise = new RSVP.Promise()
$.ajax "/admin/flags/clear/#{@id}",
type: 'POST'
cache: false
success: ->
promise.resolve()
error: (e)->
promise.reject()
promise
hiddenClass: (->
"hidden-post" if @get('hidden') == "t"
).property()
window.Discourse.FlaggedPost.reopenClass
findAll: (filter) ->
result = Em.A()
$.ajax
url: "/admin/flags/#{filter}.json"
success: (data) ->
userLookup = {}
data.users.each (u) -> userLookup[u.id] = Discourse.User.create(u)
data.posts.each (p) ->
f = Discourse.FlaggedPost.create(p)
f.userLookup = userLookup
result.pushObject(f)
result