[IMP] payment: function to build confirmation dialog allowing overrides

The confirmation dialog to delete a token from a portal user is the
same whatever the linked records. This part of the code is now moved to
a separate function `_buildConfirmationDialog` in order to allow
overrides of the method in particular cases (e.g. Subscriptions).

task-3048269

closes odoo/odoo#105289

X-original-commit: 51d6b724f061af44bc07c342dfa9a34b4d1a2101
Related: odoo/enterprise#33741
Signed-off-by: Vallaeys Valentin (vava) <vava@odoo.com>
This commit is contained in:
Valentin Vallaeys (vava)
2022-11-08 12:42:58 +01:00
parent 1451855d4b
commit 34f2b5c1d7
+49 -36
View File
@@ -68,6 +68,53 @@ odoo.define('payment.manage_form', require => {
});
},
/**
* Build the confirmation dialog based on the linked records' information.
*
* @private
* @param {Array} linkedRecordsInfo - The list of information about linked records.
* @param confirmCallback - The callback method called when the user clicks on the
* confirmation button.
* @return {object}
*/
_buildConfirmationDialog: function (linkedRecordsInfo, confirmCallback) {
const $dialogContentMessage = $(
'<span>', {text: _t("Are you sure you want to delete this payment method?")}
);
if (linkedRecordsInfo.length > 0) { // List the documents linked to the token.
$dialogContentMessage.append($('<br>'));
$dialogContentMessage.append($(
'<span>', {text: _t("It is currently linked to the following documents:")}
));
const $documentInfoList = $('<ul>');
linkedRecordsInfo.forEach(documentInfo => {
$documentInfoList.append($('<li>').append($(
'<a>', {
href: documentInfo.url,
target: '_blank',
title: documentInfo.description,
text: documentInfo.name
}
)));
});
$dialogContentMessage.append($documentInfoList);
}
return new Dialog(this, {
title: _t("Warning!"),
size: 'medium',
$content: $('<div>').append($dialogContentMessage),
buttons: [
{
text: _t("Confirm Deletion"), classes: 'btn-primary', close: true,
click: confirmCallback,
},
{
text: _t("Cancel"), close: true
},
],
});
},
/**
* Search for documents linked to the token and ask the user for confirmation.
*
@@ -107,42 +154,8 @@ odoo.define('payment.manage_form', require => {
model: 'payment.token',
method: 'get_linked_records_info',
args: [tokenId],
}).then(result => {
const $dialogContentMessage = $(
'<span>', {text: _t("Are you sure you want to delete this payment method?")}
);
if (result.length > 0) { // There are documents linked to the token, list them
$dialogContentMessage.append($('<br>'));
$dialogContentMessage.append($(
'<span>', {text: _t("It is currently linked to the following documents:")}
));
const $documentInfoList = $('<ul>');
result.forEach(documentInfo => {
$documentInfoList.append($('<li>').append($(
'<a>', {
href: documentInfo.url,
target: '_blank',
title: documentInfo.description,
text: documentInfo.name
}
)));
});
$dialogContentMessage.append($documentInfoList);
}
new Dialog(this, {
title: _t("Warning!"),
size: 'medium',
$content: $('<div>').append($dialogContentMessage),
buttons: [
{
text: _t("Confirm Deletion"), classes: 'btn-primary', close: true,
click: execute
},
{
text: _t("Cancel"), close: true
},
],
}).open();
}).then(linkedRecordsInfo => {
this._buildConfirmationDialog(linkedRecordsInfo, execute).open();
}).guardedCatch(error => {
this._displayError(
_t("Server Error"),