form视图的丢弃按钮增加二次确认功能

This commit is contained in:
mgw
2023-10-23 00:17:05 +08:00
parent 587e2a4e3e
commit 749473f9dc
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/** @odoo-module */
import {patch} from '@web/core/utils/patch';
// import { Dialog } from "@web/core/dialog/dialog";
import {_t} from "@web/core/l10n/translation";
import {FormStatusIndicator} from "@web/views/form/form_status_indicator/form_status_indicator"
var Dialog = require('web.Dialog');
// var {patch} = require("web.utils") 这句话也行
patch(FormStatusIndicator.prototype, 'jikimo_frontend.FormStatusIndicator', {
// 你可以重写或者添加一些方法和属性
async _onDiscardChanges() {
var self = this;
Dialog.confirm(this, _t("Are you sure you want to discard changes?"), {
title: _t("Discard Changes"),
// confirm_callback: function () {
// self.model.discardChanges(self.handle);
// },
});
},
async discard() {
// if (window.confirm("Are you sure you want to discard changes?")) {
// await this.props.discard();
// }
const result = await this._confirmDiscardChange();
await this.props.discard();
},
_confirmDiscardChange(){
var self = this;
var def = new Promise(function (resolve, reject) {
var message = _t("请确认是否要舍弃之前的更改?");
var dialog = Dialog.confirm(self, message, {
title: _t("Warning"),
confirm_callback: resolve.bind(self, true),
cancel_callback: reject,
});
dialog.on('closed', self, reject);
});
return def;
},
}
);