初始提交
This commit is contained in:
28
ai/static/src/file_viewer/file_viewer.js
Normal file
28
ai/static/src/file_viewer/file_viewer.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { FileViewer as WebFileViewer } from "@web/core/file_viewer/file_viewer";
|
||||
import { patch } from "@web/core/utils/patch";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
|
||||
|
||||
patch(WebFileViewer.prototype, {
|
||||
setup() {
|
||||
super.setup();
|
||||
this.aiChatLauncher = useService("aiChatLauncher");
|
||||
this.notification = useService("notification");
|
||||
},
|
||||
|
||||
async openAIChat() {
|
||||
if (this.state.file.isVideo || this.state.file.isUrlYoutube) {
|
||||
this.notification.add(_t("Oops, AI cannot process videos!"), { type: "warning" });
|
||||
return;
|
||||
}
|
||||
const fileName = this.state.file.name || 'File Attachment';
|
||||
await this.aiChatLauncher.launchAIChat({
|
||||
interfaceKey: "file_viewer_ai_button",
|
||||
recordModel: "ir.attachment",
|
||||
recordId: this.state.file.id,
|
||||
channelTitle: fileName,
|
||||
aiChatSourceId: this.state.file.id,
|
||||
});
|
||||
},
|
||||
});
|
||||
20
ai/static/src/file_viewer/file_viewer.xml
Normal file
20
ai/static/src/file_viewer/file_viewer.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates>
|
||||
<t t-name="ai.AIFileViewer" t-inherit="web.FileViewer" t-inherit-mode="extension">
|
||||
<xpath expr="//div[hasclass('o-FileViewer-download')]/preceding-sibling::div[hasclass('flex-grow-1')][1]" position="after">
|
||||
<t t-call="ai.AIFileButton"/>
|
||||
</xpath>
|
||||
</t>
|
||||
<t t-name="ai.AIFileButton">
|
||||
<div class="o-FileViewer-headerButton d-flex align-items-center px-3 mx-1">
|
||||
<button
|
||||
class="cursor-pointer border-0 bg-transparent p-0"
|
||||
data-hotkey="c"
|
||||
t-on-click="this.openAIChat"
|
||||
title="Ask AI"
|
||||
>
|
||||
<img src="/ai/static/description/icon.png" style="height: 22px;" alt="AI"/>
|
||||
</button>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
Reference in New Issue
Block a user