mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-24 06:07:44 -06:00
[MIG] attachment_preview: Migration to 12.0
[REM] Old files [ADD] Magic to travis file [FIX] Nagivation refresh widget
This commit is contained in:
@@ -7,7 +7,7 @@ odoo.define('attachment_preview', function (require) {
|
||||
var core = require('web.core');
|
||||
var _t = core._t;
|
||||
var qweb = core.qweb;
|
||||
var Sidebar = require('web.Sidebar');
|
||||
var Chatter = require('mail.Chatter');
|
||||
var basic_fields = require('web.basic_fields');
|
||||
var FormRenderer = require('web.FormRenderer');
|
||||
var FormController = require('web.FormController');
|
||||
@@ -42,21 +42,40 @@ odoo.define('attachment_preview', function (require) {
|
||||
},
|
||||
};
|
||||
|
||||
Sidebar.include(AttachmentPreviewMixin);
|
||||
Sidebar.include({
|
||||
events: _.extend({}, Sidebar.prototype.events, {
|
||||
'click .o_sidebar_preview_attachment': '_onPreviewAttachment',
|
||||
Chatter.include(AttachmentPreviewMixin);
|
||||
Chatter.include({
|
||||
events: _.extend({}, Chatter.prototype.events, {
|
||||
'click .o_attachment_preview': '_onPreviewAttachment',
|
||||
}),
|
||||
|
||||
previewableAttachments: null,
|
||||
|
||||
_redraw: function () {
|
||||
this._super.apply(this, arguments);
|
||||
_openAttachmentBox: function () {
|
||||
var res = this._super.apply(this, arguments);
|
||||
|
||||
this.getPreviewableAttachments().done(function (atts) {
|
||||
this.previewableAttachments = atts;
|
||||
this.updatePreviewButtons(atts);
|
||||
this.trigger_up('setPreviewableAttachments', {attachments: atts});
|
||||
this.getParent().attachmentPreviewWidget.setAttachments(atts);
|
||||
}.bind(this));
|
||||
|
||||
return res;
|
||||
},
|
||||
|
||||
update: function () {
|
||||
var res = this._super.apply(this, arguments);
|
||||
var self = this;
|
||||
if (this.getParent().$el.hasClass('attachment_preview')) {
|
||||
this._fetchAttachments().done(function () {
|
||||
self._openAttachmentBox();
|
||||
self.getPreviewableAttachments().done(function (atts) {
|
||||
self.updatePreviewButtons(self.previewableAttachments);
|
||||
self.previewableAttachments = atts;
|
||||
self.getParent().attachmentPreviewWidget.setAttachments(atts);
|
||||
});
|
||||
});
|
||||
}
|
||||
return res;
|
||||
},
|
||||
|
||||
_onPreviewAttachment: function (event) {
|
||||
@@ -86,7 +105,7 @@ odoo.define('attachment_preview', function (require) {
|
||||
var self = this;
|
||||
var deferred = $.Deferred();
|
||||
|
||||
var $items = this.$el.find('.o_sidebar_preview_attachment');
|
||||
var $items = this.$el.find('.o_attachment_preview');
|
||||
var attachments = _.object($items.map(function () {
|
||||
return parseInt($(this).attr('data-id'), 10);
|
||||
}), $items.map(function () {
|
||||
@@ -111,14 +130,14 @@ odoo.define('attachment_preview', function (require) {
|
||||
})), function (id) {
|
||||
return {
|
||||
id: id,
|
||||
url: attachments[id]['url'],
|
||||
url: attachments[id].url,
|
||||
extension: extensions[id],
|
||||
title: attachments[id]['title'],
|
||||
title: attachments[id].title,
|
||||
previewUrl: self.getUrl(
|
||||
id,
|
||||
attachments[id]['url'],
|
||||
attachments[id].url,
|
||||
extensions[id],
|
||||
id + ' - ' + attachments[id]['title']
|
||||
id + ' - ' + attachments[id].title
|
||||
),
|
||||
};
|
||||
});
|
||||
@@ -130,7 +149,7 @@ odoo.define('attachment_preview', function (require) {
|
||||
},
|
||||
|
||||
updatePreviewButtons: function (previewableAttachments) {
|
||||
this.$el.find('.o_sidebar_preview_attachment').each(function () {
|
||||
this.$el.find('.o_attachment_preview').each(function () {
|
||||
var $this = $(this);
|
||||
var id = $this.attr('data-id');
|
||||
var att = _.findWhere(previewableAttachments, {id: id});
|
||||
@@ -152,19 +171,23 @@ odoo.define('attachment_preview', function (require) {
|
||||
_renderReadonly: function () {
|
||||
var self = this;
|
||||
this._super.apply(this, arguments);
|
||||
this._getBinaryExtension().done(function (extension) {
|
||||
if (self.canPreview(extension)) {
|
||||
self._renderPreviewButton(extension);
|
||||
}
|
||||
});
|
||||
|
||||
if (this.recordData.id) {
|
||||
this._getBinaryExtension().done(function (extension) {
|
||||
if (self.canPreview(extension)) {
|
||||
self._renderPreviewButton(extension);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
_renderPreviewButton: function (extension) {
|
||||
this.$previewBtn = $("<span/>");
|
||||
this.$previewBtn.addClass('fa fa-search');
|
||||
this.$previewBtn = $("<a/>");
|
||||
this.$previewBtn.addClass('fa fa-search mr-2');
|
||||
this.$previewBtn.attr('href', 'javascript:void(0)');
|
||||
this.$previewBtn.attr('title', _.str.sprintf(_t('Preview %s'), this.field.string));
|
||||
this.$previewBtn.attr('data-extension', extension);
|
||||
this.$el.find('.fa-download').after(this.$previewBtn);
|
||||
this.$el.find('.fa-download').before(this.$previewBtn);
|
||||
},
|
||||
|
||||
_getBinaryExtension: function () {
|
||||
@@ -193,6 +216,7 @@ odoo.define('attachment_preview', function (require) {
|
||||
_.str.sprintf(_t('Preview %s'), this.field.string),
|
||||
false
|
||||
);
|
||||
event.stopPropagation();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -257,12 +281,12 @@ odoo.define('attachment_preview', function (require) {
|
||||
},
|
||||
|
||||
show: function () {
|
||||
this.$el.removeClass('hidden');
|
||||
this.$el.removeClass('d-none');
|
||||
this.trigger('shown');
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
this.$el.addClass('hidden');
|
||||
this.$el.addClass('d-none');
|
||||
this.trigger('hidden');
|
||||
},
|
||||
|
||||
@@ -290,6 +314,10 @@ odoo.define('attachment_preview', function (require) {
|
||||
});
|
||||
|
||||
FormRenderer.include({
|
||||
custom_events: _.extend({}, FormRenderer.prototype.custom_events, {
|
||||
onAttachmentPreview: '_onAttachmentPreview',
|
||||
}),
|
||||
|
||||
attachmentPreviewWidget: null,
|
||||
|
||||
init: function () {
|
||||
@@ -310,8 +338,9 @@ odoo.define('attachment_preview', function (require) {
|
||||
|
||||
showAttachmentPreviewWidget: function () {
|
||||
this.$el.addClass('attachment_preview');
|
||||
|
||||
this.attachmentPreviewWidget.setAttachments(
|
||||
this.getParent().sidebar.previewableAttachments
|
||||
this.chatter.previewableAttachments
|
||||
);
|
||||
this.attachmentPreviewWidget.show();
|
||||
},
|
||||
@@ -321,25 +350,12 @@ odoo.define('attachment_preview', function (require) {
|
||||
return this._super.apply(this, arguments);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
FormController.include({
|
||||
custom_events: _.extend({}, FormController.prototype.custom_events, {
|
||||
onAttachmentPreview: '_onAttachmentPreview',
|
||||
setPreviewableAttachments: '_setPreviewableAttachments',
|
||||
}),
|
||||
|
||||
_onAttachmentPreview: function (event) {
|
||||
this.renderer.showAttachmentPreviewWidget();
|
||||
},
|
||||
|
||||
_setPreviewableAttachments: function (event) {
|
||||
this.renderer.attachmentPreviewWidget.setAttachments(
|
||||
event.data.attachments
|
||||
);
|
||||
this.showAttachmentPreviewWidget();
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
AttachmentPreviewMixin: AttachmentPreviewMixin,
|
||||
AttachmentPreviewWidget: AttachmentPreviewWidget,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
.o_cp_sidebar {
|
||||
li .o_sidebar_preview_attachment {
|
||||
position: absolute;
|
||||
top: 5px;
|
||||
right: 26px;
|
||||
background-color: #FFF;
|
||||
.o_attachments_list .o_attachment_wrap {
|
||||
.o_attachment_preview {
|
||||
cursor: pointer;
|
||||
float: right;
|
||||
padding-top: 1px;
|
||||
padding-bottom: 1px;
|
||||
|
||||
&.o_sidebar_preview_attachment_new_tab {
|
||||
&.o_attachment_preview_new_tab {
|
||||
right: 43px;
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
> .attachment_preview_iframe {
|
||||
width: 100%;
|
||||
height: calc(~"100% - 30px");
|
||||
height: calc(100% - 30px);
|
||||
float: left;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
float: left;
|
||||
width: 100%;
|
||||
background-color: #FFF;
|
||||
border-left: 1px solid @gray-lighter-dark;
|
||||
border-left: 1px solid $gray-800;
|
||||
|
||||
button {
|
||||
min-width: 25px;
|
||||
@@ -1,33 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-extend="Sidebar">
|
||||
<t t-jquery="span.o_sidebar_delete_attachment" t-operation="before">
|
||||
<span t-if="section.name == 'files' and widget.options.editable and !item.callback and item.url"
|
||||
class="fa fa-search o_sidebar_preview_attachment"
|
||||
t-att-data-id="item.id"
|
||||
t-att-data-url="item.url"
|
||||
t-attf-title="Preview #{item.name}"/>
|
||||
<t t-extend="mail.Attachment">
|
||||
<t t-jquery=".o_attachment_download" t-operation="after">
|
||||
<span t-if="!attachment.callback and attachment.url"
|
||||
class="fa fa-search ml4 o_attachment_preview"
|
||||
t-att-data-id="attachment.id"
|
||||
t-att-data-url="attachment.url"
|
||||
t-attf-title="Preview #{attachment.name} in side panel"/>
|
||||
|
||||
<span t-if="section.name == 'files' and widget.options.editable and !item.callback and item.url"
|
||||
class="fa fa-external-link o_sidebar_preview_attachment o_sidebar_preview_attachment_new_tab"
|
||||
<span t-if="!attachment.callback and attachment.url"
|
||||
class="fa fa-external-link ml4 o_attachment_preview o_attachment_preview_new_tab"
|
||||
data-target="new"
|
||||
t-att-data-id="item.id"
|
||||
t-att-data-url="item.url"
|
||||
t-attf-title="Open preview #{item.name} in a new tab"/>
|
||||
t-att-data-id="attachment.id"
|
||||
t-att-data-url="attachment.url"
|
||||
t-attf-title="Open preview #{attachment.name} in a new tab"/>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<t t-name="attachment_preview.AttachmentPreviewWidget">
|
||||
<div class="attachment_preview_widget hidden">
|
||||
<div class="attachment_preview_widget d-none">
|
||||
<div class="attachment_preview_buttons">
|
||||
<div class="button-group pull-left">
|
||||
<button class="btn btn-sm btn-default attachment_preview_previous"><i class="fa fa-chevron-left"/></button>
|
||||
<button class="btn btn-sm btn-default disabled attachment_preview_current">1 / 5</button>
|
||||
<button class="btn btn-sm btn-default attachment_preview_next"><i class="fa fa-chevron-right"/></button>
|
||||
<button class="btn btn-sm btn-secondary attachment_preview_previous"><i class="fa fa-chevron-left"/></button>
|
||||
<button class="btn btn-sm btn-secondary disabled attachment_preview_current">1 / 5</button>
|
||||
<button class="btn btn-sm btn-secondary attachment_preview_next"><i class="fa fa-chevron-right"/></button>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-default pull-left ml8 attachment_preview_popout"><i class="fa fa-external-link"/></button>
|
||||
<button class="btn btn-sm btn-secondary pull-left ml8 attachment_preview_popout"><i class="fa fa-external-link"/></button>
|
||||
|
||||
<button class="btn btn-sm btn-default pull-right attachment_preview_close"><i class="fa fa-times"/></button>
|
||||
<button class="btn btn-sm btn-secondary pull-right attachment_preview_close"><i class="fa fa-times"/></button>
|
||||
</div>
|
||||
<iframe class="attachment_preview_iframe"></iframe>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user