v1.18.x
barisusakli 9 years ago
parent c72bb54957
commit e7f87f4ffd

@ -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();
}); });
}; };
@ -116,6 +115,7 @@ define('admin/manage/categories', ['vendor/jquery/serializeObject/jquery.ba-seri
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,13 +10,21 @@ module.exports = function(Categories) {
Categories.update = function(modified, callback) { 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) { Categories.exists(cid, function(err, exists) {
if (err || !exists) { if (err || !exists) {
return next(err); return callback(err);
} }
var modifiedFields = modified[cid];
if (modifiedFields.hasOwnProperty('name')) { if (modifiedFields.hasOwnProperty('name')) {
modifiedFields.slug = cid + '/' + utils.slugify(modifiedFields.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) { plugins.fireHook('filter:category.update', {category: modifiedFields}, function(err, categoryData) {
if (err) { if (err) {
return next(err); return callback(err);
} }
var category = categoryData.category; var category = categoryData.category;
var fields = Object.keys(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); updateCategoryField(cid, key, category[key], next);
}, function(err) { }, function(err) {
if (err) { if (err) {
return next(err); return callback(err);
} }
plugins.fireHook('action:category.update', {cid: cid, modified: category}); 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) { 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);
}); });
}; };

Loading…
Cancel
Save