From ae9cf39dfc68a73b3ee83ebddb08f3cd2952b968 Mon Sep 17 00:00:00 2001 From: "adrien.didenot" Date: Thu, 28 Sep 2017 17:33:00 +0200 Subject: [PATCH] [IMP] Add an option to initialize the timeline window on display. The default window display all the events (aka 'fit'), in case of events spread over the year, the events are invisibles (too small to be readable) Signed-off-by: adrien.didenot --- web_timeline/README.rst | 3 +++ web_timeline/static/src/js/web_timeline.js | 26 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/web_timeline/README.rst b/web_timeline/README.rst index 61a9b6c8..460e14af 100755 --- a/web_timeline/README.rst +++ b/web_timeline/README.rst @@ -31,6 +31,9 @@ the possible attributes for the tag: 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 scroll to navigate vertically on views with a lot of events. +* default_window (optional): Specifies the initial visible window. Aviable values are: + 'day' to display the next 24 hours, 'week', 'month' and 'fit'. + 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 in a popup. If not (default value), the record is edited changing to form view. diff --git a/web_timeline/static/src/js/web_timeline.js b/web_timeline/static/src/js/web_timeline.js index 6369ff25..6cc3ca78 100644 --- a/web_timeline/static/src/js/web_timeline.js +++ b/web_timeline/static/src/js/web_timeline.js @@ -111,6 +111,7 @@ odoo.define('web_timeline.TimelineView', function (require) { this.date_delay = attrs.date_delay; this.no_period = this.date_start == this.date_stop; this.zoomKey = attrs.zoomKey || ''; + this.default_window = attrs.default_window || 'fit'; if (!isNullOrUndef(attrs.quick_create_instance)) { self.quick_create_instance = 'instance.' + attrs.quick_create_instance; @@ -171,6 +172,27 @@ odoo.define('web_timeline.TimelineView', function (require) { onRemove: self.on_remove, zoomKey: this.zoomKey }; + if (this.default_window) { + var start = new moment(); + var end; + switch (this.default_window) { + case 'day': + end = new moment().add(1, 'days'); + break; + case 'week': + end = new moment().add(1, 'weeks'); + break; + case 'month': + end = new moment().add(1, 'months'); + break; + } + if (end) { + options['start'] = start; + options['end'] = end; + }else{ + this.default_window = 'fit'; + } + } self.timeline = new vis.Timeline(self.$timeline.empty().get(0)); self.timeline.setOptions(options); if (self.mode && self['on_scale_' + self.mode + '_clicked']) { @@ -333,7 +355,9 @@ odoo.define('web_timeline.TimelineView', function (require) { var groups = split_groups(events, group_bys); this.timeline.setGroups(groups); this.timeline.setItems(data); - this.timeline.fit(); + if (!this.default_window || this.default_window == 'fit'){ + this.timeline.fit(); + } }, do_show: function () {