Merge lp:~openerp-dev/openerp-web/6.1-opw-581888-msh into lp:openerp-web/6.1

Proposed by Mohammed Shekha(Open ERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openerp-web/6.1-opw-581888-msh
Merge into: lp:openerp-web/6.1
Diff against target: 20 lines (+7/-3)
1 file modified
addons/web/static/src/js/view_form.js (+7/-3)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/6.1-opw-581888-msh
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+134616@code.launchpad.net

Description of the change

Hello,

Fixed the issue of image not displayed newly created record when it is return from on_change result or from default values because still datarecord will not have id so it can not read image from database, hence set the value in src directly with content-type image/png.

Demo :- To generate this create an on_change method which returns binary image as a result, now call that on_change method will not display image in image widget, I have created an on_change method on hr.employee form for demo, added a binary field in res.users for instance.

Expected :- when on_change returns binary data it should be displayed on image widget.

Thanks.

To post a comment you must log in.

Unmerged revisions

2482. By Mohammed Shekha(Open ERP)

[FIX]Fixed the issue of image not displayed newly created record when it is return from on_change result or from default values because still datarecord will not have id so it can not read image from database, hence set the value in src directly with content-type image/png

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/view_form.js'
2--- addons/web/static/src/js/view_form.js 2012-10-23 07:30:10 +0000
3+++ addons/web/static/src/js/view_form.js 2012-11-16 07:41:22 +0000
4@@ -3562,9 +3562,13 @@
5 set_value: function(value) {
6 this._super.apply(this, arguments);
7 this.set_image_maxwidth();
8- var url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
9- this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime());
10- this.$image.attr('src', url);
11+ if(this.view.datarecord.id) {
12+ var url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
13+ this.view.dataset.model +'&id=' + (this.view.datarecord.id || '') + '&field=' + this.name + '&t=' + (new Date().getTime());
14+ this.$image.attr('src', url);
15+ }else {
16+ this.$image.attr('src', 'data:image/png;base64,' + value);
17+ }
18 },
19 set_image_maxwidth: function() {
20 this.$image.css('max-width', this.$element.width());