[FIX] web_editor: correctly set image on double click
Commit 321486851a fixed double click on media dialog when multiple selection is
allowed.
Still, it needs a deeper fix to ensure that the image is/remains selected when
double clicking no matter it's state (selected or not) before the clicks.
Double click should always force the image to be selected before saving.
Step to reproduce:
- Drop the Image Gallery snippet
- Open new images manager (Customize > Add images or Add Images directly if no
images set yet
- Select an image (simple click)
- Now double click on it
It won't set the image since when double clicking, it:
1. Unselected the image on the first click (click event)
2. Selected the image on the second click (click event)
3. Unselected the image and saved (dblclick event)
This commit is contained in:
@@ -112,7 +112,7 @@ var ImageDialog = Widget.extend({
|
||||
'keyup input.url': "change_input",
|
||||
'click .existing-attachments [data-src]': 'select_existing',
|
||||
'dblclick .existing-attachments [data-src]': function (e) {
|
||||
this.select_existing(e);
|
||||
this.select_existing(e, true);
|
||||
this.getParent().save();
|
||||
},
|
||||
'click .o_existing_attachment_remove': 'try_remove',
|
||||
@@ -166,11 +166,13 @@ var ImageDialog = Widget.extend({
|
||||
});
|
||||
return res;
|
||||
},
|
||||
push: function (attachment) {
|
||||
push: function (attachment, force_select) {
|
||||
if (this.options.select_images) {
|
||||
var img = _.select(this.images, function (v) { return v.id === attachment.id; });
|
||||
if (img.length) {
|
||||
this.images.splice(this.images.indexOf(img[0]),1);
|
||||
if (!force_select) {
|
||||
this.images.splice(this.images.indexOf(img[0]),1);
|
||||
}
|
||||
} else {
|
||||
this.images.push(attachment);
|
||||
}
|
||||
@@ -369,10 +371,10 @@ var ImageDialog = Widget.extend({
|
||||
});
|
||||
this.selected_existing();
|
||||
},
|
||||
select_existing: function (e) {
|
||||
select_existing: function (e, force_select) {
|
||||
var $img = $(e.currentTarget);
|
||||
var attachment = _.find(this.records, function (record) { return record.id === $img.data('id'); });
|
||||
this.push(attachment);
|
||||
this.push(attachment, force_select);
|
||||
this.selected_existing();
|
||||
},
|
||||
selected_existing: function () {
|
||||
|
||||
Reference in New Issue
Block a user