mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-06 05:09:28 +02:00
parse topic tools on demand
This commit is contained in:
@@ -1,48 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
/* globals define, app, ajaxify, socket, bootbox */
|
||||
/* globals define, app, ajaxify, socket, bootbox, templates */
|
||||
|
||||
define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'components', 'translator'], function(fork, move, components, translator) {
|
||||
|
||||
var ThreadTools = {};
|
||||
|
||||
ThreadTools.init = function(tid) {
|
||||
components.get('topic/delete').on('click', function() {
|
||||
|
||||
renderMenu();
|
||||
|
||||
var topicContainer = $('[component="topic"]');
|
||||
|
||||
topicContainer.on('click', '[component="topic/delete"]', function() {
|
||||
topicCommand('delete', tid);
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/restore').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/restore"]', function() {
|
||||
topicCommand('restore', tid);
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/purge').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/purge"]', function() {
|
||||
topicCommand('purge', tid);
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/lock').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/lock"]', function() {
|
||||
socket.emit('topics.lock', {tids: [tid], cid: ajaxify.data.cid});
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/unlock').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/unlock"]', function() {
|
||||
socket.emit('topics.unlock', {tids: [tid], cid: ajaxify.data.cid});
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/pin').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/pin"]', function() {
|
||||
socket.emit('topics.pin', {tids: [tid], cid: ajaxify.data.cid});
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/unpin').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/unpin"]', function() {
|
||||
socket.emit('topics.unpin', {tids: [tid], cid: ajaxify.data.cid});
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/mark-unread-for-all').on('click', function() {
|
||||
topicContainer.on('click', '[component="topic/mark-unread-for-all"]', function() {
|
||||
var btn = $(this);
|
||||
socket.emit('topics.markAsUnreadForAll', [tid], function(err) {
|
||||
if (err) {
|
||||
@@ -54,7 +59,7 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
|
||||
return false;
|
||||
});
|
||||
|
||||
components.get('topic/move').on('click', function(e) {
|
||||
topicContainer.on('click', '[component="topic/move"]', function() {
|
||||
move.init([tid], ajaxify.data.cid);
|
||||
return false;
|
||||
});
|
||||
@@ -91,6 +96,28 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move', 'comp
|
||||
}
|
||||
};
|
||||
|
||||
function renderMenu() {
|
||||
$('[component="topic"]').on('show.bs.dropdown', '.thread-tools', function() {
|
||||
var $this = $(this);
|
||||
var dropdownMenu = $this.find('.dropdown-menu');
|
||||
if (dropdownMenu.html()) {
|
||||
return;
|
||||
}
|
||||
|
||||
socket.emit('topics.loadTopicTools', {tid: ajaxify.data.tid, cid: ajaxify.data.cid}, function(err, data) {
|
||||
if (err) {
|
||||
return app.alertError(err);
|
||||
}
|
||||
|
||||
templates.parse('partials/topic/topic-menu-list', data, function(html) {
|
||||
translator.translate(html, function(html) {
|
||||
dropdownMenu.html(html);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function topicCommand(command, tid) {
|
||||
translator.translate('[[topic:thread_tools.' + command + '_confirm]]', function(msg) {
|
||||
bootbox.confirm(msg, function(confirm) {
|
||||
|
||||
@@ -3,10 +3,39 @@
|
||||
var async = require('async');
|
||||
var topics = require('../../topics');
|
||||
var events = require('../../events');
|
||||
var privileges = require('../../privileges');
|
||||
var socketHelpers = require('../helpers');
|
||||
|
||||
module.exports = function(SocketTopics) {
|
||||
|
||||
SocketTopics.loadTopicTools = function(socket, data, callback) {
|
||||
if (!socket.uid) {
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'))
|
||||
}
|
||||
|
||||
async.parallel({
|
||||
topic: function(next) {
|
||||
topics.getTopicFields(data.tid, ['deleted', 'locked', 'pinned'], next);
|
||||
},
|
||||
privileges: function(next) {
|
||||
privileges.topics.get(data.tid, socket.uid, next);
|
||||
}
|
||||
}, function(err, results) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
results.topic.deleted = parseInt(results.topic.deleted, 10) === 1;
|
||||
results.topic.locked = parseInt(results.topic.locked, 10) === 1;
|
||||
results.topic.pinned = parseInt(results.topic.pinned, 10) === 1;
|
||||
results.topic.privileges = results.privileges;
|
||||
|
||||
callback(null, results.topic);
|
||||
});
|
||||
};
|
||||
|
||||
SocketTopics.delete = function(socket, data, callback) {
|
||||
SocketTopics.doTopicAction('delete', 'event:topic_deleted', socket, data, callback);
|
||||
|
||||
Reference in New Issue
Block a user