diff options
Diffstat (limited to 'addons/web/static/src/js')
3 files changed, 54 insertions, 13 deletions
diff --git a/addons/web/static/src/js/views/calendar/calendar_model.js b/addons/web/static/src/js/views/calendar/calendar_model.js index 2f2c6339ac6..9635fc5ffc4 100644 --- a/addons/web/static/src/js/views/calendar/calendar_model.js +++ b/addons/web/static/src/js/views/calendar/calendar_model.js @@ -579,6 +579,8 @@ return AbstractModel.extend({ var self = this; var new_filters = {}; var to_read = {}; + var defs = []; + var color_filter = {}; _.each(this.data.filters, function (filter, fieldName) { var field = self.fields[fieldName]; @@ -620,7 +622,7 @@ return AbstractModel.extend({ }); }); _.each(_.union(fs, undefined_fs), function (f) { - var f1 = _.findWhere(filter.filters, f); + var f1 = _.findWhere(filter.filters, _.omit(f, 'color_index')); if (f1) { f1.display = true; } else { @@ -628,9 +630,32 @@ return AbstractModel.extend({ filter.filters.push(f); } }); + + if (filter.color_model && filter.field_color) { + var ids = filter.filters.reduce((acc, f) => { + if (!f.color_index && f.value) { + acc.push(f.value); + } + return acc; + }, []); + if (!color_filter[filter.color_model]) { + color_filter[filter.color_model] = {}; + } + if (ids.length) { + defs.push(self._rpc({ + model: filter.color_model, + method: 'read', + args: [_.uniq(ids), [filter.field_color]], + }) + .then(function (res) { + _.each(res, function (c) { + color_filter[filter.color_model][c.id] = c[filter.field_color]; + }); + })); + } + } }); - var defs = []; _.each(to_read, function (ids, model) { defs.push(self._rpc({ model: model, @@ -651,6 +676,13 @@ return AbstractModel.extend({ f.label = to_read[f.avatar_model][f.value]; }); } + if (filter.color_model && filter.field_color) { + _.each(filter.filters, function (f) { + if (!f.color_index) { + f.color_index = color_filter[filter.color_model] && color_filter[filter.color_model][f.value]; + } + }); + } }); }); }, diff --git a/addons/web/static/src/js/views/calendar/calendar_renderer.js b/addons/web/static/src/js/views/calendar/calendar_renderer.js index f563f793203..7755097d412 100644 --- a/addons/web/static/src/js/views/calendar/calendar_renderer.js +++ b/addons/web/static/src/js/views/calendar/calendar_renderer.js @@ -284,6 +284,9 @@ return AbstractRenderer.extend({ if (typeof key === 'string' && key.match(/^((#[A-F0-9]{3})|(#[A-F0-9]{6})|((hsl|rgb)a?\(\s*(?:(\s*\d{1,3}%?\s*),?){3}(\s*,[0-9.]{1,4})?\))|)$/i)) { return this.color_map[key] = key; } + if (typeof key === 'number' && !(key in this.color_map)) { + return this.color_map[key] = key; + } var index = (((_.keys(this.color_map).length + 1) * 5) % 24) + 1; this.color_map[key] = index; return index; diff --git a/addons/web/static/src/js/views/calendar/calendar_view.js b/addons/web/static/src/js/views/calendar/calendar_view.js index 9c9355145ee..b68a134a00a 100644 --- a/addons/web/static/src/js/views/calendar/calendar_view.js +++ b/addons/web/static/src/js/views/calendar/calendar_view.js @@ -92,23 +92,29 @@ var CalendarView = AbstractView.extend({ modelFilters.push(fields[fieldName].relation); } + if (child.attrs.filter) { + filters[fieldName] = filters[fieldName] || { + 'title': fields[fieldName].string, + 'fieldName': fieldName, + 'filters': [], + }; + if (child.attrs.color) { + filters[fieldName].field_color = child.attrs.color; + filters[fieldName].color_model = fields[fieldName].relation; + } + if (!child.attrs.avatar_field && fields[fieldName].relation) { + if (fields[fieldName].relation.includes(['res.users', 'res.partner', 'hr.employee'])) { + filters[fieldName].avatar_field = 'image_128'; + } + filters[fieldName].avatar_model = fields[fieldName].relation; + } + } } }); if (attrs.color) { var fieldName = attrs.color; fieldNames.push(fieldName); - filters[fieldName] = { - 'title': fields[fieldName].string, - 'fieldName': fieldName, - 'filters': [], - }; - if (fields[fieldName].relation) { - if (['res.users', 'res.partner', 'hr.employee'].indexOf(fields[fieldName].relation) !== -1) { - filters[fieldName].avatar_field = 'image_128'; - } - filters[fieldName].avatar_model = fields[fieldName].relation; - } } //if quick_add = False, we don't allow quick_add |
