[IMP] web_timeline: Ability to duplicate record

[IMP] web_timeline: Ability to duplicate record
pull/1413/head
tarteo 2019-10-17 15:30:52 +02:00
parent 3f07f00ef2
commit bf168d5657
5 changed files with 85 additions and 1 deletions

View File

@ -4,7 +4,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": "12.0.1.0.5", "version": "12.0.1.1.0",
"development_status": "Production/Stable", "development_status": "Production/Stable",
'author': 'ACSONE SA/NV, ' 'author': 'ACSONE SA/NV, '
'Tecnativa, ' 'Tecnativa, '

View File

@ -29,3 +29,20 @@
left: 0px; left: 0px;
top: 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;
}

View File

@ -16,6 +16,7 @@ odoo.define('web_timeline.TimelineController', function (require) {
onRemove: '_onRemove', onRemove: '_onRemove',
onMove: '_onMove', onMove: '_onMove',
onAdd: '_onAdd', 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). * Gets triggered when a timeline item is moved (triggered by the TimelineRenderer).
* *

View File

@ -12,6 +12,7 @@ odoo.define('web_timeline.TimelineRenderer', function (require) {
var _t = core._t; var _t = core._t;
var qweb = core.qweb;
var TimelineRenderer = AbstractRenderer.extend({ var TimelineRenderer = AbstractRenderer.extend({
template: "TimelineView", 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_week': '_onScaleWeekClicked',
'click .oe_timeline_button_scale_month': '_onScaleMonthClicked', 'click .oe_timeline_button_scale_month': '_onScaleMonthClicked',
'click .oe_timeline_button_scale_year': '_onScaleYearClicked', '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. * Computes the initial visible window.
* *
@ -228,6 +267,7 @@ odoo.define('web_timeline.TimelineRenderer', function (require) {
self['on_scale_' + self.mode + '_clicked'](); self['on_scale_' + self.mode + '_clicked']();
} }
this.timeline.on('click', self.on_group_click); 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(','); var group_bys = this.arch.attrs.default_group_by.split(',');
this.last_group_bys = group_bys; this.last_group_bys = group_bys;
this.last_domains = this.modelClass.data.domain; this.last_domains = this.modelClass.data.domain;

View File

@ -23,4 +23,11 @@
</marker> </marker>
</defs> </defs>
</svg> </svg>
<div t-name="TimelineView.DuplicateButton"
t-attf-data-id="#{id}"
class="oe_timeline_duplicate_button" title="Duplicate this item">
<i class="fa fa-copy" />
</div>
</template> </template>