[FIX] project: fix traceback while setting cover image
from project task kanban view (PR #17165)
This commit is contained in:
@@ -51,19 +51,23 @@ KanbanRecord.include({
|
||||
}
|
||||
|
||||
function open_cover_images_dialog(attachment_ids) {
|
||||
var cover_id = self.record.displayed_image_id.raw_value[0];
|
||||
var coverID = self.record.displayed_image_id && self.record.displayed_image_id.raw_value[0];
|
||||
var $content = $(QWeb.render("project.SetCoverModal", {
|
||||
cover_id: cover_id,
|
||||
cover_id: coverID,
|
||||
attachment_ids: attachment_ids,
|
||||
}));
|
||||
var $imgs = $content.find('img');
|
||||
|
||||
var dialog = new Dialog(self, {
|
||||
title: _t("Set a Cover Image"),
|
||||
buttons: [{text: _t("Select"), classes: 'btn-primary', close: true, disabled: !cover_id, click: function () {
|
||||
self._updateRecord({displayed_image_id: $imgs.filter('.o_selected').data('id')});
|
||||
buttons: [{text: _t("Select"), classes: 'btn-primary', close: true, disabled: !coverID, click: function () {
|
||||
var $img = $imgs.filter('.o_selected');
|
||||
var data = {
|
||||
id: $img.data('id'),
|
||||
display_name: $img.data('name')
|
||||
};
|
||||
self._updateRecord({displayed_image_id: data});
|
||||
}}, {text: _t("Remove Cover Image"), close: true, click: function () {
|
||||
self._updateRecord({displayed_image_id: 0});
|
||||
self._updateRecord({displayed_image_id: false});
|
||||
}}, {text: _t("Discard"), close: true}],
|
||||
$content: $content,
|
||||
}).open();
|
||||
@@ -75,7 +79,12 @@ KanbanRecord.include({
|
||||
});
|
||||
|
||||
$content.on('dblclick', 'img', function (ev) {
|
||||
self._updateRecord({displayed_image_id: $(ev.currentTarget).data('id')});
|
||||
var $img = $(ev.currentTarget);
|
||||
var data = {
|
||||
id: $img.data('id'),
|
||||
display_name: $img.data('name')
|
||||
};
|
||||
self._updateRecord({displayed_image_id: data});
|
||||
dialog.close();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="project.SetCoverModal">
|
||||
<div t-if="attachment_ids.length > 0" class="o_kanban_task_cover_image">
|
||||
<img t-foreach="attachment_ids" t-as="attachment" t-attf-class="img-responsive#{cover_id == attachment['id'] ? ' o_selected' : ''}" t-attf-src="/web/image/#{attachment['id']}?unique=1" t-att-data-id="attachment['id']"/>
|
||||
<img t-foreach="attachment_ids" t-as="attachment" t-attf-class="img-responsive#{cover_id == attachment['id'] ? ' o_selected' : ''}" t-attf-src="/web/image/#{attachment['id']}?unique=1" t-att-data-id="attachment['id']" t-att-data-name="attachment['name']"/>
|
||||
</div>
|
||||
<div t-if="attachment_ids.length == 0">There is no available image to be set as cover. Send a message on the task with an attached image.</div>
|
||||
</t>
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
odoo.define('project.project_kanban_tests', function (require) {
|
||||
"use strict";
|
||||
|
||||
var KanbanView = require('web.KanbanView');
|
||||
var testUtils = require('web.test_utils');
|
||||
|
||||
var createView = testUtils.createView;
|
||||
|
||||
QUnit.module('project', {
|
||||
beforeEach: function () {
|
||||
this.data = {
|
||||
'ir.attachment': {
|
||||
fields: {
|
||||
name: {
|
||||
string: "Name",
|
||||
type: "char"
|
||||
},
|
||||
},
|
||||
records: [{
|
||||
id: 1,
|
||||
name: "1.png"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "2.png"
|
||||
},
|
||||
]
|
||||
},
|
||||
'project.task': {
|
||||
fields: {
|
||||
name: {
|
||||
string: "Task Title",
|
||||
type: "char"
|
||||
},
|
||||
sequence: {
|
||||
string: "sequence",
|
||||
type: "integer"
|
||||
},
|
||||
displayed_image_id: {
|
||||
string: "cover",
|
||||
type: "many2one",
|
||||
relation: "ir.attachment"
|
||||
},
|
||||
kanban_state: {
|
||||
string: "State",
|
||||
type: "selection",
|
||||
selection: [
|
||||
["abc", "ABC"],
|
||||
["def", "DEF"],
|
||||
["ghi", "GHI"]
|
||||
]
|
||||
},
|
||||
},
|
||||
records: [{
|
||||
id: 1,
|
||||
name: "task1",
|
||||
sequence: 1,
|
||||
kanban_state: "abc"
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: "task2",
|
||||
sequence: 2,
|
||||
kanban_state: "abc"
|
||||
},
|
||||
]
|
||||
},
|
||||
};
|
||||
}
|
||||
}, function () {
|
||||
QUnit.module('image test');
|
||||
|
||||
QUnit.test('cover_image_test', function (assert) {
|
||||
assert.expect(6);
|
||||
var kanban = createView({
|
||||
View: KanbanView,
|
||||
model: 'project.task',
|
||||
data: this.data,
|
||||
arch: '<kanban class="o_kanban_test">' +
|
||||
'<templates>' +
|
||||
'<t t-name="kanban-box">' +
|
||||
'<div>' +
|
||||
'<field name="name"/>' +
|
||||
'<div class="o_dropdown_kanban dropdown">' +
|
||||
'<a class="dropdown-toggle btn" data-toggle="dropdown" href="#">' +
|
||||
'<span class="fa fa-bars fa-lg"/>' +
|
||||
'</a>' +
|
||||
'<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">' +
|
||||
'<li>' +
|
||||
'<a type="set_cover">Set Cover Image</a>'+
|
||||
'</li>' +
|
||||
'</ul>' +
|
||||
'</div>' +
|
||||
'<div>'+
|
||||
'<field name="displayed_image_id" widget="attachment_image"/>'+
|
||||
'</div>'+
|
||||
'</div>' +
|
||||
'</t>' +
|
||||
'</templates>' +
|
||||
'</kanban>',
|
||||
mockRPC: function(route, args) {
|
||||
if (args.model === 'ir.attachment' && args.method === 'search_read') {
|
||||
return $.when([{
|
||||
id: 1,
|
||||
name: "1.png"
|
||||
},{
|
||||
id: 2,
|
||||
name: "2.png"
|
||||
}]);
|
||||
}
|
||||
if (args.model === 'project.task' && args.method === 'write') {
|
||||
assert.step(args.args[0][0]);
|
||||
return this._super(route, args);
|
||||
}
|
||||
return this._super(route, args);
|
||||
},
|
||||
});
|
||||
assert.strictEqual(kanban.$('img').length, 0, "Initially there is no image.");
|
||||
kanban.$('.o_dropdown_kanban [data-type=set_cover]').eq(0).click();
|
||||
// single click on image
|
||||
$('.modal').find("img[data-id='1']").click();
|
||||
$('.modal-footer .btn-primary').click();
|
||||
assert.strictEqual(kanban.$('img[src*="/web/image/1"]').length, 1, "Image inserted in record");
|
||||
$('.o_dropdown_kanban [data-type=set_cover]').eq(1).click();
|
||||
// double click on image
|
||||
$('.modal').find("img[data-id='2']").dblclick();
|
||||
assert.strictEqual(kanban.$('img[src*="/web/image/2"]').length, 1, "Image inserted after double click");
|
||||
// varify write on both kanban record
|
||||
assert.verifySteps([1,2]);
|
||||
kanban.destroy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -10,4 +10,9 @@
|
||||
<script type="text/javascript" src="/project/static/src/js/web_planner_project.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
<template id="qunit_suite" name="project_test" inherit_id="web.qunit_suite">
|
||||
<xpath expr="//t[@t-set='head']" position="inside">
|
||||
<script type="text/javascript" src="/project/static/tests/project_tests.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
|
||||
@@ -1281,8 +1281,26 @@ var PriorityWidget = AbstractField.extend({
|
||||
},
|
||||
});
|
||||
|
||||
var AttachmentImage = AbstractField.extend({
|
||||
template: 'AttachmentImage',
|
||||
var AttachmentImage = AbstractField.extend({
|
||||
className: 'o_attachment_image',
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Private
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reset cover image when widget value change
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
_render: function () {
|
||||
if (this.value) {
|
||||
this.$el.empty().append($('<img>/', {
|
||||
src: "/web/image/" + this.value.data.id + "?unique=1",
|
||||
title: this.value.data.display_name
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var StateSelectionWidget = AbstractField.extend({
|
||||
|
||||
@@ -835,11 +835,6 @@
|
||||
t-att-width="widget.node.attrs.img_width || widget.node.attrs.width"
|
||||
t-att-height="widget.node.attrs.img_height || widget.node.attrs.height"/>
|
||||
</t>
|
||||
<t t-name="AttachmentImage">
|
||||
<div class="o_attachment_image">
|
||||
<img t-att-src="'/web/image/' + widget.value + '?unique=1'"/>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="FieldBinaryFile">
|
||||
<a t-if="widget.mode === 'readonly'" href="javascript:void(0)" class="o_form_uri"/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user