if bgColor and color are not sent in the category creation call, automatic colours are supplied

v1.18.x
Julian Lam 10 years ago
parent d342e01ef1
commit e8167a80a0

@ -75,8 +75,6 @@ define('admin/manage/categories', [
name: $('#inputName').val(), name: $('#inputName').val(),
description: $('#inputDescription').val(), description: $('#inputDescription').val(),
icon: $('#new-category-modal i').attr('value'), icon: $('#new-category-modal i').attr('value'),
bgColor: '#0059b2',
color: '#fff',
order: $('.admin-categories #entry-container').children().length + 1 order: $('.admin-categories #entry-container').children().length + 1
}; };

@ -14,15 +14,16 @@ module.exports = function(Categories) {
} }
var slug = cid + '/' + utils.slugify(data.name), var slug = cid + '/' + utils.slugify(data.name),
order = data.order || cid; // If no order provided, place it at the end order = data.order || cid, // If no order provided, place it at the end
colours = Categories.assignColours();
var category = { var category = {
cid: cid, cid: cid,
name: data.name, name: data.name,
description: data.description, description: data.description,
icon: data.icon, icon: data.icon,
bgColor: data.bgColor, bgColor: data.bgColor || colours[0],
color: data.color, color: data.color || colours[1],
slug: slug, slug: slug,
parentCid: 0, parentCid: 0,
topic_count: 0, topic_count: 0,
@ -52,4 +53,12 @@ module.exports = function(Categories) {
}); });
}); });
}; };
Categories.assignColours = function() {
var backgrounds = ['#AB4642', '#DC9656', '#F7CA88', '#A1B56C', '#86C1B9', '#7CAFC2', '#BA8BAF', '#A16946'],
text = ['#fff', '#fff', '#333', '#fff', '#333', '#fff', '#fff', '#fff'],
index = Math.floor(Math.random() * backgrounds.length);
return [backgrounds[index], text[index]];
};
}; };

Loading…
Cancel
Save