update fee5
This commit is contained in:
parent
0106833e47
commit
b70c6b10e0
Binary file not shown.
@ -105,32 +105,42 @@
|
||||
{% if subscription_enabled %}
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const roleSelect = document.querySelector('select[name="role"]');
|
||||
const planSelect = document.querySelector('select[name="subscription_plan"]');
|
||||
const fees = {{ fees_json|safe }};
|
||||
|
||||
const monthlyLabel = "{% trans 'Monthly Plan' %}";
|
||||
const annualLabel = "{% trans 'Annual Plan' %}";
|
||||
|
||||
function updateFees() {
|
||||
// Try multiple ways to find the elements to be extremely robust
|
||||
const roleSelect = document.getElementById('id_role') || document.querySelector('[name="role"]');
|
||||
const planSelect = document.getElementById('id_subscription_plan') || document.querySelector('[name="subscription_plan"]');
|
||||
|
||||
if (!roleSelect || !planSelect) return;
|
||||
|
||||
const role = roleSelect.value;
|
||||
const roleFees = fees[role];
|
||||
// Use case-insensitive match just in case
|
||||
const roleKey = Object.keys(fees).find(k => k.toUpperCase() === role.toUpperCase());
|
||||
const roleFees = fees[roleKey];
|
||||
|
||||
if (roleFees) {
|
||||
for (let option of planSelect.options) {
|
||||
for (let i = 0; i < planSelect.options.length; i++) {
|
||||
const option = planSelect.options[i];
|
||||
if (option.value === 'MONTHLY') {
|
||||
option.text = `${monthlyLabel} (${roleFees.MONTHLY})`;
|
||||
option.text = monthlyLabel + " (" + roleFees.MONTHLY + ")";
|
||||
} else if (option.value === 'ANNUAL') {
|
||||
option.text = `${annualLabel} (${roleFees.ANNUAL})`;
|
||||
option.text = annualLabel + " (" + roleFees.ANNUAL + ")";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (roleSelect && planSelect) {
|
||||
roleSelect.addEventListener('change', updateFees);
|
||||
updateFees(); // Initialize
|
||||
const roleField = document.getElementById('id_role') || document.querySelector('[name="role"]');
|
||||
if (roleField) {
|
||||
roleField.addEventListener('change', updateFees);
|
||||
updateFees(); // Run once on load
|
||||
}
|
||||
|
||||
// As a final fallback, try to run after a small delay in case of dynamic rendering issues
|
||||
setTimeout(updateFees, 500);
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
|
||||
@ -27,15 +27,15 @@ def register(request):
|
||||
app_settings = AppSetting.objects.first()
|
||||
subscription_enabled = app_settings.subscription_enabled if app_settings else False
|
||||
|
||||
# Fees for JS
|
||||
# Fees for JS - using float for cleaner JSON and explicit formatting
|
||||
fees = {
|
||||
'SHIPPER': {
|
||||
'MONTHLY': str(app_settings.shipper_monthly_fee) if app_settings else "0.00",
|
||||
'ANNUAL': str(app_settings.shipper_annual_fee) if app_settings else "0.00",
|
||||
'MONTHLY': "{:.2f}".format(app_settings.shipper_monthly_fee) if app_settings else "0.00",
|
||||
'ANNUAL': "{:.2f}".format(app_settings.shipper_annual_fee) if app_settings else "0.00",
|
||||
},
|
||||
'TRUCK_OWNER': {
|
||||
'MONTHLY': str(app_settings.truck_owner_monthly_fee) if app_settings else "0.00",
|
||||
'ANNUAL': str(app_settings.truck_owner_annual_fee) if app_settings else "0.00",
|
||||
'MONTHLY': "{:.2f}".format(app_settings.truck_owner_monthly_fee) if app_settings else "0.00",
|
||||
'ANNUAL': "{:.2f}".format(app_settings.truck_owner_annual_fee) if app_settings else "0.00",
|
||||
}
|
||||
}
|
||||
|
||||
@ -426,4 +426,4 @@ def terms_of_service(request):
|
||||
'content': app_settings.terms_of_service if app_settings else _("Terms of service are coming soon.")
|
||||
}
|
||||
}
|
||||
return render(request, 'core/article_detail.html', context)
|
||||
return render(request, 'core/article_detail.html', context)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user