mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-23 04:22:04 -06:00
[FIX] pylint/javascript-lint
This commit is contained in:
parent
7aedeff413
commit
f31e4d6004
@ -1,7 +1,7 @@
|
|||||||
///* Copyright 2014 Therp BV (<http://therp.nl>)
|
/* Copyright 2014 Therp BV (<http://therp.nl>)
|
||||||
// * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
||||||
|
|
||||||
odoo.define('attachment_preview', function(require) {
|
odoo.define('attachment_preview', function (require) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var core = require('web.core');
|
var core = require('web.core');
|
||||||
@ -14,16 +14,15 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
var Widget = require('web.Widget');
|
var Widget = require('web.Widget');
|
||||||
|
|
||||||
var AttachmentPreviewMixin = {
|
var AttachmentPreviewMixin = {
|
||||||
canPreview: function(extension) {
|
canPreview: function (extension) {
|
||||||
return $.inArray(
|
return $.inArray(
|
||||||
extension,
|
extension,
|
||||||
[
|
['odt', 'odp', 'ods', 'fodt', 'pdf', 'ott', 'fodp', 'otp',
|
||||||
'odt', 'odp', 'ods', 'fodt', 'pdf', 'ott', 'fodp', 'otp',
|
'fods', 'ots',
|
||||||
'fods', 'ots'
|
|
||||||
]) > -1;
|
]) > -1;
|
||||||
},
|
},
|
||||||
|
|
||||||
getUrl: function(attachment_id, attachment_url, attachment_extension, attachment_title) {
|
getUrl: function (attachment_id, attachment_url, attachment_extension, attachment_title) {
|
||||||
var url = (window.location.origin || '') +
|
var url = (window.location.origin || '') +
|
||||||
'/attachment_preview/static/lib/ViewerJS/index.html' +
|
'/attachment_preview/static/lib/ViewerJS/index.html' +
|
||||||
'?type=' + encodeURIComponent(attachment_extension) +
|
'?type=' + encodeURIComponent(attachment_extension) +
|
||||||
@ -33,7 +32,7 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
|
|
||||||
showPreview: function(attachment_id, attachment_url, attachment_extension, attachment_title, split_screen) {
|
showPreview: function (attachment_id, attachment_url, attachment_extension, attachment_title, split_screen) {
|
||||||
var url = this.getUrl(attachment_id, attachment_url, attachment_extension, attachment_title);
|
var url = this.getUrl(attachment_id, attachment_url, attachment_extension, attachment_title);
|
||||||
if (split_screen) {
|
if (split_screen) {
|
||||||
this.trigger_up('onAttachmentPreview', {url: url});
|
this.trigger_up('onAttachmentPreview', {url: url});
|
||||||
@ -46,51 +45,51 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
Sidebar.include(AttachmentPreviewMixin);
|
Sidebar.include(AttachmentPreviewMixin);
|
||||||
Sidebar.include({
|
Sidebar.include({
|
||||||
events: _.extend({}, Sidebar.prototype.events, {
|
events: _.extend({}, Sidebar.prototype.events, {
|
||||||
'click .o_sidebar_preview_attachment': '_onPreviewAttachment'
|
'click .o_sidebar_preview_attachment': '_onPreviewAttachment',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
previewableAttachments: null,
|
previewableAttachments: null,
|
||||||
|
|
||||||
_redraw: function () {
|
_redraw: function () {
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.getPreviewableAttachments().done(function(atts) {
|
this.getPreviewableAttachments().done(function (atts) {
|
||||||
this.previewableAttachments = atts;
|
this.previewableAttachments = atts;
|
||||||
this.updatePreviewButtons(atts);
|
this.updatePreviewButtons(atts);
|
||||||
this.trigger_up('setPreviewableAttachments', {attachments: atts});
|
this.trigger_up('setPreviewableAttachments', {attachments: atts});
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
_onPreviewAttachment: function(event) {
|
_onPreviewAttachment: function (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
var self = this,
|
var self = this,
|
||||||
$target = $(event.currentTarget),
|
$target = $(event.currentTarget),
|
||||||
split_screen = $target.attr('data-target') != 'new',
|
split_screen = $target.attr('data-target') !== 'new',
|
||||||
attachment_id = parseInt($target.attr('data-id'), 10),
|
attachment_id = parseInt($target.attr('data-id'), 10),
|
||||||
attachment_url = $target.attr('data-url'),
|
attachment_url = $target.attr('data-url'),
|
||||||
attachment_extension = $target.attr('data-extension'),
|
attachment_extension = $target.attr('data-extension'),
|
||||||
attachment_title = $target.attr('data-original-title');
|
attachment_title = $target.attr('data-original-title');
|
||||||
|
|
||||||
if(attachment_extension) {
|
if (attachment_extension) {
|
||||||
this.showPreview(attachment_id, attachment_url, attachment_extension, attachment_title, split_screen);
|
this.showPreview(attachment_id, attachment_url, attachment_extension, attachment_title, split_screen);
|
||||||
} else {
|
} else {
|
||||||
this._rpc({
|
this._rpc({
|
||||||
model: 'ir.attachment',
|
model: 'ir.attachment',
|
||||||
method: 'get_attachment_extension',
|
method: 'get_attachment_extension',
|
||||||
args: [attachment_id]
|
args: [attachment_id],
|
||||||
}).then(function(extension) {
|
}).then(function (extension) {
|
||||||
self.showPreview(attachment_id, attachment_url, extension, null, split_screen);
|
self.showPreview(attachment_id, attachment_url, extension, null, split_screen);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getPreviewableAttachments: function() {
|
getPreviewableAttachments: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
var deferred = $.Deferred();
|
var deferred = $.Deferred();
|
||||||
|
|
||||||
var $items = this.$el.find('.o_sidebar_preview_attachment');
|
var $items = this.$el.find('.o_sidebar_preview_attachment');
|
||||||
var attachments = _.object($items.map(function() {
|
var attachments = _.object($items.map(function () {
|
||||||
return parseInt($(this).attr('data-id'), 10);
|
return parseInt($(this).attr('data-id'), 10);
|
||||||
}), $items.map(function() {
|
}), $items.map(function () {
|
||||||
return {
|
return {
|
||||||
url: $(this).attr('data-url'),
|
url: $(this).attr('data-url'),
|
||||||
extension: $(this).attr('data-extension'),
|
extension: $(this).attr('data-extension'),
|
||||||
@ -102,14 +101,14 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
model: 'ir.attachment',
|
model: 'ir.attachment',
|
||||||
method: 'get_attachment_extension',
|
method: 'get_attachment_extension',
|
||||||
args: [
|
args: [
|
||||||
_.map(_.keys(attachments), function(id) {
|
_.map(_.keys(attachments), function (id) {
|
||||||
return parseInt(id, 10);
|
return parseInt(id, 10);
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
}).then(function(extensions) {
|
}).then(function (extensions) {
|
||||||
var reviewableAttachments = _.map(_.keys(_.pick(extensions, function(extension, id) {
|
var reviewableAttachments = _.map(_.keys(_.pick(extensions, function (extension, id) {
|
||||||
return self.canPreview(extension);
|
return self.canPreview(extension);
|
||||||
})), function(id) {
|
})), function (id) {
|
||||||
return {
|
return {
|
||||||
id: id,
|
id: id,
|
||||||
url: attachments[id]['url'],
|
url: attachments[id]['url'],
|
||||||
@ -120,18 +119,18 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
attachments[id]['url'],
|
attachments[id]['url'],
|
||||||
extensions[id],
|
extensions[id],
|
||||||
id + ' - ' + attachments[id]['title']
|
id + ' - ' + attachments[id]['title']
|
||||||
)
|
),
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
deferred.resolve(reviewableAttachments);
|
deferred.resolve(reviewableAttachments);
|
||||||
}, function() {
|
}, function () {
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
});
|
});
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePreviewButtons: function(previewableAttachments) {
|
updatePreviewButtons: function (previewableAttachments) {
|
||||||
this.$el.find('.o_sidebar_preview_attachment').each(function() {
|
this.$el.find('.o_sidebar_preview_attachment').each(function () {
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
var id = $this.attr('data-id');
|
var id = $this.attr('data-id');
|
||||||
var att = _.findWhere(previewableAttachments, {id: id});
|
var att = _.findWhere(previewableAttachments, {id: id});
|
||||||
@ -147,20 +146,20 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
basic_fields.FieldBinaryFile.include(AttachmentPreviewMixin);
|
basic_fields.FieldBinaryFile.include(AttachmentPreviewMixin);
|
||||||
basic_fields.FieldBinaryFile.include({
|
basic_fields.FieldBinaryFile.include({
|
||||||
events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, {
|
events: _.extend({}, basic_fields.FieldBinaryFile.prototype.events, {
|
||||||
'click .fa-search': '_onPreview'
|
'click .fa-search': '_onPreview',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
_renderReadonly: function () {
|
_renderReadonly: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this._getBinaryExtension().done(function(extension) {
|
this._getBinaryExtension().done(function (extension) {
|
||||||
if(self.canPreview(extension)) {
|
if (self.canPreview(extension)) {
|
||||||
self._renderPreviewButton(extension);
|
self._renderPreviewButton(extension);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_renderPreviewButton: function(extension) {
|
_renderPreviewButton: function (extension) {
|
||||||
this.$previewBtn = $("<span/>");
|
this.$previewBtn = $("<span/>");
|
||||||
this.$previewBtn.addClass('fa fa-search');
|
this.$previewBtn.addClass('fa fa-search');
|
||||||
this.$previewBtn.attr('title', _.str.sprintf(_t('Preview %s'), this.field.string));
|
this.$previewBtn.attr('title', _.str.sprintf(_t('Preview %s'), this.field.string));
|
||||||
@ -176,12 +175,12 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
this.model,
|
this.model,
|
||||||
this.recordData.id,
|
this.recordData.id,
|
||||||
this.name,
|
this.name,
|
||||||
this.attrs.filename
|
this.attrs.filename,
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_onPreview: function(event) {
|
_onPreview: function (event) {
|
||||||
this.showPreview(
|
this.showPreview(
|
||||||
null,
|
null,
|
||||||
_.str.sprintf(
|
_.str.sprintf(
|
||||||
@ -194,7 +193,7 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
_.str.sprintf(_t('Preview %s'), this.field.string),
|
_.str.sprintf(_t('Preview %s'), this.field.string),
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var AttachmentPreviewWidget = Widget.extend({
|
var AttachmentPreviewWidget = Widget.extend({
|
||||||
@ -237,7 +236,7 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
window.open(this.attachments[this.activeIndex].previewUrl);
|
window.open(this.attachments[this.activeIndex].previewUrl);
|
||||||
},
|
},
|
||||||
|
|
||||||
next: function() {
|
next: function () {
|
||||||
var index = this.activeIndex + 1;
|
var index = this.activeIndex + 1;
|
||||||
if (index >= this.attachments.length) {
|
if (index >= this.attachments.length) {
|
||||||
index = 0;
|
index = 0;
|
||||||
@ -247,7 +246,7 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
this.loadPreview();
|
this.loadPreview();
|
||||||
},
|
},
|
||||||
|
|
||||||
previous: function() {
|
previous: function () {
|
||||||
var index = this.activeIndex - 1;
|
var index = this.activeIndex - 1;
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
index = this.attachments.length - 1;
|
index = this.attachments.length - 1;
|
||||||
@ -267,13 +266,13 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
this.trigger('hidden');
|
this.trigger('hidden');
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePaginator: function() {
|
updatePaginator: function () {
|
||||||
var value = _.str.sprintf('%s / %s', this.activeIndex + 1, this.attachments.length);
|
var value = _.str.sprintf('%s / %s', this.activeIndex + 1, this.attachments.length);
|
||||||
this.$current.html(value);
|
this.$current.html(value);
|
||||||
},
|
},
|
||||||
|
|
||||||
loadPreview: function() {
|
loadPreview: function () {
|
||||||
if (this.attachments.length == 0) {
|
if (this.attachments.length === 0) {
|
||||||
this.$iframe.attr('src', 'about:blank');
|
this.$iframe.attr('src', 'about:blank');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -282,18 +281,18 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
this.$iframe.attr('src', att.previewUrl);
|
this.$iframe.attr('src', att.previewUrl);
|
||||||
},
|
},
|
||||||
|
|
||||||
setAttachments: function(attachments) {
|
setAttachments: function (attachments) {
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
this.activeIndex = 0;
|
this.activeIndex = 0;
|
||||||
this.updatePaginator();
|
this.updatePaginator();
|
||||||
this.loadPreview();
|
this.loadPreview();
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
FormRenderer.include({
|
FormRenderer.include({
|
||||||
attachmentPreviewWidget: null,
|
attachmentPreviewWidget: null,
|
||||||
|
|
||||||
init: function() {
|
init: function () {
|
||||||
var res = this._super.apply(this, arguments);
|
var res = this._super.apply(this, arguments);
|
||||||
this.attachmentPreviewWidget = new AttachmentPreviewWidget(this);
|
this.attachmentPreviewWidget = new AttachmentPreviewWidget(this);
|
||||||
this.attachmentPreviewWidget.on('hidden', this, this._attachmentPreviewWidgetHidden);
|
this.attachmentPreviewWidget.on('hidden', this, this._attachmentPreviewWidgetHidden);
|
||||||
@ -305,7 +304,7 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
this.attachmentPreviewWidget.insertAfter(this.$el);
|
this.attachmentPreviewWidget.insertAfter(this.$el);
|
||||||
},
|
},
|
||||||
|
|
||||||
_attachmentPreviewWidgetHidden: function() {
|
_attachmentPreviewWidgetHidden: function () {
|
||||||
this.$el.removeClass('attachment_preview');
|
this.$el.removeClass('attachment_preview');
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -320,29 +319,29 @@ odoo.define('attachment_preview', function(require) {
|
|||||||
on_detach_callback: function () {
|
on_detach_callback: function () {
|
||||||
this.attachmentPreviewWidget.hide();
|
this.attachmentPreviewWidget.hide();
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
}
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
FormController.include({
|
FormController.include({
|
||||||
custom_events: _.extend({}, FormController.prototype.custom_events, {
|
custom_events: _.extend({}, FormController.prototype.custom_events, {
|
||||||
onAttachmentPreview: '_onAttachmentPreview',
|
onAttachmentPreview: '_onAttachmentPreview',
|
||||||
setPreviewableAttachments: '_setPreviewableAttachments'
|
setPreviewableAttachments: '_setPreviewableAttachments',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
_onAttachmentPreview: function (event) {
|
_onAttachmentPreview: function (event) {
|
||||||
this.renderer.showAttachmentPreviewWidget();
|
this.renderer.showAttachmentPreviewWidget();
|
||||||
},
|
},
|
||||||
|
|
||||||
_setPreviewableAttachments: function(event) {
|
_setPreviewableAttachments: function (event) {
|
||||||
this.renderer.attachmentPreviewWidget.setAttachments(
|
this.renderer.attachmentPreviewWidget.setAttachments(
|
||||||
event.data.attachments
|
event.data.attachments
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
AttachmentPreviewMixin: AttachmentPreviewMixin,
|
AttachmentPreviewMixin: AttachmentPreviewMixin,
|
||||||
AttachmentPreviewWidget: AttachmentPreviewWidget
|
AttachmentPreviewWidget: AttachmentPreviewWidget,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
// This file contains tweaks for viewerjs itself and is not meant to be run in
|
// This file contains tweaks for viewerjs itself and is not meant to be run in
|
||||||
// OpenERP's context
|
// OpenERP's context
|
||||||
(function(original_Viewer) {
|
(function (original_Viewer) {
|
||||||
window.Viewer = function(plugin, parameters) {
|
window.Viewer = function (plugin, parameters) {
|
||||||
if(!plugin) {
|
if (!plugin) {
|
||||||
// eslint-disable-next-line no-alert
|
// eslint-disable-next-line no-alert
|
||||||
alert('Unsupported file type');
|
alert('Unsupported file type');
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user