mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 14:35:47 +01:00
fixes #4361
This commit is contained in:
@@ -152,28 +152,45 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
|
||||
* @param parentId {number} parent category identifier
|
||||
*/
|
||||
function renderList(categories, container, parentId){
|
||||
templates.parse('admin/partials/categories/category-rows', {
|
||||
cid: parentId,
|
||||
categories: categories
|
||||
}, function(html) {
|
||||
container.append(html);
|
||||
// Translate category names if needed
|
||||
var count = 0;
|
||||
categories.forEach(function(category, idx, parent) {
|
||||
translator.translate(category.name, function(translated) {
|
||||
if (category.name !== translated) {
|
||||
category.name = translated;
|
||||
}
|
||||
++count;
|
||||
|
||||
// Handle and children categories in this level have
|
||||
for(var x=0,numCategories=categories.length;x<numCategories;x++) {
|
||||
renderList(categories[x].children, $('li[data-cid="' + categories[x].cid + '"]'), categories[x].cid);
|
||||
}
|
||||
|
||||
// Make list sortable
|
||||
sortables[parentId] = Sortable.create($('ul[data-cid="' + parentId + '"]')[0], {
|
||||
group: 'cross-categories',
|
||||
animation: 150,
|
||||
handle: '.icon',
|
||||
dataIdAttr: 'data-cid',
|
||||
ghostClass: "placeholder",
|
||||
onAdd: itemDidAdd,
|
||||
onEnd: itemDragDidEnd
|
||||
if (count === parent.length) {
|
||||
continueRender();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function continueRender() {
|
||||
templates.parse('admin/partials/categories/category-rows', {
|
||||
cid: parentId,
|
||||
categories: categories
|
||||
}, function(html) {
|
||||
container.append(html);
|
||||
|
||||
// Handle and children categories in this level have
|
||||
for(var x=0,numCategories=categories.length;x<numCategories;x++) {
|
||||
renderList(categories[x].children, $('li[data-cid="' + categories[x].cid + '"]'), categories[x].cid);
|
||||
}
|
||||
|
||||
// Make list sortable
|
||||
sortables[parentId] = Sortable.create($('ul[data-cid="' + parentId + '"]')[0], {
|
||||
group: 'cross-categories',
|
||||
animation: 150,
|
||||
handle: '.icon',
|
||||
dataIdAttr: 'data-cid',
|
||||
ghostClass: "placeholder",
|
||||
onAdd: itemDidAdd,
|
||||
onEnd: itemDragDidEnd
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Categories;
|
||||
|
||||
@@ -155,6 +155,12 @@ define('admin/manage/category', [
|
||||
} else {
|
||||
$('a[href="#analytics"]').on('shown.bs.tab', Category.setupGraphs);
|
||||
}
|
||||
|
||||
// Fix the input field for the category name, as it can contain a translation key
|
||||
var nameInput = $('#cid-' + ajaxify.data.cid + '-name');
|
||||
if (ajaxify.data.category.name !== nameInput.val()) {
|
||||
$('#cid-' + ajaxify.data.category.cid + '-name').val(ajaxify.data.category.name);
|
||||
}
|
||||
};
|
||||
|
||||
Category.setupPrivilegeTable = function() {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
var async = require('async'),
|
||||
db = require('../database'),
|
||||
utils = require('../../public/src/utils'),
|
||||
translator = require('../../public/src/modules/translator'),
|
||||
plugins = require('../plugins');
|
||||
|
||||
module.exports = function(Categories) {
|
||||
@@ -27,7 +28,9 @@ module.exports = function(Categories) {
|
||||
|
||||
|
||||
if (modifiedFields.hasOwnProperty('name')) {
|
||||
modifiedFields.slug = cid + '/' + utils.slugify(modifiedFields.name);
|
||||
translator.translate(modifiedFields.name, function(translated) {
|
||||
modifiedFields.slug = cid + '/' + utils.slugify(translated);
|
||||
});
|
||||
}
|
||||
|
||||
plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
|
||||
|
||||
Reference in New Issue
Block a user