fix: Ensure sign items are always visible by injecting CSS overrides and explicitly removing the d-none class.
This commit is contained in:
parent
424e68c57c
commit
bf06e5be06
@ -4,19 +4,20 @@ import { patch } from "@web/core/utils/patch";
|
||||
import { PDFIframe } from "@sign/components/sign_request/PDF_iframe";
|
||||
import { SignablePDFIframe } from "@sign/components/sign_request/signable_PDF_iframe";
|
||||
|
||||
console.log("Sign Image Field: Re-evaluating patch strategy without overriding enableCustom for base classes");
|
||||
console.log("Sign Image Field: Initializing CSS-forced visibility patches...");
|
||||
|
||||
/**
|
||||
* Diagnostic Bridge Restoration
|
||||
* Diagnostic Bridge Restoration & Universal Force-Show
|
||||
* We re-connect the bridge but ALSO forcefully inject CSS to ensure elements are never hidden.
|
||||
*/
|
||||
const restoreBridge = (instance, caller) => {
|
||||
const restoreBridgeAndForceShow = (instance, caller) => {
|
||||
if (!instance || !instance.root || !instance.root.defaultView) return;
|
||||
|
||||
const iwin = instance.root.defaultView;
|
||||
const iframe = iwin.frameElement;
|
||||
const isDocReady = iwin.document && iwin.document.head;
|
||||
|
||||
if (iframe && !iframe.odoo_iframe_instance) {
|
||||
// Only log once per frame to reduce noise
|
||||
if (!iframe._odoo_bridge_logged) {
|
||||
console.log(`[Diagnostic] Restoring bridge on iframe element from ${caller}`);
|
||||
iframe._odoo_bridge_logged = true;
|
||||
@ -28,13 +29,27 @@ const restoreBridge = (instance, caller) => {
|
||||
iwin.odoo_iframe_instance = instance;
|
||||
}
|
||||
|
||||
if (iwin.document && !iwin.document.odoo_iframe_instance) {
|
||||
iwin.document.odoo_iframe_instance = instance;
|
||||
}
|
||||
|
||||
if (iwin.PDFViewerApplication && !iwin.PDFViewerApplication.odoo_iframe_instance) {
|
||||
iwin.PDFViewerApplication.odoo_iframe_instance = instance;
|
||||
}
|
||||
|
||||
// ULTIMATE FALLBACK: Inject CSS to override Odoo's broken d-none toggler
|
||||
if (isDocReady && !iwin.document._odoo_force_show_injected) {
|
||||
console.log(`[Diagnostic] Injecting permanent override CSS from ${caller}`);
|
||||
const style = iwin.document.createElement('style');
|
||||
style.type = 'text/css';
|
||||
// Force display block and override any inline or class-based display:none
|
||||
style.innerHTML = `
|
||||
.o_sign_sign_item.d-none {
|
||||
display: block !important;
|
||||
}
|
||||
.o_sign_sign_item[style*="display: none"] {
|
||||
display: block !important;
|
||||
}
|
||||
`;
|
||||
iwin.document.head.appendChild(style);
|
||||
iwin.document._odoo_force_show_injected = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
@ -88,30 +103,26 @@ const setupLazyObserver = (el) => {
|
||||
}
|
||||
};
|
||||
|
||||
window.diagnosticForceShowFields = () => {
|
||||
const hiddenItems = document.querySelectorAll('iframe.o_sign_pdf_iframe')?.length ?
|
||||
document.querySelector('iframe.o_sign_pdf_iframe').contentDocument.querySelectorAll('.o_sign_sign_item.d-none') : [];
|
||||
|
||||
console.log(`[Diagnostic] Forcing show on ${hiddenItems.length} hidden items`);
|
||||
hiddenItems.forEach(el => el.classList.remove('d-none'));
|
||||
};
|
||||
|
||||
const processedItems = new WeakSet();
|
||||
|
||||
// Safest Patching Strategy: Only patch `PDFIframe.prototype.refreshSignItemsForPage`
|
||||
// This avoids ANY issues with `enableCustom` halting mid-execution.
|
||||
// Patching Strategy: Use refreshSignItemsForPage as the hook point because it's
|
||||
// called every time page renders, giving us a reliable hook to inject CSS
|
||||
patch(PDFIframe.prototype, {
|
||||
refreshSignItemsForPage(page) {
|
||||
// Restore bridge right before items are evaluated
|
||||
restoreBridge(this, 'PDFIframe.refreshSignItemsForPage');
|
||||
restoreBridgeAndForceShow(this, 'PDFIframe.refreshSignItemsForPage');
|
||||
|
||||
// Execute original first so elements get un-hidden (d-none removed)
|
||||
try {
|
||||
const result = super.refreshSignItemsForPage(...arguments);
|
||||
|
||||
// Now find all image elements and apply our custom observer
|
||||
// Image tracking
|
||||
if (this.signItems && this.signItems[page]) {
|
||||
for (const id in this.signItems[page]) {
|
||||
const item = this.signItems[page][id];
|
||||
// Also forcefully remove d-none via JS just in case
|
||||
if (item && item.el) {
|
||||
item.el.classList.remove('d-none');
|
||||
}
|
||||
|
||||
if (item && item.data && item.data.type === 'image' && item.el && !processedItems.has(item.el)) {
|
||||
processedItems.add(item.el);
|
||||
setupLazyObserver(item.el);
|
||||
@ -187,8 +198,11 @@ patch(PDFIframe.prototype, {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("[Diagnostic] Error inside refreshSignItemsForPage:", error);
|
||||
// Even if super fails, don't crash our script
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user