[IMP] added preview_image and size in images

bzr revid: nicolas.vanhoren@openerp.com-20120821161517-umnu1465gq809orj
This commit is contained in:
niv-openerp 2012-08-21 18:15:17 +02:00
parent 47175ac608
commit a70222628b
4 changed files with 24 additions and 8 deletions

View File

@ -505,8 +505,8 @@
margin: 4px;
}
.openerp .oe_avatar > img {
height: 90px;
max-width: 100px;
max-height: 90px;
max-width: 90px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
border-radius: 3px;

View File

@ -426,8 +426,8 @@ $sheet-max-width: 860px
margin: 4px
.oe_avatar
> img
height: 90px
max-width: 100px
max-height: 90px
max-width: 90px
@include radius(3px)
@include box-shadow(0 1px 3px rgba(0, 0, 0, 0.3))
border: none

View File

@ -4635,19 +4635,32 @@ instance.web.form.FieldBinaryImage = instance.web.form.FieldBinary.extend({
this.render_value();
},
render_value: function() {
var self = this;
var url;
if (this.get('value') && ! /^\d+(\.\d*)? \w+$/.test(this.get('value'))) {
url = 'data:image/png;base64,' + this.get('value');
} else if (this.get('value')) {
var id = escape(JSON.stringify(this.view.datarecord.id || null));
var field = this.name;
if (this.options.preview_image)
field = this.options.preview_image;
url = '/web/binary/image?session_id=' + this.session.session_id + '&model=' +
this.view.dataset.model +'&id=' + id + '&field=' + this.name + '&t=' + (new Date().getTime());
this.view.dataset.model +'&id=' + id + '&field=' + field + '&t=' + (new Date().getTime());
} else {
url = "/web/static/src/img/placeholder.png";
}
var img = QWeb.render("FieldBinaryImage-img", { widget: this, url: url });
var $img = $(QWeb.render("FieldBinaryImage-img", { widget: this, url: url }));
this.$element.find('> img').remove();
this.$element.prepend(img);
this.$element.prepend($img);
$img.load(function() {
if (! self.options.size)
return;
debugger;
$img.css("max-width", "" + self.options.size[0] + "px");
$img.css("max-height", "" + self.options.size[1] + "px");
$img.css("margin-left", "" + (self.options.size[0] - $img.width()) / 2 + "px");
$img.css("margin-top", "" + (self.options.size[1] - $img.height()) / 2 + "px");
});
},
on_file_change: function() {
this.render_value();

View File

@ -865,7 +865,8 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
var email_md5 = $.md5(email);
return 'http://www.gravatar.com/avatar/' + email_md5 + '.png?s=' + size + '&d=' + default_;
},
kanban_image: function(model, field, id, cache) {
kanban_image: function(model, field, id, cache, options) {
options = options || {};
var url;
if (this.record[field] && this.record[field].value && ! /^\d+(\.\d*)? \w+$/.test(this.record[field].value)) {
url = 'data:image/png;base64,' + this.record[field].value;
@ -873,6 +874,8 @@ instance.web_kanban.KanbanRecord = instance.web.Widget.extend({
url = "/web/static/src/img/placeholder.png";
} else {
id = escape(JSON.stringify(id));
if (options.preview_image)
field = options.preview_image;
url = instance.session.prefix + '/web/binary/image?session_id=' + this.session.session_id + '&model=' + model + '&field=' + field + '&id=' + id;
if (cache !== undefined) {
// Set the cache duration in seconds.