closes #2132
parent
c57dc25ea7
commit
f6f6ca7f76
@ -0,0 +1 @@
|
|||||||
|
|
@ -0,0 +1,68 @@
|
|||||||
|
"use strict";
|
||||||
|
/*global define, socket, app, admin, utils, bootbox, RELATIVE_PATH*/
|
||||||
|
|
||||||
|
define('forum/admin/manage/flags', ['forum/infinitescroll', 'admin/selectable'], function(infinitescroll, selectable) {
|
||||||
|
var Flags = {};
|
||||||
|
|
||||||
|
Flags.init = function() {
|
||||||
|
handleDismiss();
|
||||||
|
handleDelete();
|
||||||
|
handleInfiniteScroll();
|
||||||
|
};
|
||||||
|
|
||||||
|
function handleDismiss() {
|
||||||
|
$('.flags').on('click', '.dismiss', function() {
|
||||||
|
var btn = $(this);
|
||||||
|
var pid = btn.siblings('[data-pid]').attr('data-pid');
|
||||||
|
|
||||||
|
socket.emit('admin.dismissFlag', pid, function(err) {
|
||||||
|
done(err, btn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDelete() {
|
||||||
|
$('.flags').on('click', '.delete', function() {
|
||||||
|
var btn = $(this);
|
||||||
|
var pid = btn.siblings('[data-pid]').attr('data-pid');
|
||||||
|
var tid = btn.siblings('[data-pid]').attr('data-tid');
|
||||||
|
socket.emit('posts.delete', {pid: pid, tid: tid}, function(err) {
|
||||||
|
done(err, btn);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function done(err, btn) {
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.messaage);
|
||||||
|
}
|
||||||
|
btn.parent().fadeOut(function() {
|
||||||
|
btn.remove();
|
||||||
|
});
|
||||||
|
if (!$('.flags [data-pid]').length) {
|
||||||
|
$('.post-container').text('No flagged posts!');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleInfiniteScroll() {
|
||||||
|
infinitescroll.init(function(direction) {
|
||||||
|
if (direction < 0 && !$('.flags').length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
infinitescroll.loadMore('admin.getMoreFlags', $('[data-next]').attr('data-next'), function(data, done) {
|
||||||
|
if (data.posts && data.posts.length) {
|
||||||
|
infinitescroll.parseAndTranslate('admin/manage/flags', 'posts', {posts: data.posts}, function(html) {
|
||||||
|
$('[data-next]').attr('data-next', data.next);
|
||||||
|
$('.post-container').append(html);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Flags;
|
||||||
|
});
|
@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var async = require('async'),
|
||||||
|
db = require('../database');
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = function(Posts) {
|
||||||
|
Posts.flag = function(pid, callback) {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetAdd('posts:flagged', Date.now(), pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.incrObjectField('post:' + pid, 'flags', next);
|
||||||
|
}
|
||||||
|
], function(err, results) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.dismissFlag = function(pid, callback) {
|
||||||
|
async.parallel([
|
||||||
|
function(next) {
|
||||||
|
db.sortedSetRemove('posts:flagged', pid, next);
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
db.deleteObjectField('post:' + pid, 'flags', next);
|
||||||
|
}
|
||||||
|
], function(err, results) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
Posts.getFlags = function(uid, start, end, callback) {
|
||||||
|
db.getSortedSetRevRange('posts:flagged', start, end, function(err, pids) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
Posts.getPostSummaryByPids(pids, uid, {stripTags: false, extraFields: ['flags']}, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
@ -0,0 +1,46 @@
|
|||||||
|
<div class="flags">
|
||||||
|
<div class="col-lg-9">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading"><i class="fa fa-flag"></i> Flags</div>
|
||||||
|
<div class="panel-body post-container" data-next="{next}">
|
||||||
|
|
||||||
|
<!-- IF !posts.length -->
|
||||||
|
No flagged posts!
|
||||||
|
<!-- ENDIF !posts.length-->
|
||||||
|
|
||||||
|
<!-- BEGIN posts -->
|
||||||
|
<div>
|
||||||
|
<div class="panel panel-default" data-pid="{posts.pid}" data-tid="{posts.topic.tid}">
|
||||||
|
<div class="panel-body">
|
||||||
|
<a href="{relative_path}/user/{posts.user.userslug}">
|
||||||
|
<img title="{posts.user.username}" class="img-rounded user-img" src="{posts.user.picture}">
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<a href="{relative_path}/user/{posts.user.userslug}">
|
||||||
|
<strong><span>{posts.user.username}</span></strong>
|
||||||
|
</a>
|
||||||
|
<div class="content">
|
||||||
|
<p>{posts.content}</p>
|
||||||
|
<p class="fade-out"></p>
|
||||||
|
</div>
|
||||||
|
<small>
|
||||||
|
<span class="pull-right footer">
|
||||||
|
Posted in <a href="{relative_path}/category/{posts.category.slug}"><i class="fa {posts.category.icon}"></i> {posts.category.name}</a>, <span class="timeago" title="{posts.relativeTime}"></span> •
|
||||||
|
<a href="{relative_path}/topic/{posts.topic.slug}/{posts.index}">Read More</a>
|
||||||
|
</span>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span class="badge badge-warning"><i class="fa fa-flag"></i> {posts.flags}</span>
|
||||||
|
<button class="btn btn-warning dismiss">Dismiss</button>
|
||||||
|
<button class="btn btn-danger delete">Delete</button>
|
||||||
|
<br/><br/>
|
||||||
|
</div>
|
||||||
|
<!-- END posts -->
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue