mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-15 10:16:12 +01:00
closes #3686
This commit is contained in:
@@ -94,19 +94,18 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
|
||||
}
|
||||
};
|
||||
|
||||
Categories.toggle = function(cid, state) {
|
||||
Categories.toggle = function(cid, disabled) {
|
||||
var payload = {};
|
||||
|
||||
payload[cid] = {
|
||||
disabled: !state | 0
|
||||
disabled: disabled ? 1 : 0
|
||||
};
|
||||
|
||||
socket.emit('admin.categories.update', payload, function(err, result) {
|
||||
if (err) {
|
||||
return app.alertError(err.message);
|
||||
} else {
|
||||
ajaxify.refresh();
|
||||
}
|
||||
ajaxify.refresh();
|
||||
});
|
||||
};
|
||||
|
||||
@@ -114,8 +113,9 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
|
||||
newCategoryId = e.to.dataset.cid;
|
||||
}
|
||||
|
||||
function itemDragDidEnd(e){
|
||||
function itemDragDidEnd(e) {
|
||||
var isCategoryUpdate = (newCategoryId != -1);
|
||||
|
||||
//Update needed?
|
||||
if((e.newIndex != undefined && e.oldIndex != e.newIndex) || isCategoryUpdate){
|
||||
var parentCategory = isCategoryUpdate ? sortables[newCategoryId] : sortables[e.from.dataset.cid],
|
||||
|
||||
@@ -10,13 +10,21 @@ module.exports = function(Categories) {
|
||||
|
||||
Categories.update = function(modified, callback) {
|
||||
|
||||
function updateCategory(cid, next) {
|
||||
var cids = Object.keys(modified);
|
||||
|
||||
async.each(cids, function(cid, next) {
|
||||
updateCategory(cid, modified[cid], next);
|
||||
}, function(err) {
|
||||
callback(err, cids);
|
||||
});
|
||||
};
|
||||
|
||||
function updateCategory(cid, modifiedFields, callback) {
|
||||
Categories.exists(cid, function(err, exists) {
|
||||
if (err || !exists) {
|
||||
return next(err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var modifiedFields = modified[cid];
|
||||
|
||||
if (modifiedFields.hasOwnProperty('name')) {
|
||||
modifiedFields.slug = cid + '/' + utils.slugify(modifiedFields.name);
|
||||
@@ -24,31 +32,30 @@ module.exports = function(Categories) {
|
||||
|
||||
plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
var category = categoryData.category;
|
||||
var fields = Object.keys(category);
|
||||
async.each(fields, function(key, next) {
|
||||
// move parent to front, so its updated first
|
||||
var parentCidIndex = fields.indexOf('parentCid');
|
||||
if (parentCidIndex !== -1 && fields.length > 1) {
|
||||
fields.splice(0, 0, fields.splice(parentCidIndex, 1)[0]);
|
||||
}
|
||||
|
||||
async.eachSeries(fields, function(key, next) {
|
||||
updateCategoryField(cid, key, category[key], next);
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
return callback(err);
|
||||
}
|
||||
plugins.fireHook('action:category.update', {cid: cid, modified: category});
|
||||
next();
|
||||
callback();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var cids = Object.keys(modified);
|
||||
|
||||
async.each(cids, updateCategory, function(err) {
|
||||
callback(err, cids);
|
||||
});
|
||||
};
|
||||
|
||||
function updateCategoryField(cid, key, value, callback) {
|
||||
if (key === 'parentCid') {
|
||||
return updateParent(cid, value, callback);
|
||||
|
||||
@@ -68,7 +68,7 @@ module.exports = function(db, module) {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
callback(null, item[field] || null);
|
||||
callback(null, item.hasOwnProperty(field) ? item[field] : null);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user