[MIG] attachment_preview: Migration to 13.0

This commit is contained in:
vancouver29
2022-08-16 18:16:53 +02:00
parent c6e0419f98
commit 6203fdd7bf
6 changed files with 47 additions and 35 deletions

View File

@@ -6,13 +6,15 @@ odoo.define("attachment_preview", function(require) {
var core = require("web.core");
var _t = core._t;
var qweb = core.qweb;
var Chatter = require("mail.Chatter");
var basic_fields = require("web.basic_fields");
var FormRenderer = require("web.FormRenderer");
var FormController = require("web.FormController");
var Widget = require("web.Widget");
var active_attachment_id = 0;
var active_attachment_index = 0;
var first_click = true;
var AttachmentPreviewMixin = {
canPreview: function(extension) {
return (
@@ -96,7 +98,7 @@ odoo.define("attachment_preview", function(require) {
var res = this._super.apply(this, arguments);
var self = this;
if (this.getParent().$el.hasClass("attachment_preview")) {
this._fetchAttachments().done(function() {
this._fetchAttachments().then(function() {
self._openAttachmentBox();
self.getPreviewableAttachments().done(function(atts) {
self.updatePreviewButtons(self.previewableAttachments);
@@ -118,6 +120,11 @@ odoo.define("attachment_preview", function(require) {
attachment_extension = $target.attr("data-extension"),
attachment_title = $target.attr("data-original-title");
if (attachment_id !== active_attachment_id) {
active_attachment_id = attachment_id;
first_click = true;
}
if (attachment_extension) {
this.showPreview(
attachment_id,
@@ -147,16 +154,15 @@ odoo.define("attachment_preview", function(require) {
var self = this;
var deferred = $.Deferred();
var $items = this.$el.find(".o_attachment_preview");
var attachments = _.object(
$items.map(function() {
return parseInt($(this).attr("data-id"), 10);
this.attachments.map(function(attachment) {
return attachment.id;
}),
$items.map(function() {
this.attachments.map(function(attachment) {
return {
url: $(this).attr("data-url"),
extension: $(this).attr("data-extension"),
title: $(this).attr("data-original-title"),
url: attachment.url,
extension: attachment.filename.split(".")[1],
title: attachment.name,
};
})
);
@@ -173,7 +179,7 @@ odoo.define("attachment_preview", function(require) {
function(extensions) {
var reviewableAttachments = _.map(
_.keys(
_.pick(extensions, function(extension, id) {
_.pick(extensions, function(extension) {
return self.canPreview(extension);
})
),
@@ -226,7 +232,7 @@ odoo.define("attachment_preview", function(require) {
this._super.apply(this, arguments);
if (this.recordData.id) {
this._getBinaryExtension().done(function(extension) {
this._getBinaryExtension().then(function(extension) {
if (self.canPreview(extension)) {
self._renderPreviewButton(extension);
}
@@ -284,6 +290,7 @@ odoo.define("attachment_preview", function(require) {
},
start: function() {
first_click = true;
var res = this._super.apply(this, arguments);
this.$overlay = this.$el.find(".attachment_preview_overlay");
this.$iframe = this.$el.find(".attachment_preview_iframe");
@@ -337,6 +344,7 @@ odoo.define("attachment_preview", function(require) {
},
hide: function() {
first_click = true;
this.$el.addClass("d-none");
this.trigger("hidden");
},
@@ -356,7 +364,18 @@ odoo.define("attachment_preview", function(require) {
return;
}
var att = this.attachments[this.activeIndex];
if (first_click) {
for (var i in this.attachments) {
if (this.attachments[i].id === active_attachment_id.toString()) {
active_attachment_index = i;
first_click = false;
}
}
} else {
active_attachment_index = this.activeIndex;
}
var att = this.attachments[active_attachment_index];
this.$iframe.attr("src", att.previewUrl);
},
@@ -411,7 +430,7 @@ odoo.define("attachment_preview", function(require) {
return this._super.apply(this, arguments);
},
_onAttachmentPreview: function(event) {
_onAttachmentPreview: function() {
this.showAttachmentPreviewWidget();
},
});