mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 23:15:48 +01:00
closes #3982
This commit is contained in:
@@ -15,7 +15,7 @@ define('forum/topic/move', function() {
|
|||||||
Move.onComplete = onComplete;
|
Move.onComplete = onComplete;
|
||||||
Move.moveAll = tids ? false : true;
|
Move.moveAll = tids ? false : true;
|
||||||
|
|
||||||
socket.emit('categories.get', onCategoriesLoaded);
|
socket.emit('categories.getMoveCategories', onCategoriesLoaded);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onCategoriesLoaded(err, categories) {
|
function onCategoriesLoaded(err, categories) {
|
||||||
@@ -23,8 +23,7 @@ define('forum/topic/move', function() {
|
|||||||
return app.alertError(err.message);
|
return app.alertError(err.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
parseModal(categories, function(html) {
|
parseModal(categories, function() {
|
||||||
modal = $(html);
|
|
||||||
|
|
||||||
modal.on('hidden.bs.modal', function() {
|
modal.on('hidden.bs.modal', function() {
|
||||||
modal.remove();
|
modal.remove();
|
||||||
@@ -36,7 +35,7 @@ define('forum/topic/move', function() {
|
|||||||
modal.find('.modal-header h3').translateText('[[topic:move_topics]]');
|
modal.find('.modal-header h3').translateText('[[topic:move_topics]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
modal.on('click', '.category-list li[data-cid]', function(e) {
|
modal.on('click', '.category-list li[data-cid]', function() {
|
||||||
selectCategory($(this));
|
selectCategory($(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,8 +46,41 @@ define('forum/topic/move', function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseModal(categories, callback) {
|
function parseModal(categories, callback) {
|
||||||
templates.parse('partials/move_thread_modal', {categories: categories}, function(html) {
|
templates.parse('partials/move_thread_modal', {categories: []}, function(html) {
|
||||||
translator.translate(html, callback);
|
translator.translate(html, function(html) {
|
||||||
|
modal = $(html);
|
||||||
|
categories.forEach(function(category) {
|
||||||
|
if (!category.link) {
|
||||||
|
buildRecursive(modal.find('.category-list'), category, '');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildRecursive(parentEl, category, level) {
|
||||||
|
var categoryEl = $('<li/>');
|
||||||
|
|
||||||
|
if (category.bgColor) {
|
||||||
|
categoryEl.css('background-color', category.bgColor);
|
||||||
|
}
|
||||||
|
if (category.color) {
|
||||||
|
categoryEl.css('color', category.color);
|
||||||
|
}
|
||||||
|
categoryEl.toggleClass('disabled', !!category.disabled);
|
||||||
|
categoryEl.attr('data-cid', category.cid);
|
||||||
|
categoryEl.html('<i class="fa fa-fw ' + category.icon + '"></i> ' + category.name);
|
||||||
|
|
||||||
|
parentEl.append(level);
|
||||||
|
parentEl.append(categoryEl);
|
||||||
|
parentEl.append('<br/>');
|
||||||
|
|
||||||
|
var indent = ' ';
|
||||||
|
category.children.forEach(function(childCategory) {
|
||||||
|
if (!childCategory.link) {
|
||||||
|
buildRecursive(parentEl, childCategory, indent + level);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async'),
|
var async = require('async');
|
||||||
db = require('../database'),
|
var db = require('../database');
|
||||||
categories = require('../categories'),
|
var categories = require('../categories');
|
||||||
privileges = require('../privileges'),
|
var privileges = require('../privileges');
|
||||||
user = require('../user'),
|
var user = require('../user');
|
||||||
topics = require('../topics'),
|
var topics = require('../topics');
|
||||||
websockets = require('./index'),
|
|
||||||
|
|
||||||
SocketCategories = {};
|
|
||||||
|
var SocketCategories = {};
|
||||||
|
|
||||||
SocketCategories.getRecentReplies = function(socket, cid, callback) {
|
SocketCategories.getRecentReplies = function(socket, cid, callback) {
|
||||||
categories.getRecentReplies(cid, socket.uid, 4, callback);
|
categories.getRecentReplies(cid, socket.uid, 4, callback);
|
||||||
@@ -141,6 +141,32 @@ SocketCategories.getCategoriesByPrivilege = function(socket, privilege, callback
|
|||||||
categories.getCategoriesByPrivilege('categories:cid', socket.uid, privilege, callback);
|
categories.getCategoriesByPrivilege('categories:cid', socket.uid, privilege, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SocketCategories.getMoveCategories = function(socket, data, callback) {
|
||||||
|
async.parallel({
|
||||||
|
isAdmin: async.apply(user.isAdministrator, socket.uid),
|
||||||
|
categories: function(next) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getSortedSetRange('cid:0:children', 0, -1, next);
|
||||||
|
},
|
||||||
|
function (cids, next) {
|
||||||
|
categories.getCategories(cids, socket.uid, next);
|
||||||
|
}
|
||||||
|
], next);
|
||||||
|
}
|
||||||
|
}, function(err, results) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.categories = results.categories.filter(function(category) {
|
||||||
|
return category && (!category.disabled || results.isAdmin) && !category.link;
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, results.categories);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
SocketCategories.watch = function(socket, cid, callback) {
|
SocketCategories.watch = function(socket, cid, callback) {
|
||||||
user.watchCategory(socket.uid, cid, function(err) {
|
user.watchCategory(socket.uid, cid, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user