3
0
Fork 0

[IMP] change the option to initialize the timeline window on display.

Change the attribute 'default_window' to 'mode' like the Odoo calendar view (to be iso functional)
11.0
adrien.didenot 2017-10-11 10:13:38 +02:00 committed by Martin Nicolas Cuesta
parent 1dbdefbb44
commit 3fc685a576
3 changed files with 16 additions and 22 deletions

View File

@ -31,8 +31,8 @@ the possible attributes for the tag:
additional key is down. Available values are '' (does not apply), 'altKey', additional key is down. Available values are '' (does not apply), 'altKey',
'ctrlKey', or 'metaKey'. Set this option if you want to be able to use the 'ctrlKey', or 'metaKey'. Set this option if you want to be able to use the
scroll to navigate vertically on views with a lot of events. scroll to navigate vertically on views with a lot of events.
* default_window (optional): Specifies the initial visible window. Aviable values are: * mode (optional): Specifies the initial visible window. Available values are:
'day' to display the next 24 hours, 'week', 'month' and 'fit'. 'day' to display the current day, 'week', 'month' and 'fit'.
Default value is 'fit' to adjust the visible window such that it fits all items Default value is 'fit' to adjust the visible window such that it fits all items
* event_open_popup (optional): when set to true, it allows to edit the events * event_open_popup (optional): when set to true, it allows to edit the events
in a popup. If not (default value), the record is edited changing to form in a popup. If not (default value), the record is edited changing to form

View File

@ -5,7 +5,7 @@
{ {
'name': "Web timeline", 'name': "Web timeline",
'summary': "Interactive visualization chart to show events in time", 'summary': "Interactive visualization chart to show events in time",
"version": "10.0.1.1.0", "version": "10.0.1.2.0",
'author': 'ACSONE SA/NV, ' 'author': 'ACSONE SA/NV, '
'Tecnativa, ' 'Tecnativa, '
'Monk Software, ' 'Monk Software, '

View File

@ -55,13 +55,6 @@ odoo.define('web_timeline.TimelineView', function (require) {
} }
}, },
// set_default_options: function(options) {
// this._super(options);
// _.defaults(this.options, {
// confirm_on_delete: true
// });
// },
parse_colors: function () { parse_colors: function () {
if (this.fields_view.arch.attrs.colors) { if (this.fields_view.arch.attrs.colors) {
this.colors = _(this.fields_view.arch.attrs.colors.split(';')).chain().compact().map(function (color_pair) { this.colors = _(this.fields_view.arch.attrs.colors.split(';')).chain().compact().map(function (color_pair) {
@ -101,7 +94,6 @@ odoo.define('web_timeline.TimelineView', function (require) {
this.$el.addClass(attrs['class']); this.$el.addClass(attrs['class']);
this.info_fields = []; this.info_fields = [];
this.mode = attrs.mode;
if (!attrs.date_start) { if (!attrs.date_start) {
throw new Error(_t("Timeline view has not defined 'date_start' attribute.")); throw new Error(_t("Timeline view has not defined 'date_start' attribute."));
@ -111,7 +103,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
this.date_delay = attrs.date_delay; this.date_delay = attrs.date_delay;
this.no_period = this.date_start == this.date_stop; this.no_period = this.date_start == this.date_stop;
this.zoomKey = attrs.zoomKey || ''; this.zoomKey = attrs.zoomKey || '';
this.default_window = attrs.default_window || 'fit'; this.mode = attrs.mode || attrs.default_window || 'fit';
if (!isNullOrUndef(attrs.quick_create_instance)) { if (!isNullOrUndef(attrs.quick_create_instance)) {
self.quick_create_instance = 'instance.' + attrs.quick_create_instance; self.quick_create_instance = 'instance.' + attrs.quick_create_instance;
@ -172,25 +164,27 @@ odoo.define('web_timeline.TimelineView', function (require) {
onRemove: self.on_remove, onRemove: self.on_remove,
zoomKey: this.zoomKey zoomKey: this.zoomKey
}; };
if (this.default_window) { if (this.mode) {
var start = new moment(); var start = false, end = false;
var end; switch (this.mode) {
switch (this.default_window) {
case 'day': case 'day':
end = new moment().add(1, 'days'); start = new moment().startOf('day');
end = new moment().endOf('day');
break; break;
case 'week': case 'week':
end = new moment().add(1, 'weeks'); start = new moment().startOf('week');
end = new moment().endOf('week');
break; break;
case 'month': case 'month':
end = new moment().add(1, 'months'); start = new moment().startOf('month');
end = new moment().endOf('month');
break; break;
} }
if (end) { if (end && start) {
options['start'] = start; options['start'] = start;
options['end'] = end; options['end'] = end;
}else{ }else{
this.default_window = 'fit'; this.mode = 'fit';
} }
} }
self.timeline = new vis.Timeline(self.$timeline.empty().get(0)); self.timeline = new vis.Timeline(self.$timeline.empty().get(0));
@ -355,7 +349,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
var groups = split_groups(events, group_bys); var groups = split_groups(events, group_bys);
this.timeline.setGroups(groups); this.timeline.setGroups(groups);
this.timeline.setItems(data); this.timeline.setItems(data);
if (!this.default_window || this.default_window == 'fit'){ if (!this.mode || this.mode == 'fit'){
this.timeline.fit(); this.timeline.fit();
} }
}, },