2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Our data model for interacting with flagged posts.
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-03-05 15:39:21 -05:00
|
|
|
@class FlaggedPost
|
2013-02-22 15:41:12 -05:00
|
|
|
@extends Discourse.Post
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-05 15:39:21 -05:00
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.FlaggedPost = Discourse.Post.extend({
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-05-20 15:27:58 -04:00
|
|
|
flaggers: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
|
|
|
this.post_actions.each(function(a) {
|
|
|
|
return r.push(_this.userLookup[a.user_id]);
|
|
|
|
});
|
|
|
|
return r;
|
2013-05-20 15:27:58 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-05-20 15:27:58 -04:00
|
|
|
messages: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
|
|
|
this.post_actions.each(function(a) {
|
|
|
|
if (a.message) {
|
|
|
|
return r.push({
|
|
|
|
user: _this.userLookup[a.user_id],
|
2013-05-09 03:37:34 -04:00
|
|
|
message: a.message,
|
|
|
|
permalink: a.permalink
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return r;
|
2013-05-20 15:27:58 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
lastFlagged: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.post_actions[0].created_at;
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
user: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.userLookup[this.user_id];
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
topicHidden: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.get('topic_visible') === 'f';
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property('topic_hidden'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
deletePost: function() {
|
|
|
|
if (this.get('post_number') === "1") {
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/t/" + this.topic_id, { type: 'DELETE', cache: false });
|
2013-02-22 15:41:12 -05:00
|
|
|
} else {
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/posts/" + this.id, { type: 'DELETE', cache: false });
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
clearFlags: function() {
|
2013-05-07 13:30:12 -04:00
|
|
|
return Discourse.ajax("/admin/flags/clear/" + this.id, { type: 'POST', cache: false });
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
hiddenClass: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
if (this.get('hidden') === "t") return "hidden-post";
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property()
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.FlaggedPost.reopenClass({
|
|
|
|
findAll: function(filter) {
|
2013-04-03 16:06:55 -04:00
|
|
|
var result = Em.A();
|
2013-06-05 10:24:50 -04:00
|
|
|
result.set('loading', true);
|
2013-05-07 13:30:12 -04:00
|
|
|
Discourse.ajax("/admin/flags/" + filter + ".json").then(function(data) {
|
2013-04-03 16:06:55 -04:00
|
|
|
var userLookup = {};
|
|
|
|
data.users.each(function(u) {
|
|
|
|
userLookup[u.id] = Discourse.User.create(u);
|
|
|
|
});
|
|
|
|
data.posts.each(function(p) {
|
|
|
|
var f = Discourse.FlaggedPost.create(p);
|
|
|
|
f.userLookup = userLookup;
|
|
|
|
result.pushObject(f);
|
|
|
|
});
|
2013-06-05 10:24:50 -04:00
|
|
|
result.set('loading', false);
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-20 13:15:50 -05:00
|
|
|
|