diff --git a/addons/web/static/src/js/views/kanban/kanban_record.js b/addons/web/static/src/js/views/kanban/kanban_record.js index 48f1aacf4ad..94621211d2d 100644 --- a/addons/web/static/src/js/views/kanban/kanban_record.js +++ b/addons/web/static/src/js/views/kanban/kanban_record.js @@ -182,24 +182,30 @@ var KanbanRecord = Widget.extend({ */ _getImageURL: function (model, field, id, cache, options) { options = options || {}; + id = (_.isArray(id) ? id[0] : id) || false; + field = options.preview_image || field; + var isCurrentRecord = this.modelName === model && this.recordData.id === id; var url; - if (this.record[field] && this.record[field].raw_value && !utils.is_bin_size(this.record[field].raw_value)) { + if (isCurrentRecord && this.record[field] && this.record[field].raw_value && !utils.is_bin_size(this.record[field].raw_value)) { // Use magic-word technique for detecting image type url = 'data:image/' + this.file_type_magic_word[this.record[field].raw_value[0]] + ';base64,' + this.record[field].raw_value; - } else if (this.record[field] && ! this.record[field].raw_value) { + } else if (!model || !field || !id || (isCurrentRecord && this.record[field] && !this.record[field].raw_value)) { url = "/web/static/src/img/placeholder.png"; } else { - if (_.isArray(id)) { id = id[0]; } - if (!id) { id = undefined; } - if (options.preview_image) - field = options.preview_image; - var unique = this.record.__last_update && this.record.__last_update.value.replace(/[^0-9]/g, ''); var session = this.getSession(); - url = session.url('/web/image', {model: model, field: field, id: id, unique: unique}); + var params = { + model: model, + field: field, + id: id + }; + if (isCurrentRecord) { + params.unique = this.record.__last_update && this.record.__last_update.value.replace(/[^0-9]/g, ''); + } if (cache !== undefined) { // Set the cache duration in seconds. - url += '&cache=' + parseInt(cache, 10); + params.cache = parseInt(cache, 10); } + url = session.url('/web/image', params); } return url; }, diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index a012eff1ca8..3b9e6435536 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -4847,7 +4847,7 @@ QUnit.module('Views', { } }); - QUnit.test('test displaying image (URL)', function (assert) { + QUnit.test('test displaying image (URL, image field not set)', function (assert) { assert.expect(1); var kanban = createView({ @@ -4899,6 +4899,39 @@ QUnit.module('Views', { kanban.destroy(); }); + QUnit.test('test displaying image (for another record)', function (assert) { + assert.expect(2); + + var kanban = createView({ + View: KanbanView, + model: 'partner', + data: this.data, + arch: '' + + '' + + '' + + '
' + + '' + + '
' + + '
', + mockRPC: function (route, args) { + if (route === 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACAA==') { + assert.ok("The view's image should have been fetched."); + return $.when(); + } + return this._super.apply(this, arguments); + }, + }); + + // the field image is set, but we request the image for a specific id + // -> for the record matching the ID, the base64 should be returned + // -> for all the other records, the image should be displayed by url + var imageOnRecord = kanban.$('img[data-src*="/web/image"][data-src*="&id=1"]'); + assert.strictEqual(imageOnRecord.length, this.data.partner.records.length - 1, + "display image by url when requested for another record"); + + kanban.destroy(); + }); + QUnit.test('check if the view destroys all widgets and instances', function (assert) { assert.expect(1);