mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-26 18:38:41 -06:00
first set of fix in js
This commit is contained in:
parent
3f10957589
commit
f333a387ec
@ -19,10 +19,23 @@
|
|||||||
//
|
//
|
||||||
//############################################################################
|
//############################################################################
|
||||||
|
|
||||||
openerp.attachment_preview = function(instance)
|
odoo.define('attachment_preview.attachment_preview', function(require) {
|
||||||
{
|
"use strict";
|
||||||
var _t = instance.web._t;
|
|
||||||
openerp.attachment_preview.show_preview = function(
|
/* global _, jQuery, odoo */
|
||||||
|
|
||||||
|
var core = require('web.core');
|
||||||
|
var Model = require('web.DataModel');
|
||||||
|
var Sidebar = require('web.Sidebar');
|
||||||
|
var ListView = require('web.ListView');
|
||||||
|
var Binary = require('web.list.Binary');
|
||||||
|
var FieldBinaryFile = require('web.form.FieldBinaryFile');
|
||||||
|
var session = require('web.session');
|
||||||
|
|
||||||
|
var _t = core._t;
|
||||||
|
|
||||||
|
var AttachementPreview = core.Class.extend({
|
||||||
|
show_preview : function(
|
||||||
attachment_id, attachment_url, attachment_extension,
|
attachment_id, attachment_url, attachment_extension,
|
||||||
attachment_title)
|
attachment_title)
|
||||||
{
|
{
|
||||||
@ -32,8 +45,9 @@ openerp.attachment_preview = function(instance)
|
|||||||
'&title=' + encodeURIComponent(attachment_title) +
|
'&title=' + encodeURIComponent(attachment_title) +
|
||||||
'&ext=.' + encodeURIComponent(attachment_extension);
|
'&ext=.' + encodeURIComponent(attachment_extension);
|
||||||
window.open(url);
|
window.open(url);
|
||||||
};
|
},
|
||||||
openerp.attachment_preview.can_preview = function(extension)
|
|
||||||
|
can_preview : function(extension)
|
||||||
{
|
{
|
||||||
return jQuery.inArray(
|
return jQuery.inArray(
|
||||||
extension,
|
extension,
|
||||||
@ -41,9 +55,10 @@ openerp.attachment_preview = function(instance)
|
|||||||
'odt', 'odp', 'ods', 'fodt', 'pdf', 'ott', 'fodp', 'otp',
|
'odt', 'odp', 'ods', 'fodt', 'pdf', 'ott', 'fodp', 'otp',
|
||||||
'fods', 'ots'
|
'fods', 'ots'
|
||||||
]) > -1;
|
]) > -1;
|
||||||
};
|
},
|
||||||
instance.web.Sidebar.include(
|
});
|
||||||
{
|
|
||||||
|
Sidebar.include({
|
||||||
on_attachments_loaded: function(attachments)
|
on_attachments_loaded: function(attachments)
|
||||||
{
|
{
|
||||||
var result = this._super.apply(this, arguments);
|
var result = this._super.apply(this, arguments);
|
||||||
@ -64,17 +79,17 @@ openerp.attachment_preview = function(instance)
|
|||||||
attachment_title = $target.attr('data-original-title');
|
attachment_title = $target.attr('data-original-title');
|
||||||
if(attachment_extension)
|
if(attachment_extension)
|
||||||
{
|
{
|
||||||
openerp.attachment_preview.show_preview(
|
AttachementPreview.show_preview(
|
||||||
attachment_id, attachment_url, attachment_extension,
|
attachment_id, attachment_url, attachment_extension,
|
||||||
attachment_title);
|
attachment_title);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(new instance.web.Model('ir.attachment')).call(
|
(new Model('ir.attachment')).call(
|
||||||
'get_attachment_extension', [attachment_id], {})
|
'get_attachment_extension', [attachment_id], {})
|
||||||
.then(function(extension)
|
.then(function(extension)
|
||||||
{
|
{
|
||||||
openerp.attachment_preview.show_preview(
|
AttachementPreview.show_preview(
|
||||||
attachment_id, attachment_url, extension);
|
attachment_id, attachment_url, extension);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -82,7 +97,7 @@ openerp.attachment_preview = function(instance)
|
|||||||
update_preview_buttons: function()
|
update_preview_buttons: function()
|
||||||
{
|
{
|
||||||
var self = this;
|
var self = this;
|
||||||
return (new instance.web.Model('ir.attachment')).call(
|
return (new Model('ir.attachment')).call(
|
||||||
'get_attachment_extension',
|
'get_attachment_extension',
|
||||||
[
|
[
|
||||||
this.$el.find('.oe-sidebar-attachment-preview')
|
this.$el.find('.oe-sidebar-attachment-preview')
|
||||||
@ -100,7 +115,7 @@ openerp.attachment_preview = function(instance)
|
|||||||
var $element = jQuery(
|
var $element = jQuery(
|
||||||
'a.oe-sidebar-attachment-preview[data-id="'
|
'a.oe-sidebar-attachment-preview[data-id="'
|
||||||
+ id + '"]');
|
+ id + '"]');
|
||||||
if(openerp.attachment_preview.can_preview(extension))
|
if(AttachementPreview.can_preview(extension))
|
||||||
{
|
{
|
||||||
$element.attr('data-extension', extension);
|
$element.attr('data-extension', extension);
|
||||||
}
|
}
|
||||||
@ -112,8 +127,8 @@ openerp.attachment_preview = function(instance)
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
instance.web.ListView.include(
|
|
||||||
{
|
ListView.include({
|
||||||
reload_content: function()
|
reload_content: function()
|
||||||
{
|
{
|
||||||
var deferred = this._super.apply(this, arguments),
|
var deferred = this._super.apply(this, arguments),
|
||||||
@ -131,13 +146,13 @@ openerp.attachment_preview = function(instance)
|
|||||||
var $target = jQuery(e.currentTarget),
|
var $target = jQuery(e.currentTarget),
|
||||||
attachment_id = parseInt($target.attr('data-id')),
|
attachment_id = parseInt($target.attr('data-id')),
|
||||||
attachment_extension = $target.attr('data-extension');
|
attachment_extension = $target.attr('data-extension');
|
||||||
openerp.attachment_preview.show_preview(
|
AttachementPreview.show_preview(
|
||||||
attachment_id,
|
attachment_id,
|
||||||
$target.siblings('a').attr('href'),
|
$target.siblings('a').attr('href'),
|
||||||
attachment_extension,
|
attachment_extension,
|
||||||
$target.attr('alt'));
|
$target.attr('alt'));
|
||||||
});
|
});
|
||||||
return (new instance.web.Model('ir.attachment')).call(
|
return (new Model('ir.attachment')).call(
|
||||||
'get_binary_extension',
|
'get_binary_extension',
|
||||||
[
|
[
|
||||||
$elements.attr('data-model'),
|
$elements.attr('data-model'),
|
||||||
@ -157,7 +172,7 @@ openerp.attachment_preview = function(instance)
|
|||||||
{
|
{
|
||||||
var $element = $elements.filter(
|
var $element = $elements.filter(
|
||||||
'[data-id="' + id + '"]');
|
'[data-id="' + id + '"]');
|
||||||
if(openerp.attachment_preview.can_preview(extension))
|
if(AttachementPreview.can_preview(extension))
|
||||||
{
|
{
|
||||||
$element.attr('data-extension', extension);
|
$element.attr('data-extension', extension);
|
||||||
}
|
}
|
||||||
@ -171,8 +186,8 @@ openerp.attachment_preview = function(instance)
|
|||||||
return deferred;
|
return deferred;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
instance.web.list.Binary.include(
|
|
||||||
{
|
Binary.include({
|
||||||
_format: function (row_data, options)
|
_format: function (row_data, options)
|
||||||
{
|
{
|
||||||
var link = this._super.apply(this, arguments);
|
var link = this._super.apply(this, arguments);
|
||||||
@ -187,8 +202,9 @@ openerp.attachment_preview = function(instance)
|
|||||||
});
|
});
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
});
|
}),
|
||||||
instance.web.form.FieldBinaryFile.include(
|
|
||||||
|
FieldBinaryFile.include(
|
||||||
{
|
{
|
||||||
render_value: function()
|
render_value: function()
|
||||||
{
|
{
|
||||||
@ -196,8 +212,8 @@ openerp.attachment_preview = function(instance)
|
|||||||
if(this.get("effective_readonly") && this.get('value'))
|
if(this.get("effective_readonly") && this.get('value'))
|
||||||
{
|
{
|
||||||
var self = this;
|
var self = this;
|
||||||
(new instance.web.Model('ir.attachment')).call(
|
(new Model('ir.attachment')).call(
|
||||||
'get_binary_extension', [
|
'get_binary_extension',[
|
||||||
this.view.dataset.model,
|
this.view.dataset.model,
|
||||||
this.view.datarecord.id ? [this.view.datarecord.id] : [],
|
this.view.datarecord.id ? [this.view.datarecord.id] : [],
|
||||||
this.name,
|
this.name,
|
||||||
@ -209,15 +225,15 @@ openerp.attachment_preview = function(instance)
|
|||||||
_(extensions).each(function(extension)
|
_(extensions).each(function(extension)
|
||||||
{
|
{
|
||||||
var $element = self.$el.find('.oe-binary-preview');
|
var $element = self.$el.find('.oe-binary-preview');
|
||||||
if(openerp.attachment_preview.can_preview(extension))
|
if(AttachementPreview.can_preview(extension))
|
||||||
{
|
{
|
||||||
$element.click(function()
|
$element.click(function()
|
||||||
{
|
{
|
||||||
openerp.attachment_preview.show_preview(
|
AttachementPreview.show_preview(
|
||||||
null,
|
null,
|
||||||
_.str.sprintf(
|
_.str.sprintf(
|
||||||
'/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d',
|
'/web/binary/saveas?session_id=%s&model=%s&field=%s&id=%d',
|
||||||
instance.session.session_id,
|
session.session_id,
|
||||||
self.view.dataset.model,
|
self.view.dataset.model,
|
||||||
self.name,
|
self.name,
|
||||||
self.view.datarecord.id),
|
self.view.datarecord.id),
|
||||||
@ -239,4 +255,6 @@ openerp.attachment_preview = function(instance)
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
return AttachementPreview;
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user