Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] Sign Oca problem with sign a document #90

Closed
anddago78 opened this issue Mar 10, 2025 · 3 comments
Closed

[16.0] Sign Oca problem with sign a document #90

anddago78 opened this issue Mar 10, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@anddago78
Copy link

Issue in the signature module: When I try to sign a document, if I scroll through the pages and then attempt to sign it, sometimes the click on the signature fields doesn't work. Below, I’m attaching a video so you can see the issue.

Module

sign_oca

Describe the bug

sometimes lost the click event in the signature space...

To Reproduce

Odoo 16 community:

Steps to reproduce the behavior:
1.Create a template,
2. create a request
3. try to sign the document after scrolling the pages

A video for more details:

https://www.loom.com/share/7e44ecef3ed9424f9a650fe63073fe06?sid=d8a25379-7155-4f10-8ca2-3fb1ef8bbbeb

@anddago78 anddago78 added the bug Something isn't working label Mar 10, 2025
@raul660322
Copy link

raul660322 commented Mar 10, 2025

This issue can be solved modifying the file sign_oca_pdf_common.esm.js:

export default class SignOcaPdfCommon extends Component {
    setup() {
        super.setup(...arguments);
        this.field_template = "sign_oca.sign_iframe_field";
        console.log(this.props);
        this.pdf_url = this.getPdfUrl();
        this.viewer_url = "/web/static/lib/pdfjs/web/viewer.html?file=" + this.pdf_url;
        this.iframe = useRef("sign_oca_iframe");
        var iframeResolve = undefined;
        var iframeReject = undefined;
        this.iframeLoaded = new Promise(function (resolve, reject) {
            iframeResolve = resolve;
            iframeReject = reject;
        });
        this.items = {};
        onWillUnmount(() => {
            clearTimeout(this.reviewFieldsTimeout);
        });
        this.iframeLoaded.resolve = iframeResolve;
        this.iframeLoaded.reject = iframeReject;
        onWillStart(this.willStart.bind(this));
        onMounted(() => {
            this.waitIframeLoaded();
        });
        //Add the code here to include the resize event listener
        window.onresize = ()=> {
            this.waitIframeLoaded();
        }
    }

Also here:

    waitIframeLoaded() {
        var error = this.iframe.el.contentDocument.getElementById("errorWrapper");
       //Include here the scroll event listener
        this.iframe.el.contentDocument.getElementById("viewerContainer")?.addEventListener("scroll", (event) => {  
            this.postIframeFields();
        });  
        
        if (error && window.getComputedStyle(error).display !== "none") {
            this.iframeLoaded.resolve();
            return Dialog.alert(this, _t("Need a valid PDF to add signature fields !"));
        }
        var nbPages =
            this.iframe.el.contentDocument.getElementsByClassName("page").length;
        var nbLayers =
            this.iframe.el.contentDocument.getElementsByClassName(
                "endOfContent"
            ).length;
        if (nbPages > 0 && nbLayers > 0) {
            this.postIframeFields();
            this.reviewFields();
        } else {
            var self = this;
            setTimeout(function () {
                self.waitIframeLoaded();
            }, 50);
        }
    }

@raul660322
Copy link

raul660322 commented Mar 10, 2025

Also, in method postIframeFields() I removed this code:

        iframeJs.setAttribute("type", "text/javascript");
        iframeJs.setAttribute("src", "/sign_oca/get_assets.js");

to avoid error 404

@anddago78
Copy link
Author

@raul660322 this solution work perfectly! thanks a lot!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants