2013-02-23 04:41:12 +08:00
|
|
|
/**
|
|
|
|
Our data model for interacting with flagged posts.
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2013-03-06 04:39:21 +08:00
|
|
|
@class FlaggedPost
|
2013-02-23 04:41:12 +08:00
|
|
|
@extends Discourse.Post
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-06 04:39:21 +08:00
|
|
|
**/
|
2013-02-23 04:41:12 +08:00
|
|
|
Discourse.FlaggedPost = Discourse.Post.extend({
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-06-17 15:15:56 +08:00
|
|
|
summary: function(){
|
|
|
|
return _(this.post_actions)
|
2013-06-26 14:00:17 +08:00
|
|
|
.groupBy(function(a){ return a.post_action_type_id; })
|
2013-06-17 15:15:56 +08:00
|
|
|
.map(function(v,k){
|
2013-06-26 14:18:50 +08:00
|
|
|
return Em.String.i18n('admin.flags.summary.action_type_' + k, {count: v.length});
|
2013-06-17 15:15:56 +08:00
|
|
|
})
|
2013-06-26 14:18:50 +08:00
|
|
|
.join(',');
|
2013-06-17 15:15:56 +08:00
|
|
|
}.property(),
|
|
|
|
|
2013-05-21 03:27:58 +08:00
|
|
|
flaggers: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
2013-06-11 04:48:50 +08:00
|
|
|
_.each(this.post_actions, function(action) {
|
2013-06-26 15:01:39 +08:00
|
|
|
var user = _this.userLookup[action.user_id];
|
|
|
|
var flagType = Em.String.i18n('admin.flags.summary.action_type_' + action.post_action_type_id, {count: 1});
|
|
|
|
r.push({user: user, flagType: flagType, flaggedAt: action.created_at});
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
return r;
|
2013-05-21 03:27:58 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-05-21 03:27:58 +08:00
|
|
|
messages: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
2013-06-11 04:48:50 +08:00
|
|
|
_.each(this.post_actions,function(action) {
|
|
|
|
if (action.message) {
|
|
|
|
r.push({
|
|
|
|
user: _this.userLookup[action.user_id],
|
|
|
|
message: action.message,
|
|
|
|
permalink: action.permalink
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return r;
|
2013-05-21 03:27:58 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-04-04 04:06:55 +08:00
|
|
|
lastFlagged: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
return this.post_actions[0].created_at;
|
2013-04-04 04:06:55 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-04-04 04:06:55 +08:00
|
|
|
user: function() {
|
2013-02-23 04:41:12 +08:00
|
|
|
return this.userLookup[this.user_id];
|
2013-04-04 04:06:55 +08:00
|
|
|
}.property(),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-04-04 04:06:55 +08:00
|
|
|
topicHidden: function() {
|
2013-06-26 14:00:17 +08:00
|
|
|
return !this.get('topic_visible');
|
2013-04-04 04:06:55 +08:00
|
|
|
}.property('topic_hidden'),
|
2013-02-22 03:09:28 +08:00
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
deletePost: function() {
|
2013-06-26 14:18:50 +08:00
|
|
|
if (this.get('post_number') === '1') {
|
|
|
|
return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
2013-02-23 04:41:12 +08:00
|
|
|
} else {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
2013-02-21 02:15:50 +08:00
|
|
|
}
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2013-06-20 15:42:15 +08:00
|
|
|
disagreeFlags: function() {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
2013-02-23 04:41:12 +08:00
|
|
|
},
|
|
|
|
|
2013-06-20 15:42:15 +08:00
|
|
|
deferFlags: function() {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false });
|
2013-06-20 15:42:15 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
agreeFlags: function() {
|
2013-06-26 14:18:50 +08:00
|
|
|
return Discourse.ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false });
|
2013-06-20 15:42:15 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
postHidden: function() {
|
2013-06-26 14:00:17 +08:00
|
|
|
return (this.get('hidden'));
|
2013-06-20 15:42:15 +08:00
|
|
|
}.property(),
|
|
|
|
|
2013-06-26 14:18:50 +08:00
|
|
|
extraClasses: function() {
|
|
|
|
var classes = [];
|
|
|
|
if (this.get('hidden')) {
|
|
|
|
classes.push('hidden-post');
|
|
|
|
}
|
|
|
|
if (this.get('deleted')){
|
|
|
|
classes.push('deleted');
|
|
|
|
}
|
|
|
|
return classes.join(' ');
|
|
|
|
}.property(),
|
|
|
|
|
|
|
|
deleted: function() {
|
|
|
|
return (this.get('deleted_at') || this.get('topic_deleted_at'));
|
2013-04-04 04:06:55 +08:00
|
|
|
}.property()
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.FlaggedPost.reopenClass({
|
|
|
|
findAll: function(filter) {
|
2013-04-04 04:06:55 +08:00
|
|
|
var result = Em.A();
|
2013-06-05 22:24:50 +08:00
|
|
|
result.set('loading', true);
|
2013-06-26 14:18:50 +08:00
|
|
|
Discourse.ajax('/admin/flags/' + filter + '.json').then(function(data) {
|
2013-04-04 04:06:55 +08:00
|
|
|
var userLookup = {};
|
2013-06-11 04:48:50 +08:00
|
|
|
_.each(data.users,function(user) {
|
|
|
|
userLookup[user.id] = Discourse.User.create(user);
|
2013-04-04 04:06:55 +08:00
|
|
|
});
|
2013-06-11 04:48:50 +08:00
|
|
|
_.each(data.posts,function(post) {
|
|
|
|
var f = Discourse.FlaggedPost.create(post);
|
2013-04-04 04:06:55 +08:00
|
|
|
f.userLookup = userLookup;
|
|
|
|
result.pushObject(f);
|
|
|
|
});
|
2013-06-05 22:24:50 +08:00
|
|
|
result.set('loading', false);
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-21 02:15:50 +08:00
|
|
|
|