summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/calendar
diff options
context:
space:
mode:
authorjbm-odoo <jbm@odoo.com>2019-12-09 13:11:36 +0000
committerYannick Tivisse <yti@odoo.com>2020-01-27 16:08:34 +0000
commitfa48e05f42492fdca7fd371bca1b2643b50e4ac0 (patch)
treed071c4bf2803893f91c9179ad422e1a8e2df59ae /addons/web/static/src/js/views/calendar
parentd39fc89324810df765cdcdbe2113446ec5cd882d (diff)
[IMP] calendar: Improve color and filters
Now in a calendar view, if we use the color, attribute, it will use the same color as Gantt views and the color picker widget. The attribute color isn't more set as default in filter because it make, in most situation, no sense to filter by color. Now, we can add new filters in the right panel. To do that, we must add the attribute "filter='1'" in the corresponding field line. And if the filter has no direct link with the color of the model, we can specify an attribute 'color' for this filter line block. (for example color='color', and the color of the related model will be used) TaskID: 2153249
Diffstat (limited to 'addons/web/static/src/js/views/calendar')
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_model.js36
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_renderer.js3
-rw-r--r--addons/web/static/src/js/views/calendar/calendar_view.js28
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