improving flag handling, links and delete button

This commit is contained in:
Sam Saffron 2013-02-07 16:00:40 +11:00
parent c7461622a9
commit 7b123e12dd
5 changed files with 34 additions and 8 deletions

View file

@ -7,6 +7,13 @@ window.Discourse.AdminFlagsController = Ember.Controller.extend
bootbox.alert("something went wrong")
)
deletePost: (item) ->
item.deletePost().then (=>
@content.removeObject(item)
), (->
bootbox.alert("something went wrong")
)
adminOldFlagsView: (->
@query == 'old'
).property('query')

View file

@ -28,6 +28,25 @@ window.Discourse.FlaggedPost = Discourse.Post.extend
@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()
clearFlags: ->
promise = new RSVP.Promise()
$.ajax "/admin/flags/clear/#{@id}",

View file

@ -21,14 +21,15 @@
<tbody>
{{#each content}}
<tr {{bindAttr class="hiddenClass"}}>
<td class='user'>{{avatar user imageSize="small"}}</td>
<td class='user'><a href="/admin{{unbound user.path}}">{{avatar user imageSize="small"}}</a></td>
<td class='excerpt'>{{#if topicHidden}}<i title='this topic is invisible' class='icon icon-eye-close'></i> {{/if}}<h3><a href='{{unbound url}}'>{{title}}</a></h3><br>{{{excerpt}}}
</td>
<td class='flaggers'>{{#each flaggers}}{{avatar this imageSize="small"}}{{/each}}</td>
<td class='flaggers'>{{#each flaggers}}<a href="/admin{{unbound path}}">{{avatar this imageSize="small"}}</a>{{/each}}</td>
<td class='last-flagged'>{{date lastFlagged}}</td>
<td class='action'>
{{#if controller.adminActiveFlagsView}}
<button title='dismiss all flags on this post (will unhide hidden posts)' class='btn' {{action clearFlags this}}>Clear Flags</button>
<button title='{{i18n admin.flags.clear_title}}' class='btn' {{action clearFlags this}}>{{i18n admin.flags.clear}}</button>
<button title='{{i18n admin.flags.delete_title}}' class='btn' {{action deletePost this}}>{{i18n admin.flags.delete}}</button>
{{/if}}
</td>
</tr>

View file

@ -314,6 +314,10 @@ en:
title: "Flags"
old: "Old"
active: "Active"
clear: "Clear Flags"
clear_title: "dismiss all flags on this post (will unhide hidden posts)"
delete: "Delete Post"
delete_title: "delete post (if its the first post delete topic)"
customize:
title: "Customize"

View file

@ -63,15 +63,10 @@ describe Post do
post = Fabricate(:post)
user = Fabricate(:coding_horror)
PostAction.act(user, post, PostActionType.Types[:off_topic])
PostAction.act(post.user, post, PostActionType.Types[:spam])
post.reload
post.is_flagged?.should == true
PostAction.remove_act(post.user, post, PostActionType.Types[:spam])
post.reload
post.is_flagged?.should == true
PostAction.remove_act(user, post, PostActionType.Types[:off_topic])
post.reload
post.is_flagged?.should == false