[REF] web: allow 12 kanban colors

We added 2 colors to the custom colors scheme for tags and cards' colors
but we did not adapt the possibility to set them properly in kanban.
Also adapt the related test.
This commit is contained in:
qsm-odoo
2017-08-28 12:53:17 +02:00
parent 76b19e8f35
commit 539f66dd72
2 changed files with 20 additions and 15 deletions
@@ -15,6 +15,8 @@ var Widget = require('web.Widget');
var _t = core._t;
var QWeb = core.qweb;
var NB_KANBAN_RECORD_COLORS = 12;
var KanbanRecord = Widget.extend({
events: {
'click .oe_kanban_action': '_onKanbanActionClicked',
@@ -111,15 +113,15 @@ var KanbanRecord = Widget.extend({
* @returns {integer} the color id
*/
_getColorID: function (variable) {
if (typeof(variable) === 'number') {
return Math.round(variable) % 10;
if (typeof variable === 'number') {
return Math.round(variable) % NB_KANBAN_RECORD_COLORS;
}
if (typeof(variable) === 'string') {
if (typeof variable === 'string') {
var index = 0;
for (var i=0; i<variable.length; i++) {
for (var i = 0 ; i < variable.length ; i++) {
index += variable.charCodeAt(i);
}
return index % 10;
return index % NB_KANBAN_RECORD_COLORS;
}
return 0;
},
+13 -10
View File
@@ -1414,6 +1414,8 @@ QUnit.module('Views', {
var writeOnColor;
this.data.category.records[0].color = 12;
var kanban = createView({
View: KanbanView,
model: 'category',
@@ -1446,20 +1448,21 @@ QUnit.module('Views', {
},
});
var $first_record = kanban.$('.o_kanban_record:first()');
var $firstRecord = kanban.$('.o_kanban_record:first()');
assert.strictEqual($first_record.find('.oe_kanban_color_10').length, 0,
"no record should have the color 10");
assert.strictEqual($first_record.find('.oe_kanban_colorpicker').length, 1,
assert.strictEqual(kanban.$('.o_kanban_record.oe_kanban_color_12').length, 0,
"no record should have the color 12");
assert.strictEqual($firstRecord.find('.oe_kanban_colorpicker').length, 1,
"there should be a color picker");
assert.strictEqual($first_record.find('.oe_kanban_colorpicker').children().length, 10,
"the color picker should have 10 children (the colors)");
assert.strictEqual($firstRecord.find('.oe_kanban_colorpicker').children().length, 12,
"the color picker should have 12 children (the colors)");
// set the last color
$first_record.find('.oe_kanban_colorpicker a.oe_kanban_color_9').click();
// Set a color
$firstRecord.find('.oe_kanban_colorpicker a.oe_kanban_color_9').click();
assert.ok(writeOnColor, "should write on the color field");
assert.strictEqual($first_record.find('.oe_kanban_color_9').length, 1,
"one record should have the color 10");
$firstRecord = kanban.$('.o_kanban_record:first()'); // First record is reloaded here
assert.ok($firstRecord.is('.oe_kanban_color_9'),
"the first record should have the color 9");
kanban.destroy();
});