[MIG] web_copy_confirm: Migration to 14.0

This commit is contained in:
Robin Conjour
2021-01-04 17:13:35 +01:00
committed by Miquel Raïch
parent c1acd004eb
commit cb7cba0bd6
11 changed files with 657 additions and 51 deletions

View File

@@ -1,15 +1,50 @@
// Copyright (C) 2018 DynApps <http://www.dynapps.be>
// @author Stefan Rijnhart <stefan@opener.amsterdam>
// @author Robin Conjour <rconjour@demolium.com>
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
openerp.web_copy_confirm = function (instance) {
instance.web.FormView.include({
on_button_duplicate: function () {
var self = this;
this.has_been_loaded.done(function () {
if (confirm(_t("Do you really want to copy this record?"))) {
return self._super.apply(self, arguments);
odoo.define("web_copy_confirm.web_copy_confirm", function (require) {
"use strict";
const Core = require("web.core");
const FormController = require("web.FormController");
const Dialog = require("web.Dialog");
const _t = Core._t;
return FormController.include({
/**
* Trigger the confirmation dialog when duplicating records
* @returns {Promise<void>}
* @private
*/
_onDuplicateRecordConfirm: async function () {
Dialog.confirm(
this,
_t("Are you sure that you would like to copy this record?"),
{
confirm_callback: () => this._onDuplicateRecord(),
}
});
);
},
/**
* Override the "duplicate" in the action menu
* @returns {any}
* @private
*/
_getActionMenuItems: function () {
const props = this._super(...arguments);
if (props && props.items && props.items.other) {
const other_list = props.items.other;
const duplicate_index = other_list.findIndex(
(item) => item.description === _t("Duplicate")
);
if (other_list[duplicate_index]) {
other_list[duplicate_index].callback = () =>
this._onDuplicateRecordConfirm();
}
}
return props;
},
});
};
});