diff --git a/web_timeline/__manifest__.py b/web_timeline/__manifest__.py index fe367e268..aa741f411 100644 --- a/web_timeline/__manifest__.py +++ b/web_timeline/__manifest__.py @@ -4,7 +4,7 @@ { 'name': "Web timeline", 'summary': "Interactive visualization chart to show events in time", - "version": "12.0.1.0.5", + "version": "12.0.1.1.0", "development_status": "Production/Stable", 'author': 'ACSONE SA/NV, ' 'Tecnativa, ' diff --git a/web_timeline/static/src/css/web_timeline.css b/web_timeline/static/src/css/web_timeline.css index d32d3616e..6d1244f93 100644 --- a/web_timeline/static/src/css/web_timeline.css +++ b/web_timeline/static/src/css/web_timeline.css @@ -29,3 +29,20 @@ left: 0px; top: 0px; } + +.oe_timeline_view .vis-item .oe_timeline_duplicate_button { + position: absolute; + top: 0px; + left: -24px; + width: 24px; + height: 24px; + box-sizing: border-box; + padding: 0 5px; + cursor: pointer; + line-height: 24px; +} + +.oe_timeline_view .vis-item .oe_timeline_duplicate_button:hover { + color: #FFF; + background-color: #000; +} diff --git a/web_timeline/static/src/js/timeline_controller.js b/web_timeline/static/src/js/timeline_controller.js index 1e2969fed..3cb8fb4ae 100644 --- a/web_timeline/static/src/js/timeline_controller.js +++ b/web_timeline/static/src/js/timeline_controller.js @@ -16,6 +16,7 @@ odoo.define('web_timeline.TimelineController', function (require) { onRemove: '_onRemove', onMove: '_onMove', onAdd: '_onAdd', + onDuplicate: '_onDuplicate' }), /** @@ -133,6 +134,25 @@ odoo.define('web_timeline.TimelineController', function (require) { } }, + /** + * Gets triggered when a timeline item is duplicated (triggered by the TimelineRenderer). + * + * @private + */ + _onDuplicate: function (event) { + var self = this; + return this._rpc({ + model: this.model.modelName, + method: 'copy', + args: [event.data.id], + context: this.getSession().user_context, + }) + .then(function (res_id) { + self.create_completed([res_id]); + event.data.callback(); + }); + }, + /** * Gets triggered when a timeline item is moved (triggered by the TimelineRenderer). * diff --git a/web_timeline/static/src/js/timeline_renderer.js b/web_timeline/static/src/js/timeline_renderer.js index 4a0038ce6..6bcb2538d 100644 --- a/web_timeline/static/src/js/timeline_renderer.js +++ b/web_timeline/static/src/js/timeline_renderer.js @@ -12,6 +12,7 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { var _t = core._t; + var qweb = core.qweb; var TimelineRenderer = AbstractRenderer.extend({ template: "TimelineView", @@ -22,6 +23,7 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { 'click .oe_timeline_button_scale_week': '_onScaleWeekClicked', 'click .oe_timeline_button_scale_month': '_onScaleMonthClicked', 'click .oe_timeline_button_scale_year': '_onScaleYearClicked', + 'click .oe_timeline_duplicate_button': '_onDuplicateClicked' }), /** @@ -157,6 +159,43 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { } }, + /** + * Triggers when an item is selected or deselected. + * + * @private + */ + _onSelect: function (ev) { + var notSelectedIds = _.difference( + this.timeline.itemsData.getIds(), + ev.items + ); + _.each(notSelectedIds, function (id) { + this.$(_.str.sprintf('.oe_timeline_duplicate_button[data-id="%s"]', id)).remove(); + }.bind(this)); + + _.each(ev.items, function (id) { + var $deleteButton = $(this.timeline.itemSet.items[id].dom.deleteButton); + var $duplicateButton = $(qweb.render('TimelineView.DuplicateButton', { + id: id + })); + $deleteButton.after($duplicateButton); + }.bind(this)); + }, + + /** + * Triggers when the user clicks on the duplicate button. + * + * @private + */ + _onDuplicateClicked: function (ev) { + var $duplicateButton = $(ev.currentTarget); + var id = $duplicateButton.data('id'); + this.trigger_up('onDuplicate', { + id: id, + callback: function () {} + }); + }, + /** * Computes the initial visible window. * @@ -228,6 +267,7 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { self['on_scale_' + self.mode + '_clicked'](); } this.timeline.on('click', self.on_group_click); + this.timeline.on('select', this._onSelect.bind(this)); var group_bys = this.arch.attrs.default_group_by.split(','); this.last_group_bys = group_bys; this.last_domains = this.modelClass.data.domain; diff --git a/web_timeline/static/src/xml/web_timeline.xml b/web_timeline/static/src/xml/web_timeline.xml index 1c2f7c9db..41aac853c 100644 --- a/web_timeline/static/src/xml/web_timeline.xml +++ b/web_timeline/static/src/xml/web_timeline.xml @@ -23,4 +23,11 @@ + +
+