Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
NoeBerdoz committed Aug 22, 2024
1 parent f3184cf commit d144258
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 55 deletions.
110 changes: 56 additions & 54 deletions crowdfunding_compassion/static/src/js/website_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@
name="amount"
t-att-value="amount"
min="1"
/>
/>
<h3
class="text-primary"
>CHF</h3>
Expand Down

0 comments on commit d144258

Please sign in to comment.