Add js confirm() to warn admins about promoted group updates (#15990)
This commit is contained in:
Родитель
6765fbbe07
Коммит
bac109cd9c
|
@ -132,6 +132,11 @@ class PromotedAddonAdmin(admin.ModelAdmin):
|
|||
inlines = (PromotedApprovalInline, PrimaryHeroInline,
|
||||
PromotedSubscriptionInline)
|
||||
|
||||
class Media:
|
||||
js = (
|
||||
'js/admin/promotedaddon.js',
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _transformer(self, objs):
|
||||
Version.transformer_promoted(
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
'use strict';
|
||||
|
||||
const promotedAddonForm = document.getElementById('promotedaddon_form');
|
||||
|
||||
if (!promotedAddonForm) {
|
||||
return;
|
||||
}
|
||||
|
||||
const groupSelect = promotedAddonForm.querySelector('#id_group_id');
|
||||
let initialIndex = groupSelect.selectedIndex;
|
||||
const initialGroup = groupSelect.options[initialIndex].label || '';
|
||||
|
||||
// Enable the listener only when loading a promoted add-on belonging to a
|
||||
// group that requires a subscription.
|
||||
if (['sponsored', 'verified'].includes(initialGroup.toLowerCase())) {
|
||||
groupSelect.addEventListener('change', () => {
|
||||
if (
|
||||
!confirm(
|
||||
"This promoted add-on belongs to a group that requires a Stripe subscription, which should be cancelled in Stripe first. If you confirm this action, you will be able to update the group but Stripe won't be notified and the Stripe subscription will remain active. Do you really want to continue?",
|
||||
)
|
||||
) {
|
||||
groupSelect.selectedIndex = initialIndex;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
Загрузка…
Ссылка в новой задаче