mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-28 03:16:29 -06:00
[WIP] Migrating module to v14
This commit is contained in:
parent
37abe5a7a5
commit
c6c354e58e
@ -16,6 +16,8 @@ class IrAttachment(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_binary_extension(self, model, ids, binary_field, filename_field=None):
|
def get_binary_extension(self, model, ids, binary_field, filename_field=None):
|
||||||
|
# import pdb
|
||||||
|
# pdb.set_trace()
|
||||||
result = {}
|
result = {}
|
||||||
ids_to_browse = ids if isinstance(ids, collections.Iterable) else [ids]
|
ids_to_browse = ids if isinstance(ids, collections.Iterable) else [ids]
|
||||||
|
|
||||||
@ -73,4 +75,4 @@ class IrAttachment(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def get_attachment_extension(self, ids):
|
def get_attachment_extension(self, ids):
|
||||||
return self.get_binary_extension(self._name, ids, "datas", "datas_fname")
|
return self.get_binary_extension(self._name, ids, "datas", "name")
|
||||||
|
@ -74,8 +74,6 @@ c;a?(e.title||(e.title=a.replace(/^.*[\\\/]/,"")),e.documentUrl=a,b(a,function(b
|
|||||||
|
|
||||||
//]]>
|
//]]>
|
||||||
</script>
|
</script>
|
||||||
<!-- load some small tweaks for the Odoo integration /-->
|
|
||||||
<script src="../../src/js/viewerjs_tweaks.js" type="text/javascript" charset="utf-8"></script>
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,19 +1,29 @@
|
|||||||
/* Copyright 2014 Therp BV (<http://therp.nl>)
|
odoo.define("/attachment_preview/static/src/js/attachment_preview.js", function (
|
||||||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
|
require
|
||||||
|
) {
|
||||||
odoo.define("attachment_preview", function (require) {
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
const useStore = require("mail/static/src/component_hooks/use_store/use_store.js");
|
||||||
var core = require("web.core");
|
const {Component} = owl;
|
||||||
var _t = core._t;
|
const {useRef} = owl.hooks;
|
||||||
var qweb = core.qweb;
|
const components = {
|
||||||
var Chatter = require("mail.Chatter");
|
Attachment: require("mail/static/src/components/attachment/attachment.js"),
|
||||||
|
Chatter: require("mail/static/src/components/chatter/chatter.js"),
|
||||||
|
AttachmentBox: require("mail/static/src/components/attachment_box/attachment_box.js"),
|
||||||
|
};
|
||||||
|
const {patch} = require("web.utils");
|
||||||
|
var rpc = require("web.rpc");
|
||||||
var basic_fields = require("web.basic_fields");
|
var basic_fields = require("web.basic_fields");
|
||||||
var FormRenderer = require("web.FormRenderer");
|
var FormRenderer = require("web.FormRenderer");
|
||||||
var FormController = require("web.FormController");
|
|
||||||
var Widget = require("web.Widget");
|
var Widget = require("web.Widget");
|
||||||
|
|
||||||
var AttachmentPreviewMixin = {
|
const attachment = patch(
|
||||||
|
components.Attachment,
|
||||||
|
"/attachment_preview/static/src/js/attachment_preview.js",
|
||||||
|
{
|
||||||
|
previewableAttachments: null,
|
||||||
|
events: _.extend({}, components.Attachment.prototype.events, {
|
||||||
|
"click .o_attachment_preview": "_onPreviewAttachment",
|
||||||
|
}),
|
||||||
canPreview: function (extension) {
|
canPreview: function (extension) {
|
||||||
return (
|
return (
|
||||||
$.inArray(extension, [
|
$.inArray(extension, [
|
||||||
@ -49,7 +59,7 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
return url;
|
return url;
|
||||||
},
|
},
|
||||||
|
|
||||||
showPreview: function (
|
showPreview(
|
||||||
attachment_id,
|
attachment_id,
|
||||||
attachment_url,
|
attachment_url,
|
||||||
attachment_extension,
|
attachment_extension,
|
||||||
@ -63,59 +73,103 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
attachment_title
|
attachment_title
|
||||||
);
|
);
|
||||||
if (split_screen) {
|
if (split_screen) {
|
||||||
this.trigger_up("onAttachmentPreview", {url: url});
|
this.trigger("onAttachmentPreview", {url: url});
|
||||||
} else {
|
} else {
|
||||||
window.open(url);
|
window.open(url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
|
||||||
|
|
||||||
Chatter.include(AttachmentPreviewMixin);
|
|
||||||
Chatter.include({
|
|
||||||
events: _.extend({}, Chatter.prototype.events, {
|
|
||||||
"click .o_attachment_preview": "_onPreviewAttachment",
|
|
||||||
}),
|
|
||||||
|
|
||||||
previewableAttachments: null,
|
|
||||||
|
|
||||||
_openAttachmentBox: function () {
|
|
||||||
var res = this._super.apply(this, arguments);
|
|
||||||
|
|
||||||
|
_openAttachmentBox() {
|
||||||
this.getPreviewableAttachments().done(
|
this.getPreviewableAttachments().done(
|
||||||
function (atts) {
|
function (atts) {
|
||||||
this.previewableAttachments = atts;
|
this.previewableAttachments = atts;
|
||||||
this.updatePreviewButtons(atts);
|
this.updatePreviewButtons(atts);
|
||||||
this.getParent().attachmentPreviewWidget.setAttachments(atts);
|
this.attachmentPreviewWidget.setAttachments(atts);
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
return res;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
update: function () {
|
getPreviewableAttachments: function () {
|
||||||
var res = this._super.apply(this, arguments);
|
var self = this;
|
||||||
|
var deferred = $.Deferred();
|
||||||
|
|
||||||
|
var $items = $(this);
|
||||||
|
var attachments = _.object(
|
||||||
|
$items.map(function () {
|
||||||
|
return parseInt($(this).attr("data-id"), 10);
|
||||||
|
}),
|
||||||
|
$items.map(function () {
|
||||||
|
return {
|
||||||
|
url: $(this).attr("data-url"),
|
||||||
|
extension: $(this).attr("data-extension"),
|
||||||
|
title: $(this).attr("data-original-title"),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
rpc.query({
|
||||||
|
model: "ir.attachment",
|
||||||
|
method: "get_attachment_extension",
|
||||||
|
args: [
|
||||||
|
_.map(_.keys(attachments), function (id) {
|
||||||
|
return parseInt(id, 10);
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}).then(
|
||||||
|
function (extensions) {
|
||||||
|
var reviewableAttachments = _.map(
|
||||||
|
_.keys(
|
||||||
|
_.pick(extensions, function (extension, id) {
|
||||||
|
return self.canPreview(extension);
|
||||||
|
})
|
||||||
|
),
|
||||||
|
function (id) {
|
||||||
|
return {
|
||||||
|
id: id,
|
||||||
|
url: attachments[id].url,
|
||||||
|
extension: extensions[id],
|
||||||
|
title: attachments[id].title,
|
||||||
|
previewUrl: self.getUrl(
|
||||||
|
id,
|
||||||
|
attachments[id].url,
|
||||||
|
extensions[id],
|
||||||
|
id + " - " + attachments[id].title
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
deferred.resolve(reviewableAttachments);
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return deferred.promise();
|
||||||
|
},
|
||||||
|
|
||||||
|
_update: function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (this.getParent().$el.hasClass("attachment_preview")) {
|
|
||||||
this._fetchAttachments().done(function () {
|
|
||||||
self._openAttachmentBox();
|
self._openAttachmentBox();
|
||||||
self.getPreviewableAttachments().done(function (atts) {
|
self.getPreviewableAttachments().done(function (atts) {
|
||||||
self.updatePreviewButtons(self.previewableAttachments);
|
self.updatePreviewButtons(self.previewableAttachments);
|
||||||
self.previewableAttachments = atts;
|
self.previewableAttachments = atts;
|
||||||
self.getParent().attachmentPreviewWidget.setAttachments(atts);
|
self.attachmentPreviewWidget.setAttachments(atts);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_onPreviewAttachment: function (event) {
|
patched() {
|
||||||
|
this._update();
|
||||||
|
},
|
||||||
|
_onPreviewAttachment(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 = this.attachmentUrl,
|
||||||
attachment_extension = $target.attr("data-extension"),
|
attachment_extension = $(event.currentTarget).attr(
|
||||||
|
"data-extension"
|
||||||
|
),
|
||||||
attachment_title = $target.attr("data-original-title");
|
attachment_title = $target.attr("data-original-title");
|
||||||
|
|
||||||
if (attachment_extension) {
|
if (attachment_extension) {
|
||||||
@ -127,7 +181,7 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
split_screen
|
split_screen
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this._rpc({
|
rpc.query({
|
||||||
model: "ir.attachment",
|
model: "ir.attachment",
|
||||||
method: "get_attachment_extension",
|
method: "get_attachment_extension",
|
||||||
args: [attachment_id],
|
args: [attachment_id],
|
||||||
@ -147,7 +201,7 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
var deferred = $.Deferred();
|
var deferred = $.Deferred();
|
||||||
|
|
||||||
var $items = this.$el.find(".o_attachment_preview");
|
var $items = $(this).find(".o_attachment_preview");
|
||||||
var attachments = _.object(
|
var attachments = _.object(
|
||||||
$items.map(function () {
|
$items.map(function () {
|
||||||
return parseInt($(this).attr("data-id"), 10);
|
return parseInt($(this).attr("data-id"), 10);
|
||||||
@ -161,7 +215,7 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._rpc({
|
rpc.query({
|
||||||
model: "ir.attachment",
|
model: "ir.attachment",
|
||||||
method: "get_attachment_extension",
|
method: "get_attachment_extension",
|
||||||
args: [
|
args: [
|
||||||
@ -202,7 +256,9 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
updatePreviewButtons: function (previewableAttachments) {
|
updatePreviewButtons: function (previewableAttachments) {
|
||||||
this.$el.find(".o_attachment_preview").each(function () {
|
$(this)
|
||||||
|
.find(".o_attachment_preview")
|
||||||
|
.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});
|
||||||
@ -213,9 +269,10 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
basic_fields.FieldBinaryFile.include(AttachmentPreviewMixin);
|
basic_fields.FieldBinaryFile.include(attachment);
|
||||||
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",
|
||||||
@ -270,7 +327,6 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var AttachmentPreviewWidget = Widget.extend({
|
var AttachmentPreviewWidget = Widget.extend({
|
||||||
template: "attachment_preview.AttachmentPreviewWidget",
|
template: "attachment_preview.AttachmentPreviewWidget",
|
||||||
activeIndex: 0,
|
activeIndex: 0,
|
||||||
@ -396,10 +452,12 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
showAttachmentPreviewWidget: function () {
|
showAttachmentPreviewWidget: function () {
|
||||||
|
// Debugger;
|
||||||
this.$el.addClass("attachment_preview");
|
this.$el.addClass("attachment_preview");
|
||||||
|
|
||||||
this.attachmentPreviewWidget.setAttachments(
|
this.attachmentPreviewWidget.setAttachments(
|
||||||
this.chatter.previewableAttachments
|
this.attachments
|
||||||
|
// This._chatterContainerComponent.Component.components.Chatter.props.chatterLocalId.previewableAttachments
|
||||||
);
|
);
|
||||||
this.attachmentPreviewWidget.show();
|
this.attachmentPreviewWidget.show();
|
||||||
},
|
},
|
||||||
@ -415,7 +473,7 @@ odoo.define("attachment_preview", function (require) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
AttachmentPreviewMixin: AttachmentPreviewMixin,
|
attachment,
|
||||||
AttachmentPreviewWidget: AttachmentPreviewWidget,
|
AttachmentPreviewWidget: AttachmentPreviewWidget,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@ -15,6 +15,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.o_Attachment_actions {
|
||||||
|
justify-content: space-between;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
.o_form_uri .fa-search {
|
.o_form_uri .fa-search {
|
||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
padding-right: 5px;
|
padding-right: 5px;
|
||||||
|
@ -1,24 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<templates>
|
<templates xml:space="preserve">
|
||||||
<t t-extend="mail.Attachment">
|
<t
|
||||||
<t t-jquery=".o_attachment_download" t-operation="after">
|
t-name="Attachment"
|
||||||
<span
|
t-inherit="mail.Attachment"
|
||||||
t-if="!attachment.callback and attachment.url"
|
t-inherit-mode="extension"
|
||||||
class="fa fa-search ml4 o_attachment_preview"
|
owl="1"
|
||||||
|
>
|
||||||
|
<xpath expr="//div[hasclass('o_Attachment_actionDownload')]" position="before">
|
||||||
|
<div
|
||||||
|
class="ml4 o_attachment_preview"
|
||||||
|
t-on-click="_onPreviewAttachment"
|
||||||
t-att-data-id="attachment.id"
|
t-att-data-id="attachment.id"
|
||||||
t-att-data-url="attachment.url"
|
t-att-data-url="attachment.url"
|
||||||
t-attf-title="Preview #{attachment.name} in side panel"
|
t-attf-title="Preview {{attachment.name}} in side panel"
|
||||||
/>
|
>
|
||||||
|
<i class="fa fa-search" />
|
||||||
<span
|
</div>
|
||||||
t-if="!attachment.callback and attachment.url"
|
<div
|
||||||
class="fa fa-external-link ml4 o_attachment_preview o_attachment_preview_new_tab"
|
class="ml4 o_attachment_preview o_attachment_preview_new_tab"
|
||||||
data-target="new"
|
data-target="new"
|
||||||
t-att-data-id="attachment.id"
|
t-att-data-id="attachment.id"
|
||||||
t-att-data-url="attachment.url"
|
t-att-data-url="attachment.url"
|
||||||
t-attf-title="Open preview #{attachment.name} in a new tab"
|
t-attf-title="Open preview {{attachment.name}} in a new tab"
|
||||||
/>
|
>
|
||||||
</t>
|
<i class="fa fa-external-link" />
|
||||||
|
</div>
|
||||||
|
</xpath>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="attachment_preview.AttachmentPreviewWidget">
|
<t t-name="attachment_preview.AttachmentPreviewWidget">
|
||||||
@ -30,7 +37,7 @@
|
|||||||
><i class="fa fa-chevron-left" /></button>
|
><i class="fa fa-chevron-left" /></button>
|
||||||
<button
|
<button
|
||||||
class="btn btn-sm btn-secondary disabled attachment_preview_current"
|
class="btn btn-sm btn-secondary disabled attachment_preview_current"
|
||||||
>1 / 5</button>
|
>1 / 2</button>
|
||||||
<button class="btn btn-sm btn-secondary attachment_preview_next"><i
|
<button class="btn btn-sm btn-secondary attachment_preview_next"><i
|
||||||
class="fa fa-chevron-right"
|
class="fa fa-chevron-right"
|
||||||
/></button>
|
/></button>
|
||||||
|
Loading…
Reference in New Issue
Block a user