mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 20:12:04 -06:00
[ADD] allow previewing binary fields on forms
[FIX] error on list views without binary fields
This commit is contained in:
parent
73a5af01bd
commit
a37bbf563c
@ -19,3 +19,8 @@
|
||||
-webkit-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.openerp .oe-binary-preview
|
||||
{
|
||||
cursor: pointer;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user