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-02-22 15:41:12 -05:00
|
|
|
flaggers: (function() {
|
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
|
|
|
this.post_actions.each(function(a) {
|
|
|
|
return r.push(_this.userLookup[a.user_id]);
|
|
|
|
});
|
|
|
|
return r;
|
|
|
|
}).property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
messages: (function() {
|
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
|
|
|
this.post_actions.each(function(a) {
|
|
|
|
if (a.message) {
|
|
|
|
return r.push({
|
|
|
|
user: _this.userLookup[a.user_id],
|
|
|
|
message: a.message
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return r;
|
|
|
|
}).property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
lastFlagged: (function() {
|
|
|
|
return this.post_actions[0].created_at;
|
|
|
|
}).property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
user: (function() {
|
|
|
|
return this.userLookup[this.user_id];
|
|
|
|
}).property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
topicHidden: (function() {
|
|
|
|
return this.get('topic_visible') === 'f';
|
|
|
|
}).property('topic_hidden'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
deletePost: function() {
|
|
|
|
var promise;
|
|
|
|
promise = new RSVP.Promise();
|
|
|
|
if (this.get('post_number') === "1") {
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/t/" + this.topic_id, {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'DELETE',
|
2013-02-20 13:15:50 -05:00
|
|
|
cache: false,
|
|
|
|
success: function() {
|
2013-02-21 14:09:28 -05:00
|
|
|
promise.resolve();
|
2013-02-20 13:15:50 -05:00
|
|
|
},
|
|
|
|
error: function(e) {
|
2013-02-21 14:09:28 -05:00
|
|
|
promise.reject();
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
} else {
|
2013-03-05 15:39:21 -05:00
|
|
|
return $.ajax("/posts/" + this.id, {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'DELETE',
|
|
|
|
cache: false,
|
|
|
|
success: function() {
|
|
|
|
promise.resolve();
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
promise.reject();
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
clearFlags: function() {
|
|
|
|
var promise;
|
|
|
|
promise = new RSVP.Promise();
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax("/admin/flags/clear/" + this.id, {
|
2013-02-22 15:41:12 -05:00
|
|
|
type: 'POST',
|
|
|
|
cache: false,
|
|
|
|
success: function() {
|
|
|
|
promise.resolve();
|
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
promise.reject();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return promise;
|
|
|
|
},
|
|
|
|
|
|
|
|
hiddenClass: (function() {
|
|
|
|
if (this.get('hidden') === "t") return "hidden-post";
|
|
|
|
}).property()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.FlaggedPost.reopenClass({
|
|
|
|
findAll: function(filter) {
|
|
|
|
var result;
|
|
|
|
result = Em.A();
|
2013-03-05 15:39:21 -05:00
|
|
|
$.ajax({
|
2013-02-22 15:41:12 -05:00
|
|
|
url: "/admin/flags/" + filter + ".json",
|
|
|
|
success: function(data) {
|
|
|
|
var userLookup;
|
|
|
|
userLookup = {};
|
|
|
|
data.users.each(function(u) {
|
|
|
|
userLookup[u.id] = Discourse.User.create(u);
|
|
|
|
});
|
|
|
|
return data.posts.each(function(p) {
|
|
|
|
var f;
|
|
|
|
f = Discourse.FlaggedPost.create(p);
|
|
|
|
f.userLookup = userLookup;
|
|
|
|
return result.pushObject(f);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-20 13:15:50 -05:00
|
|
|
|