load post tools menu on demand

v1.18.x
barisusakli 9 years ago
parent 22f1ebc2dd
commit 6c9de29326

@ -10,6 +10,8 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
PostTools.init = function(tid) {
topicName = ajaxify.data.title;
renderMenu();
addPostHandlers(tid);
share.addShareHandlers(topicName);
@ -19,6 +21,30 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
PostTools.updatePostCount(ajaxify.data.postcount);
};
function renderMenu() {
$('[component="topic"]').on('show.bs.dropdown', '.moderator-tools', function() {
var $this = $(this);
var dropdownMenu = $this.find('.dropdown-menu');
if (dropdownMenu.html()) {
return;
}
var postEl = $this.parents('[data-pid]');
var pid = postEl.attr('data-pid');
var index = parseInt(postEl.attr('data-index'), 10);
socket.emit('posts.loadPostTools', {pid: pid, cid: ajaxify.data.cid}, function(err, data) {
if (err) {
return app.alertError(err);
}
data.posts.display_move_tools = data.posts.display_move_tools && index !== 0;
templates.parse('partials/topic/post-menu-list', data, function(html) {
translator.translate(html, function(html) {
dropdownMenu.html(html);
});
});
});
});
}
PostTools.toggle = function(pid, isDeleted) {
var postEl = components.get('post', 'pid', pid);

@ -6,10 +6,44 @@ var posts = require('../../posts');
var events = require('../../events');
var websockets = require('../index');
var socketTopics = require('../topics');
var privileges = require('../../privileges');
var favourites = require('../../favourites');
module.exports = function(SocketPosts) {
SocketPosts.loadPostTools = function(socket, data, callback) {
if (!socket.uid) {
return;
}
if (!data) {
return callback(new Error('[[error:invalid-data]]'))
}
async.parallel({
posts: function(next) {
posts.getPostFields(data.pid, ['deleted', 'reputation', 'uid'], next);
},
isAdminOrMod: function(next) {
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
},
favourited: function(next) {
favourites.getFavouritesByPostIDs([data.pid], socket.uid, next);
}
}, function(err, results) {
if (err) {
return callback(err);
}
results.posts.tools = []; // TODO: add filter for this
results.posts.deleted = parseInt(results.posts.deleted, 10) === 1;
results.posts.favourited = results.favourited[0];
results.posts.selfPost = socket.uid === parseInt(results.posts.uid, 10);
results.posts.display_moderator_tools = results.isAdminOrMod || results.posts.selfPost;
results.posts.display_move_tools = results.isAdminOrMod;
callback(null, results);
});
};
SocketPosts.delete = function(socket, data, callback) {
doPostAction('delete', 'event:post_deleted', socket, data, callback);
};

Loading…
Cancel
Save