discourse/app/assets/javascripts/admin/controllers/admin_flags_controller.js

100 lines
2.5 KiB
JavaScript
Raw Normal View History

/**
This controller supports the interface for dealing with flags in the admin section.
@class AdminFlagsController
@extends Ember.Controller
@namespace Discourse
@module Discourse
**/
Discourse.AdminFlagsController = Ember.ArrayController.extend({
2013-09-16 14:08:55 -04:00
actions: {
/**
Clear all flags on a post
2013-09-16 14:08:55 -04:00
@method clearFlags
@param {Discourse.FlaggedPost} item The post whose flags we want to clear
**/
disagreeFlags: function(item) {
var adminFlagsController = this;
item.disagreeFlags().then((function() {
adminFlagsController.removeObject(item);
}), function() {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
2013-09-16 14:08:55 -04:00
agreeFlags: function(item) {
var adminFlagsController = this;
item.agreeFlags().then((function() {
adminFlagsController.removeObject(item);
}), function() {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
2013-09-16 14:08:55 -04:00
deferFlags: function(item) {
var adminFlagsController = this;
item.deferFlags().then((function() {
adminFlagsController.removeObject(item);
}), function() {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
2014-02-05 17:54:16 -05:00
doneTopicFlags: function(item) {
this.send('disagreeFlags', item);
},
2013-09-16 14:08:55 -04:00
/**
Deletes a post
2013-09-16 14:08:55 -04:00
@method deletePost
@param {Discourse.FlaggedPost} post The post to delete
2013-09-16 14:08:55 -04:00
**/
deletePost: function(post) {
2013-09-16 14:08:55 -04:00
var adminFlagsController = this;
post.deletePost().then((function() {
adminFlagsController.removeObject(post);
2013-09-16 14:08:55 -04:00
}), function() {
bootbox.alert(I18n.t("admin.flags.error"));
});
},
2013-09-16 14:08:55 -04:00
/**
Deletes a user and all posts and topics created by that user.
2013-09-16 14:08:55 -04:00
@method deleteSpammer
@param {Discourse.FlaggedPost} item The post to delete
**/
deleteSpammer: function(item) {
item.get('user').deleteAsSpammer(function() { window.location.reload(); });
}
},
/**
Are we viewing the 'old' view?
@property adminOldFlagsView
**/
adminOldFlagsView: Em.computed.equal('query', 'old'),
/**
Are we viewing the 'active' view?
@property adminActiveFlagsView
**/
adminActiveFlagsView: Em.computed.equal('query', 'active'),
loadMore: function(){
var flags = this.get('model');
return Discourse.FlaggedPost.findAll(this.get('query'),flags.length+1).then(function(data){
if(data.length===0){
flags.set('allLoaded',true);
}
flags.addObjects(data);
});
}
});