0
votes

I've followed instructions in this post

https://www.odoo.com/es_ES/forum/help-1/question/how-to-add-css-and-js-javascript-files-in-openerp-7-odoo-8-module-76719

to add javascript file to the front end (inheriting a template from website.assets_frontend)

When I log with a user that has permission to alter qweb the js is downloaded, but when I log with a user without that permission or with the anonymous user, the script is not downloaded.

I need this js script for anonymous users. What's wrong? what should i do?

<template id="assets_frontend" inherit_id="website.assets_frontend" name="menora_website assets"> 
  <xpath expr="/t" position="inside"> 
    <script type="text/javascript" src="/website_my_module/static/src/js/my_assets.js"></script> 
  </xpath> 
</template> 

this code works for admin user but not for the anonymous user

//my_assets.js 
$(document).ready(function () { 
  "use strict"; 
  var website = openerp.website; var _t = openerp._t; 
  $('#birdthdate').datepicker(); 
});
2
can you share the code on how you add the javascript to the front end? - jkris
i've added this code to inherit from website.assets_frontend. <template id="assets_frontend" inherit_id="website.assets_frontend" name="menora_website assets"> <xpath expr="/t" position="inside"> <script type="text/javascript" src="/website_my_module/static/src/js/my_assets.js"></script> </xpath> </template> this code works for admin user but not for the anonymous user my_assets.js $(document).ready(function () { "use strict"; var website = openerp.website; var _t = openerp._t; $('#birdthdate').datepicker(); }); - Marcelo Ariel Hamra
I've finally found the problem. The template was working ok, js file was included into assets_frontend. The problem was found in my javascript code- i've tried to use jquery $ variable before loading jquery libraries. The other problem was that i wanted to use jquery-ui elements, but jquery-ui is not included for portal users - Marcelo Ariel Hamra
awsome! maybe you could provide an answer so others could benefit from it - jkris

2 Answers

0
votes

My guess would be this line

<xpath expr="/t" position="inside"> 

Change expr="/t" to expr="." as shown in your reference

0
votes

Reviewing my code and results, I've observed that the Template snippet was working fine. JS file was downloaded or inserted into minized assets_frontend ok.

My js code was not working because it was inserted before JQuery definition. That's why Global $ variable was not defined yet. The position should be "after" the last <script> tag when inheriting the template.

I did not try my last suggestion, what I did was to insert a <script> tag at the end of the template I've created for my custom website UI. At this point, all js files were loaded the way global $ variable was defined.