mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +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
|
* @param parentId {number} parent category identifier
|
||||||
*/
|
*/
|
||||||
function renderList(categories, container, parentId){
|
function renderList(categories, container, parentId){
|
||||||
templates.parse('admin/partials/categories/category-rows', {
|
// Translate category names if needed
|
||||||
cid: parentId,
|
var count = 0;
|
||||||
categories: categories
|
categories.forEach(function(category, idx, parent) {
|
||||||
}, function(html) {
|
translator.translate(category.name, function(translated) {
|
||||||
container.append(html);
|
if (category.name !== translated) {
|
||||||
|
category.name = translated;
|
||||||
|
}
|
||||||
|
++count;
|
||||||
|
|
||||||
// Handle and children categories in this level have
|
if (count === parent.length) {
|
||||||
for(var x=0,numCategories=categories.length;x<numCategories;x++) {
|
continueRender();
|
||||||
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
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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;
|
return Categories;
|
||||||
|
|||||||
@@ -155,6 +155,12 @@ define('admin/manage/category', [
|
|||||||
} else {
|
} else {
|
||||||
$('a[href="#analytics"]').on('shown.bs.tab', Category.setupGraphs);
|
$('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() {
|
Category.setupPrivilegeTable = function() {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
utils = require('../../public/src/utils'),
|
utils = require('../../public/src/utils'),
|
||||||
|
translator = require('../../public/src/modules/translator'),
|
||||||
plugins = require('../plugins');
|
plugins = require('../plugins');
|
||||||
|
|
||||||
module.exports = function(Categories) {
|
module.exports = function(Categories) {
|
||||||
@@ -27,7 +28,9 @@ module.exports = function(Categories) {
|
|||||||
|
|
||||||
|
|
||||||
if (modifiedFields.hasOwnProperty('name')) {
|
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) {
|
plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
|
||||||
|
|||||||
Reference in New Issue
Block a user