创建提醒弹窗

This commit is contained in:
李鹏宇
2026-07-31 15:11:36 +08:00
parent be611eca2a
commit ebff252913
5 changed files with 119 additions and 3 deletions
+1
View File
@@ -34,6 +34,7 @@
], ],
'assets': { 'assets': {
'web.assets_backend': [ 'web.assets_backend': [
'yuthon_issue/static/src/js/issue_m2o_confirm.js',
'yuthon_issue/static/xml/issue_approval.xml', 'yuthon_issue/static/xml/issue_approval.xml',
'yuthon_issue/static/scss/issue_library_scss.scss', 'yuthon_issue/static/scss/issue_library_scss.scss',
], ],
@@ -0,0 +1,100 @@
/* @odoo-module */
/**
* 议题 Many2one 字段创建前确认弹窗
* - 继承 Odoo 17 原生 Many2OneField,包裹 quickCreate(拦截"创建 xxx")
* - 自定义 Many2XAutocomplete,包裹 openMany2X(拦截"创建并编辑...")
*/
import { Component } from "@odoo/owl";
import { registry } from "@web/core/registry";
import { _t } from "@web/core/l10n/translation";
import { Dialog } from "@web/core/dialog/dialog";
import { Many2OneField } from "@web/views/fields/many2one/many2one_field";
import { Many2XAutocomplete } from "@web/views/fields/relational_utils";
// ============================================================
// 自定义确认弹窗组件
// ============================================================
class IssueM2OConfirmDialog extends Component {
static template = "yuthon_issue.IssueM2OConfirmDialog";
static components = { Dialog };
}
// ============================================================
// 通用:显示确认弹窗,返回 Promise<boolean>
// ============================================================
function showCreateConfirm(env, value) {
const displayName = value || "";
return new Promise((resolve) => {
// 注意:dialog.add() 返回值本身就是一个 close 函数(非 dialog 对象)
const closeDialog = env.services.dialog.add(
IssueM2OConfirmDialog,
{
title: _t("创建新选项"),
body: _t("请您确认要创建一个新的选项") + (displayName ? `: "${displayName}"` : ""),
confirmLabel: _t("确认创建"),
cancelLabel: _t("取消"),
// 确认创建:resolve(true) 并关闭弹窗
onConfirm: () => { resolve(true); closeDialog(); },
// 取消:resolve(false) 并关闭弹窗
onCancel: () => { resolve(false); closeDialog(); },
},
// 点 X 或 ESC 关闭时视为取消
{ onClose: () => resolve(false) }
);
});
}
// ============================================================
// 自定义 Many2XAutocomplete:拦截"创建并编辑..."
// ============================================================
class IssueM2OConfirmAutocomplete extends Many2XAutocomplete {
setup() {
super.setup();
if (this.openMany2X) {
const originalOpenMany2X = this.openMany2X;
this.openMany2X = async (params) => {
const request =
(params &&
params.context &&
(params.context.default_name ||
params.context[`default_${this.props.nameCreateField}`])) ||
"";
const confirmed = await showCreateConfirm(this.env, request);
if (!confirmed) return;
return originalOpenMany2X(params);
};
}
}
}
// ============================================================
// 自定义 Many2OneField:拦截"创建 xxx"(quickCreate)
// ============================================================
export class IssueM2OConfirmCreate extends Many2OneField {
setup() {
super.setup();
// 包裹 quickCreate("创建 xxx" 快速创建)
if (this.quickCreate) {
const originalQuickCreate = this.quickCreate;
this.quickCreate = async (name, params) => {
const confirmed = await showCreateConfirm(this.env, name);
if (!confirmed) return;
return originalQuickCreate(name, params);
};
}
}
}
IssueM2OConfirmCreate.template = "web.Many2OneField";
// 让模板里的 <Many2XAutocomplete> 使用我们的自定义版本(拦截"创建并编辑...")
IssueM2OConfirmCreate.components = {
Many2XAutocomplete: IssueM2OConfirmAutocomplete,
};
IssueM2OConfirmCreate.componentName = "issue_m2o_confirm_create";
// 注册自定义字段组件
registry.category("fields").add("issue_m2o_confirm_create", {
component: IssueM2OConfirmCreate,
displayName: _t("议题 Many2one 创建确认"),
supportedTypes: ["many2one"],
});
@@ -23,4 +23,19 @@
</p> </p>
</div> </div>
</t> </t>
<!-- 议题 Many2one 创建确认弹窗模板 -->
<t t-name="yuthon_issue.IssueM2OConfirmDialog" owl="1">
<Dialog title="props.title" size="'sm'">
<p><t t-esc="props.body"/></p>
<t t-set-slot="footer">
<button class="btn btn-secondary" t-on-click="() => this.props.onCancel()">
<t t-esc="props.cancelLabel or '取消'"/>
</button>
<button class="btn btn-primary" t-on-click="() => this.props.onConfirm()">
<t t-esc="props.confirmLabel or '确认创建'"/>
</button>
</t>
</Dialog>
</t>
</templates> </templates>
+1 -1
View File
@@ -29,7 +29,7 @@
<button name="open_record" type="object" string="详情" class="oe_highlight"/> <button name="open_record" type="object" string="详情" class="oe_highlight"/>
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="meeting_booking_id" column_invisible="1"/> <field name="meeting_booking_id" column_invisible="1"/>
<field name="issue_library_id" class="o_m2o_mutil_line"/> <field name="issue_library_id" class="o_m2o_mutil_line" widget="issue_m2o_confirm_create"/>
<field name="employee_id" options="{'no_create': True}"/> <field name="employee_id" options="{'no_create': True}"/>
<field name="attendees_ids" widget="many2many_tags" options="{'no_create': True}"/> <field name="attendees_ids" widget="many2many_tags" options="{'no_create': True}"/>
<field name="users_role_group_ids" widget="many2many_tags" options="{'no_create': True}"/> <field name="users_role_group_ids" widget="many2many_tags" options="{'no_create': True}"/>
+2 -2
View File
@@ -63,7 +63,7 @@
decoration-muted="issue_state == 'cancel'"> decoration-muted="issue_state == 'cancel'">
<header> <header>
<button name="all_meeting_issue" type="object" string="会议安排" class="oe_highlight" groups="yuthon_salary.group_lc_user"/> <button name="all_meeting_issue" type="object" string="会议安排" class="oe_highlight" groups="yuthon_salary.group_lc_user"/>
<button name="batch_add_ci_char" type="object" string="批量补'次'字" class="oe_highlight"/> <!-- <button name="batch_add_ci_char" type="object" string="批量补'次'字" class="oe_highlight"/>-->
<button name="remove_duplicate_lines" type="object" string="去重明细行" class="btn btn-warning" <button name="remove_duplicate_lines" type="object" string="去重明细行" class="btn btn-warning"
confirm="确定要删除当前选中议题的重复关联流程和关联会议明细吗?重复的只保留一条,此操作不可恢复!"/> confirm="确定要删除当前选中议题的重复关联流程和关联会议明细吗?重复的只保留一条,此操作不可恢复!"/>
</header> </header>
@@ -732,7 +732,7 @@
<header> <header>
<button name="all_meeting_issue" type="object" string="会议安排" class="oe_highlight"/> <button name="all_meeting_issue" type="object" string="会议安排" class="oe_highlight"/>
<button name="issue_class_approval" type="object" string="批量审批" class="oe_highlight"/> <button name="issue_class_approval" type="object" string="批量审批" class="oe_highlight"/>
<button name="batch_add_ci_char" type="object" string="批量补'次'字" class="oe_highlight"/> <!-- <button name="batch_add_ci_char" type="object" string="批量补'次'字" class="oe_highlight"/>-->
<button name="remove_duplicate_lines" type="object" string="去重明细行" class="btn btn-warning" <button name="remove_duplicate_lines" type="object" string="去重明细行" class="btn btn-warning"
confirm="确定要删除当前选中议题的重复关联流程和关联会议明细吗?重复的只保留一条,此操作不可恢复!"/> confirm="确定要删除当前选中议题的重复关联流程和关联会议明细吗?重复的只保留一条,此操作不可恢复!"/>
</header> </header>