[ADD] allow previewing binary fields on forms

[FIX] error on list views without binary fields
This commit is contained in:
Holger Brunn 2014-09-22 17:42:08 +02:00
parent 73a5af01bd
commit a37bbf563c
3 changed files with 60 additions and 0 deletions

View File

@ -19,3 +19,8 @@
-webkit-border-radius: 2px;
border-radius: 2px;
}
.openerp .oe-binary-preview
{
cursor: pointer;
vertical-align: middle;
}

View File

@ -126,6 +126,10 @@ openerp.attachment_preview = function(instance)
deferred.then(function()
{
var $elements = self.$el.find('.oe-binary-preview');
if(!$elements.length)
{
return;
}
$elements.click(function(e)
{
e.stopPropagation();
@ -187,4 +191,50 @@ openerp.attachment_preview = function(instance)
return link;
}
});
instance.web.form.FieldBinaryFile.include(
{
render_value: function()
{
this._super.apply(this, arguments);
if(this.get("effective_readonly") && this.get('value'))
{
var self = this;
(new instance.web.Model('ir.attachment')).call(
'get_binary_extension', [
this.view.dataset.model,
this.view.datarecord.id ? [this.view.datarecord.id] : [],
this.name,
this.node.attrs.filename,
],
{})
.then(function(extensions)
{
_(extensions).each(function(extension)
{
var $element = self.$el.find('.oe-binary-preview');
if(openerp.attachment_preview.can_preview(extension))
{
$element.click(function()
{
openerp.attachment_preview.show_preview(
null,
_.str.sprintf(
'/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d',
instance.session.session_id,
self.view.dataset.model,
self.name,
self.view.datarecord.id),
extension,
self.view.datarecord[self.node.attrs.filename]);
});
}
else
{
$element.remove();
}
});
});
}
},
});
}

View File

@ -7,4 +7,9 @@
</a>
</t>
</t>
<t t-extend="FieldBinaryFile">
<t t-jquery="a.oe_form_uri" t-operation="after">
<img class="oe-binary-preview" t-att-src='_s + "/web/static/src/img/icons/gtk-print-preview.png"'/>
</t>
</t>
</templates>