refactor: Replace DOM observer-based decimal styling with direct wrapDecimal integration in field formatters.
This commit is contained in:
parent
61c3f010a9
commit
d28cfcaa89
@ -151,26 +151,27 @@ const ultraSafeObserver = new MutationObserver((mutations) => {
|
|||||||
|
|
||||||
// Start ultra-safe observing
|
// Start ultra-safe observing
|
||||||
function startUltraSafeObserver() {
|
function startUltraSafeObserver() {
|
||||||
console.log('Ultra-Safe Decimal Observer: Starting ultra-conservative observation');
|
// console.log('Ultra-Safe Decimal Observer: Starting ultra-conservative observation');
|
||||||
|
|
||||||
// Process existing content safely with delay
|
// Process existing content safely with delay
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
ultraSafelyProcessContainer(document.body);
|
// ultraSafelyProcessContainer(document.body);
|
||||||
}, 1000); // Initial delay to let everything load
|
// }, 1000); // Initial delay to let everything load
|
||||||
|
|
||||||
// Start observing for new content with very reduced frequency
|
// Start observing for new content with very reduced frequency
|
||||||
ultraSafeObserver.observe(document.body, {
|
// ultraSafeObserver.observe(document.body, {
|
||||||
childList: true,
|
// childList: true,
|
||||||
subtree: true
|
// subtree: true
|
||||||
});
|
// });
|
||||||
|
|
||||||
// Much less frequent periodic processing to reduce conflicts
|
// Much less frequent periodic processing to reduce conflicts
|
||||||
setInterval(() => {
|
// setInterval(() => {
|
||||||
ultraSafelyProcessContainer(document.body);
|
// ultraSafelyProcessContainer(document.body);
|
||||||
}, 10000); // Every 10 seconds instead of 5
|
// }, 10000); // Every 10 seconds instead of 5
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start ultra-safely
|
// Start ultra-safely
|
||||||
|
/*
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
setTimeout(startUltraSafeObserver, 2000); // Extra delay
|
setTimeout(startUltraSafeObserver, 2000); // Extra delay
|
||||||
@ -178,5 +179,6 @@ if (document.readyState === 'loading') {
|
|||||||
} else {
|
} else {
|
||||||
setTimeout(startUltraSafeObserver, 2000); // Extra delay
|
setTimeout(startUltraSafeObserver, 2000); // Extra delay
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
console.log('Ultra-safe decimal observer loaded');
|
console.log('Ultra-safe decimal observer disabled');
|
||||||
@ -21,25 +21,11 @@ try {
|
|||||||
noSymbol: !this.props.readonly || this.props.hideSymbol,
|
noSymbol: !this.props.readonly || this.props.hideSymbol,
|
||||||
});
|
});
|
||||||
|
|
||||||
// For readonly fields, apply decimal styling via safe DOM manipulation
|
// Start of Owl Safe Decimal Styling
|
||||||
if (this.props.readonly) {
|
if (this.props.readonly) {
|
||||||
// Use a longer timeout to avoid Owl lifecycle conflicts
|
return wrapDecimal(res);
|
||||||
setTimeout(() => {
|
|
||||||
try {
|
|
||||||
const element = this.el?.querySelector('.o_field_monetary');
|
|
||||||
if (element && !element.querySelector('.o_decimal') && document.contains(element)) {
|
|
||||||
const text = element.textContent;
|
|
||||||
const match = text?.match(/^(.*)(\d{1,3}(?:[.,]\d{3})*)[.,](\d+)(.*)$/);
|
|
||||||
if (match && element.textContent === text) { // Double-check content hasn't changed
|
|
||||||
const [, prefix, integerPart, decimalPart, suffix] = match;
|
|
||||||
element.innerHTML = `${prefix}${integerPart}<span class="o_decimal">.${decimalPart}</span>${suffix}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Monetary field decimal styling error (non-critical):', error);
|
|
||||||
}
|
|
||||||
}, 150); // Longer delay to avoid Owl conflicts
|
|
||||||
}
|
}
|
||||||
|
// End of Owl Safe Decimal Styling
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -68,24 +54,11 @@ try {
|
|||||||
res = formatFloat(this.value, { ...options, humanReadable: false });
|
res = formatFloat(this.value, { ...options, humanReadable: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
// For readonly fields, apply decimal styling via safe DOM manipulation
|
// Start of Owl Safe Decimal Styling
|
||||||
if (this.props.readonly) {
|
if (this.props.readonly) {
|
||||||
setTimeout(() => {
|
return wrapDecimal(res);
|
||||||
try {
|
|
||||||
const element = this.el?.querySelector('.o_field_float');
|
|
||||||
if (element && !element.querySelector('.o_decimal') && document.contains(element)) {
|
|
||||||
const text = element.textContent;
|
|
||||||
const match = text?.match(/^(.*)(\d+)[.](\d+)(.*)$/);
|
|
||||||
if (match && element.textContent === text) { // Double-check content hasn't changed
|
|
||||||
const [, prefix, integerPart, decimalPart, suffix] = match;
|
|
||||||
element.innerHTML = `${prefix}${integerPart}<span class="o_decimal">.${decimalPart}</span>${suffix}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.warn('Float field decimal styling error (non-critical):', error);
|
|
||||||
}
|
|
||||||
}, 150);
|
|
||||||
}
|
}
|
||||||
|
// End of Owl Safe Decimal Styling
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@ -94,6 +67,7 @@ try {
|
|||||||
console.warn('Field patching error (non-critical):', error);
|
console.warn('Field patching error (non-critical):', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Safe Registry Patching for List Views
|
||||||
// Safe Registry Patching for List Views
|
// Safe Registry Patching for List Views
|
||||||
try {
|
try {
|
||||||
const formattersRegistry = registry.category("formatters");
|
const formattersRegistry = registry.category("formatters");
|
||||||
@ -110,9 +84,8 @@ try {
|
|||||||
formattersRegistry.add(name, (...args) => {
|
formattersRegistry.add(name, (...args) => {
|
||||||
try {
|
try {
|
||||||
const res = original(...args);
|
const res = original(...args);
|
||||||
// Return the result as-is, let DOM observer handle styling
|
// Safely wrap with Owl Markup
|
||||||
// This avoids markup escaping issues and Owl conflicts
|
return wrapDecimal(res);
|
||||||
return res;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn(`Formatter ${name} error (non-critical):`, error);
|
console.warn(`Formatter ${name} error (non-critical):`, error);
|
||||||
return original(...args); // Fallback to original
|
return original(...args); // Fallback to original
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user