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

How to change template of instance.web.ViewManager according to dataset.context parameter?

By
Daniela Scarpa
on 8/6/15, 10:38 AM 527 views

I want to create a special custom view for kanban. This view has to have special View Manager too.
In my_module_view.xml file I have menuitem and action definition. Action has context: 

<field name="context">{'special_view': True}</field>

Into my_module.js file I want to change template of instance.web.ViewManager only when context has 'special_view' true.

init: function (parent, dataset, view_id, options) {
    if (this.dataset.context.special_view) {
    	this.template = "MyViewManager";
    }
    this._super(parent, dataset, view_id, options);
 },
Unfortunately, this.dataset is null and I get this exception: Uncaught TypeError: Cannot read property 'context' of undefined.

Is there another way to change this template according to special_view value of context?

Thank you.

0
Daniela Scarpa
On 8/6/15, 12:38 PM

Because I've found a solution myself, I want to answer my own question, in case someone will have the same problem.

The code was right, but I was customizing the wrong Class.

SOLUTION:


instance.web.ViewManagerAction.include({
    init: function (parent, dataset, view_id, options) { this._super(parent, dataset, view_id, options); if (this.dataset.context.special_view) {     this.template = "MyViewManager"; } },
});

Greetings.

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/6/15, 10:38 AM
Seen: 527 times
Last updated: 3/7/16, 5:50 AM