(English) How to add an HTML element at the bottom of the last page of a webkit report


Ci spiace, ma questo articolo è disponibile soltanto in English.

Facebook Twitter Linkedin Digg Delicious Reddit Stumbleupon Tumblr Posterous Email Snailmail

Written by on martedì, maggio 27th, 2014

Lorenzo Battistini
OpenERP addicted
GitHub profile: https://github.com/eLBati
Launchpad profile: https://launchpad.net/~elbati
Linkedin profile: http://www.linkedin.com/in/elbati
Agile Business Group
  • http://profile.e-ware.org/ Francesco Scapigliato

    Grazie mille Lorenzo. Era da tempo che attendevo un articolo così!

  • Valentin LAB

    You should probably:

    – move out the two lines about “signature_div“ out of the “for“. Since there are no reason to be included there, and they will get executed as many times (7 times) there are elements in “x“ array, for no reasons.
    – in your current example, move the “.getElementsByClassName“ in the “if“ (no need to fetch the element if you already know that you won’t need to change it), or…
    – set visibility to “hidden“ when it should be hidden via js to avoid having two different places tinkering with visibility.

    In last version of odoo, version 8 (or saas-6), to enable special class names to do special things (as for instance a ‘last-page’ class name to trigger visibility), you should only modify “report“ module, in “static/src/js/subst.js“, and add this code to the “subst“ function:

    var operations = {
    'last-page': function (elt) { elt.style.visibility = (vars.page === vars.topage) ? "visible" : "hidden"; },

    for (var klass in operations) {
    var y = document.getElementsByClassName(klass);
    for (var j=0; j<y.length; ++j) operations[klass](y[j]);

    In the QWEB “ir.ui.views“ used by your report, you can then add anywhere (header, body, footer), code with:

    My content only displayed if on last page.

    Adding other operations is quite easy with this structure. For instance, “first-page“, “odd-page“ … or any other variation could be easily done by adding a proper line in the operations. Some people would probably also prefer to set “display: none“ to remove the space taken by the box. You could allow both possibility with “display-last-page“ and “visiblity-last-page“ classes. The code is straightforward. You could even do a “last-page-set-class-myclass“ to set a CSS class on conditions.

    Hope this helps others,

    Thank you for your original post !

    • Anil Kesariya

      Thank you very much for sharing this. this helped me a lot. 🙂

    • Jean-Charles Drubay

      Nice page and answers. I think one point is still unsolved so…

      I am part of the people who would prefer to set “display: none“ to remove the space taken by the box. But when doing so, the rest of the content of my footer just moves up, and the footer of all pages have the same size (which is too big for all pages except the last one).

  • Anil Kesariya

    Nice Blog! how to apply the same for qweb report?