Refactor AXO module

This commit is contained in:
Pedro Silva 2024-03-14 10:54:15 +00:00
parent a9d2f97a80
commit 578a5426dc
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
7 changed files with 337 additions and 121 deletions

View file

@ -23,8 +23,15 @@ class DomElementCollection {
className: 'ppcp-axo-watermark-container'
});
this.allFields = new DomElement({
selector: '#customer_details .form-row, #customer_details .woocommerce-shipping-fields'
this.customerDetails = new DomElement({
selector: '#customer_details > *:not(#ppcp-axo-customer-details)'
});
this.axoCustomerDetails = new DomElement({
id: 'ppcp-axo-customer-details',
selector: '#ppcp-axo-customer-details',
className: 'ppcp-axo-customer-details',
anchorSelector: '#customer_details'
});
this.emailWidgetContainer = new DomElement({
@ -36,15 +43,13 @@ class DomElementCollection {
this.shippingAddressContainer = new DomElement({
id: 'ppcp-axo-shipping-address-container',
selector: '#ppcp-axo-shipping-address-container',
className: 'ppcp-axo-shipping-address-container',
anchorSelector: '.woocommerce-shipping-fields'
className: 'ppcp-axo-shipping-address-container'
});
this.billingAddressContainer = new DomElement({
id: 'ppcp-axo-billing-address-container',
selector: '#ppcp-axo-billing-address-container',
className: 'ppcp-axo-billing-address-container',
anchorSelector: '.woocommerce-billing-fields__field-wrapper'
className: 'ppcp-axo-billing-address-container'
});
this.fieldBillingEmail = new DomElement({

View file

@ -48,36 +48,40 @@ class MockData {
content.innerHTML = '';
if (!this.active) {
this.hideField(this.contentSelector);
} else {
this.showField(this.contentSelector);
}
Object.keys(this.fields).forEach((key) => {
const field = this.fields[key];
if (this.active) {
this.hideField(field.selector);
//this.showField(this.contentSelector);
} else {
this.showField(field.selector);
//this.hideField(this.contentSelector);
}
if (typeof this.template === 'function') {
content.innerHTML = this.template({
value: (valueKey) => {
return this.getDataValue(this.fields[valueKey].valuePath);
},
isEmpty: () => {
let isEmpty = true;
Object.values(this.fields).forEach((valueField) => {
if (this.getDataValue(valueField.valuePath)) {
isEmpty = false;
return false;
}
});
return isEmpty;
}
});
}
});
if (typeof this.template === 'function') {
content.innerHTML = this.template({
value: (valueKey) => {
return this.getDataValue(this.fields[valueKey].valuePath);
},
isEmpty: () => {
let isEmpty = true;
Object.values(this.fields).forEach((valueField) => {
if (this.getDataValue(valueField.valuePath)) {
isEmpty = false;
return false;
}
});
return isEmpty;
}
});
}
}
showField(selector) {