feat: Improve image field lazy loading by checking src attribute and reducing timeout, and refine image field setup with role-based access in PDFIframe and SignablePDFIframe.
This commit is contained in:
parent
947543d54d
commit
c98aa6777e
@ -33,10 +33,10 @@ const setupLazyObserver = (iframeInstance, el) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const lazyImg = el.querySelector('.o_sign_image_lazy');
|
const lazyImg = el.querySelector('.o_sign_image_lazy');
|
||||||
if (!lazyImg || !lazyImg.dataset.src) return;
|
if (!lazyImg || (!lazyImg.dataset.src && !lazyImg.src)) return;
|
||||||
|
|
||||||
// Use a safety timeout to ensure it loads even if observer fails
|
// Use a safety timeout to ensure it loads even if observer fails
|
||||||
const safetyTimeout = setTimeout(() => triggerLazyLoad(el), 5000);
|
const safetyTimeout = setTimeout(() => triggerLazyLoad(el), 3000);
|
||||||
|
|
||||||
const observer = new IntersectionObserver((entries) => {
|
const observer = new IntersectionObserver((entries) => {
|
||||||
entries.forEach(entry => {
|
entries.forEach(entry => {
|
||||||
@ -52,30 +52,44 @@ const setupLazyObserver = (iframeInstance, el) => {
|
|||||||
observer.observe(el);
|
observer.observe(el);
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. Patch PDFIframe (Base class)
|
// 1. Patch PDFIframe (Base class) for read-only / non-signer views
|
||||||
// We patch only what is strictly necessary and avoid super calls if possible for base classes
|
|
||||||
patch(PDFIframe.prototype, {
|
patch(PDFIframe.prototype, {
|
||||||
enableCustom(signItem) {
|
enableCustom(signItem) {
|
||||||
// PDFIframe.enableCustom is normally empty
|
// Shared logic: Ensure lazy loading is set up for all image fields
|
||||||
if (typeof super.enableCustom === 'function') {
|
|
||||||
super.enableCustom(signItem);
|
|
||||||
}
|
|
||||||
if (signItem && signItem.data && signItem.data.type === 'image') {
|
if (signItem && signItem.data && signItem.data.type === 'image') {
|
||||||
setupLazyObserver(this, signItem.el);
|
setupLazyObserver(this, signItem.el);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base PDFIframe.enableCustom is empty, but we call super just in case of other patches
|
||||||
|
if (typeof super.enableCustom === 'function') {
|
||||||
|
super.enableCustom(signItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 2. Patch SignablePDFIframe (Subclass)
|
// 2. Patch SignablePDFIframe (Subclass) for active signers
|
||||||
patch(SignablePDFIframe.prototype, {
|
patch(SignablePDFIframe.prototype, {
|
||||||
enableCustom(signItem) {
|
enableCustom(signItem) {
|
||||||
// Ensure we call the base implementation (which now includes our lazy loading)
|
// IMPORTANT: Execute shared logic first!
|
||||||
|
// PDFIframe.enableCustom (our patch above) will handle lazy loading.
|
||||||
|
// However, SignablePDFIframe does NOT normally call super.enableCustom().
|
||||||
|
// We manually trigger the shared observation logic here to be sure.
|
||||||
|
if (signItem && signItem.data && signItem.data.type === 'image') {
|
||||||
|
setupLazyObserver(this, signItem.el);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now call the original SignablePDFIframe.enableCustom (which has the role check)
|
||||||
super.enableCustom(signItem);
|
super.enableCustom(signItem);
|
||||||
|
|
||||||
if (signItem && signItem.data && signItem.data.type === 'image') {
|
// Additional setup only for the current signer
|
||||||
|
if (signItem && signItem.data && signItem.data.type === 'image' && signItem.el) {
|
||||||
const el = signItem.el;
|
const el = signItem.el;
|
||||||
const data = signItem.data;
|
const data = signItem.data;
|
||||||
if (!el) return;
|
|
||||||
|
// Check if we are responsible for this field (duplicate check from original but needed for our additions)
|
||||||
|
if (this.readonly || data.responsible !== this.currentRole) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
el.setAttribute('data-type', 'image');
|
el.setAttribute('data-type', 'image');
|
||||||
|
|
||||||
@ -95,7 +109,6 @@ patch(SignablePDFIframe.prototype, {
|
|||||||
const input = el.querySelector('.o_sign_image_upload_input');
|
const input = el.querySelector('.o_sign_image_upload_input');
|
||||||
if (input) {
|
if (input) {
|
||||||
el.addEventListener('click', (e) => {
|
el.addEventListener('click', (e) => {
|
||||||
if (this.readonly || (data.responsible > 0 && data.responsible !== this.currentRole)) return;
|
|
||||||
if (e.target !== input) {
|
if (e.target !== input) {
|
||||||
input.click();
|
input.click();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user