From 0ca38d820c0257f33be8303b428833f8bb39fb31 Mon Sep 17 00:00:00 2001 From: NoeBerdoz Date: Thu, 22 Aug 2024 16:13:43 +0200 Subject: [PATCH] pre-commit --- .../static/src/js/website_widgets.js | 110 +++++++++--------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/crowdfunding_compassion/static/src/js/website_widgets.js b/crowdfunding_compassion/static/src/js/website_widgets.js index feaddfe..9711b15 100644 --- a/crowdfunding_compassion/static/src/js/website_widgets.js +++ b/crowdfunding_compassion/static/src/js/website_widgets.js @@ -35,62 +35,64 @@ odoo.define("crowdfunding_compassion.website_widgets", function (require) { // Handle donation card selection publicWidget.registry.CustomAmountSelection = publicWidget.Widget.extend({ - selector: '#custom-amount-card', - events: { - 'click': '_checkCustomCard', - }, - - start: function () { - this._super.apply(this, arguments); - // Attach click event listener to all card options except custom amount card - const otherCardsInputs = document.querySelectorAll('input[name="amount"]:not(#custom-amount-card)'); - otherCardsInputs.forEach(card => { - card.addEventListener('click', this._onCardClick.bind(this)); - }); - - // Attach input event listener to custom-amount-field - const customAmountField = document.getElementById('custom-amount-field'); - customAmountField.addEventListener('input', this._onInput.bind(this)); - }, - - // Check the custom amount card when custom amount field changes - _onInput: function () { - const customAmountField = document.getElementById('custom-amount-field'); - - if (customAmountField) { - const amount = customAmountField.value.trim(); - const isAmountNotEmpty = amount !== ''; - - if (isAmountNotEmpty) { - this._checkCustomCard(); - } - } - }, - - // Check the custom amount card and uncheck the others - _checkCustomCard: function (event) { - const customAmountCard = document.getElementById('custom-amount-card'); - const otherCardsInputs = document.querySelectorAll('input[name="amount"]:not(#custom-amount-card):not(#custom-amount-field)'); - - if (customAmountCard && otherCardsInputs) { - - customAmountCard.checked = true; - - otherCardsInputs.forEach(input => { - input.checked = false; - }); - } - }, - - // Uncheck the custom amount card when any other card option is clicked - _onCardClick: function (event) { - const customAmountCard = document.getElementById('custom-amount-card'); - if (customAmountCard) { - customAmountCard.checked = false; - } + selector: "#custom-amount-card", + events: { + click: "_checkCustomCard", + }, + + start: function () { + this._super.apply(this, arguments); + // Attach click event listener to all card options except custom amount card + const otherCardsInputs = document.querySelectorAll( + 'input[name="amount"]:not(#custom-amount-card)' + ); + otherCardsInputs.forEach((card) => { + card.addEventListener("click", this._onCardClick.bind(this)); + }); + + // Attach input event listener to custom-amount-field + const customAmountField = document.getElementById("custom-amount-field"); + customAmountField.addEventListener("input", this._onInput.bind(this)); + }, + + // Check the custom amount card when custom amount field changes + _onInput: function () { + const customAmountField = document.getElementById("custom-amount-field"); + + if (customAmountField) { + const amount = customAmountField.value.trim(); + const isAmountNotEmpty = amount !== ""; + + if (isAmountNotEmpty) { + this._checkCustomCard(); } + } + }, + + // Check the custom amount card and uncheck the others + _checkCustomCard: function (event) { + const customAmountCard = document.getElementById("custom-amount-card"); + const otherCardsInputs = document.querySelectorAll( + 'input[name="amount"]:not(#custom-amount-card):not(#custom-amount-field)' + ); + + if (customAmountCard && otherCardsInputs) { + customAmountCard.checked = true; - }); + otherCardsInputs.forEach((input) => { + input.checked = false; + }); + } + }, + + // Uncheck the custom amount card when any other card option is clicked + _onCardClick: function (event) { + const customAmountCard = document.getElementById("custom-amount-card"); + if (customAmountCard) { + customAmountCard.checked = false; + } + }, + }); // EDIT PROJECT FORM publicWidget.registry.EditProjectForm = publicWidget.Widget.extend({