diff --git a/addons/web/static/src/core/dialog/dialog.js b/addons/web/static/src/core/dialog/dialog.js index f9bbefbc757..a501adf19a8 100644 --- a/addons/web/static/src/core/dialog/dialog.js +++ b/addons/web/static/src/core/dialog/dialog.js @@ -54,19 +54,3 @@ Dialog.defaultProps = { technical: true, title: "Odoo", }; - -export class SimpleDialog extends Component { - setup() { - useActiveElement("modal"); - useHotkey("escape", () => { - this.props.close(); - }); - useChildSubEnv({ inDialog: true }); - } -} -SimpleDialog.template = "web.SimpleDialog"; -SimpleDialog.props = { - close: Function, - isActive: { optional: true }, - "*": true, -}; diff --git a/addons/web/static/src/core/dialog/dialog.xml b/addons/web/static/src/core/dialog/dialog.xml index 9925618ea71..cb900b1d1d9 100644 --- a/addons/web/static/src/core/dialog/dialog.xml +++ b/addons/web/static/src/core/dialog/dialog.xml @@ -24,14 +24,14 @@
- +
diff --git a/addons/web/static/src/core/dialog/simple_dialog.xml b/addons/web/static/src/core/dialog/simple_dialog.xml deleted file mode 100644 index 127b7d2da39..00000000000 --- a/addons/web/static/src/core/dialog/simple_dialog.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - -
- -
-
-
diff --git a/addons/web/static/src/views/kanban/kanban_compiler.js b/addons/web/static/src/views/kanban/kanban_compiler.js index df19bc174f7..94c70bb2ef9 100644 --- a/addons/web/static/src/views/kanban/kanban_compiler.js +++ b/addons/web/static/src/views/kanban/kanban_compiler.js @@ -99,11 +99,11 @@ export class KanbanCompiler extends ViewCompiler { const nodeParams = extractAttributes(el, ["type"]); if (type === "set_cover") { - const { "data-field": fieldName, "auto-open": autoOpen } = extractAttributes(el, [ - "data-field", + const { "auto-open": autoOpen, "data-field": fieldName } = extractAttributes(el, [ "auto-open", + "data-field", ]); - Object.assign(nodeParams, { fieldName, autoOpen }); + Object.assign(nodeParams, { autoOpen, fieldName }); } const strParams = Object.entries(nodeParams) .map(([k, v]) => [k, toStringExpression(v)].join(":")) diff --git a/addons/web/static/src/views/kanban/kanban_cover_image_dialog.js b/addons/web/static/src/views/kanban/kanban_cover_image_dialog.js index a138518122d..e4fb3fde054 100644 --- a/addons/web/static/src/views/kanban/kanban_cover_image_dialog.js +++ b/addons/web/static/src/views/kanban/kanban_cover_image_dialog.js @@ -1,9 +1,10 @@ /** @odoo-module **/ -import { SimpleDialog } from "@web/core/dialog/dialog"; +import { Dialog } from "@web/core/dialog/dialog"; +import { FileInput } from "@web/core/file_input/file_input"; import { useService } from "@web/core/utils/hooks"; -const { Component, useState, useRef, onWillStart, onMounted } = owl; +const { Component, useState, onWillStart } = owl; let nextDialogId = 1; @@ -11,12 +12,13 @@ export class KanbanCoverImageDialog extends Component { setup() { this.id = `o_cover_image_upload_${nextDialogId++}`; this.orm = useService("orm"); + this.http = useService("http"); const { record, fieldName } = this.props; - this.coverId = record && record.data[fieldName]; + const attachment = (record && record.data[fieldName]) || []; this.state = useState({ - selectedAttachmentId: this.coverId, + selectFile: false, + selectedAttachmentId: attachment[0], }); - this.fileInput = useRef("fileInput"); onWillStart(async () => { this.attachments = await this.orm.searchRead( "ir.attachment", @@ -25,22 +27,29 @@ export class KanbanCoverImageDialog extends Component { ["res_id", "=", record.resId], ["mimetype", "ilike", "image"], ], - ["id", "name"] + ["id"] ); - }); - onMounted(() => { - if (!this.props.autoOpen && this.attachments.length === 0) { - this.fileInput.el.click(); - } + this.state.selectFile = this.props.autoOpen && this.attachments.length; }); } - selectAttachment(attachment) { + onUpload([attachment]) { + if (!attachment) { + return; + } + this.state.selectFile = false; + this.selectAttachment(attachment, true); + } + + selectAttachment(attachment, setSelected) { if (this.state.selectedAttachmentId !== attachment.id) { this.state.selectedAttachmentId = attachment.id; } else { this.state.selectedAttachmentId = null; } + if (setSelected) { + this.setCover(); + } } removeCover() { @@ -54,7 +63,11 @@ export class KanbanCoverImageDialog extends Component { await this.props.record.save(); this.props.close(); } + + uploadImage() { + this.state.selectFile = true; + } } KanbanCoverImageDialog.template = "web.KanbanCoverImageDialog"; -KanbanCoverImageDialog.components = { SimpleDialog }; +KanbanCoverImageDialog.components = { Dialog, FileInput }; diff --git a/addons/web/static/src/views/kanban/kanban_cover_image_dialog.xml b/addons/web/static/src/views/kanban/kanban_cover_image_dialog.xml index 8f49e283be1..f0f72c52228 100644 --- a/addons/web/static/src/views/kanban/kanban_cover_image_dialog.xml +++ b/addons/web/static/src/views/kanban/kanban_cover_image_dialog.xml @@ -2,38 +2,45 @@ - +
- Attachment + Attachment
There is no available image to be set as cover. -
-
- - - - - -
-