Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[Odoo v.9c] Custom front-end UI and javascript

By
Thanh Loyal
on 8/22/16, 3:36 AM 325 views

Hello,

I want to create a custom front-end page, and I want to reuse the website.layout template, which provides header and footer of the website page. 

Inside the body section, I want to have a button. When that button is clicked, I want to call some javascript and make some communication with the back-end server.

What I have done is to follow the Theme tutorial (https://www.odoo.com/documentation/9.0/howtos/themes.html), but that tutorial is kind of creating a static page, I mean it lacks of how to communicate with backend and how to include javascript correctly.

I also try this code:

<button id="create_new_db" class="mt16">Create</button>

And js: I place these lines globally in a js file, I don't know where else to place it.

var button = document.getElementById("create_new_db");
console.log("Button: ", button);

This console.log shows "null"

I think that i took a wrong step, so my js get called before the page is rendered.

I have tried to find document on Odoo document for developer but still lost. The "Building interface extension" is still for v8.

Could you please give me some hint ?

Thank you!


0
Thanh Loyal
On 8/22/16, 6:47 AM

I resolve this by putting my code after require('website.website')


odoo.define('tut_theme.main', function (require) {    
'use strict';
var utils = require('web.utils');
var Model = require('web.Model');
var core = require('web.core');
var website = require('website.website'); // The important line
 
var button = document.getElementById("create_new_db");
console.log("Button: ", button); // It works this time
$("#create_new_db").click(function () {
console.log("Clicked");
});
});

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/22/16, 3:36 AM
Seen: 325 times
Last updated: 8/22/16, 7:09 AM