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 = {};
|
var payload = {};
|
||||||
|
|
||||||
payload[cid] = {
|
payload[cid] = {
|
||||||
disabled: !state | 0
|
disabled: disabled ? 1 : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.emit('admin.categories.update', payload, function(err, result) {
|
socket.emit('admin.categories.update', payload, function(err, result) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return app.alertError(err.message);
|
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;
|
newCategoryId = e.to.dataset.cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
function itemDragDidEnd(e){
|
function itemDragDidEnd(e) {
|
||||||
var isCategoryUpdate = (newCategoryId != -1);
|
var isCategoryUpdate = (newCategoryId != -1);
|
||||||
|
|
||||||
//Update needed?
|
//Update needed?
|
||||||
if((e.newIndex != undefined && e.oldIndex != e.newIndex) || isCategoryUpdate){
|
if((e.newIndex != undefined && e.oldIndex != e.newIndex) || isCategoryUpdate){
|
||||||
var parentCategory = isCategoryUpdate ? sortables[newCategoryId] : sortables[e.from.dataset.cid],
|
var parentCategory = isCategoryUpdate ? sortables[newCategoryId] : sortables[e.from.dataset.cid],
|
||||||
|
|||||||
@@ -10,45 +10,52 @@ module.exports = function(Categories) {
|
|||||||
|
|
||||||
Categories.update = function(modified, callback) {
|
Categories.update = function(modified, callback) {
|
||||||
|
|
||||||
function updateCategory(cid, next) {
|
|
||||||
Categories.exists(cid, function(err, exists) {
|
|
||||||
if (err || !exists) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
var modifiedFields = modified[cid];
|
|
||||||
|
|
||||||
if (modifiedFields.hasOwnProperty('name')) {
|
|
||||||
modifiedFields.slug = cid + '/' + utils.slugify(modifiedFields.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
var category = categoryData.category;
|
|
||||||
var fields = Object.keys(category);
|
|
||||||
async.each(fields, function(key, next) {
|
|
||||||
updateCategoryField(cid, key, category[key], next);
|
|
||||||
}, function(err) {
|
|
||||||
if (err) {
|
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
plugins.fireHook('action:category.update', {cid: cid, modified: category});
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var cids = Object.keys(modified);
|
var cids = Object.keys(modified);
|
||||||
|
|
||||||
async.each(cids, updateCategory, function(err) {
|
async.each(cids, function(cid, next) {
|
||||||
|
updateCategory(cid, modified[cid], next);
|
||||||
|
}, function(err) {
|
||||||
callback(err, cids);
|
callback(err, cids);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function updateCategory(cid, modifiedFields, callback) {
|
||||||
|
Categories.exists(cid, function(err, exists) {
|
||||||
|
if (err || !exists) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (modifiedFields.hasOwnProperty('name')) {
|
||||||
|
modifiedFields.slug = cid + '/' + utils.slugify(modifiedFields.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
var category = categoryData.category;
|
||||||
|
var fields = Object.keys(category);
|
||||||
|
// 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 callback(err);
|
||||||
|
}
|
||||||
|
plugins.fireHook('action:category.update', {cid: cid, modified: category});
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function updateCategoryField(cid, key, value, callback) {
|
function updateCategoryField(cid, key, value, callback) {
|
||||||
if (key === 'parentCid') {
|
if (key === 'parentCid') {
|
||||||
return updateParent(cid, value, callback);
|
return updateParent(cid, value, callback);
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ module.exports = function(db, module) {
|
|||||||
return callback(err, null);
|
return callback(err, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, item[field] || null);
|
callback(null, item.hasOwnProperty(field) ? item[field] : null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user