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 catch promise before calling this._super? Javascript

By
Replicateur
on 10/8/14, 4:39 AM 1,835 views

Hi everybody,

I would like to get result from my request "instance.web.Model", then call this.super(). The matter is that "instance.web.Model" is asynchronous, so in my case the super() will be called before the request has finished.

    MyObject.extend({

        init: function(parent, data){

            var newData = instance.web.Model('advanced.search')

            .call('check_duplication', [data]).done(function (name) {

                // do stuff

                return name

            });

            data = newData;

            this._super.apply(this, arguments);

            // super is called before my request is done so the new data are not sent to super.

        }

    });

Do you know how to get through that? In order to pass the newData instead data as argument to the super object.

PS : I tried to encapsulate this in self : var self = this; but it does not work because it seems the parent object I extend continue to run without waiting. So I got error like "self.super(... is not a function".

Odoo comes with jQuery BlockUI plugin. I believe, it can help you.

Ben Bernard
on 10/8/14, 6:14 AM

How to implement it? I tried some simple $.blockUI() -> $.unblockUI() but I cannot get the right behavior.

Replicateur
on 10/8/14, 6:41 AM

In odoo: instance.web.blockUI() and instance.web.unblockUI().

Ben Bernard
on 10/9/14, 12:01 AM

blockUI does not avoid super to be called before Model has done its request. If I try to deferred it tells me : "dict.widget.attrs is undefined". Whenever I try to call super only when request is done I got this error back

Replicateur
on 10/9/14, 3:42 AM
0

Thierry Godin

--Thierry Godin--
1516
| 8 7 8
Collegien, France
--Thierry Godin--

..

Thierry Godin
On 10/13/14, 10:55 AM

Hello , try this :

init: function(parent, data){
      var tmp = this._super.apply(this, arguments);

// your function here

return tmp;

},

Also, you can put your function in another block and call it like bellow :

$.when(self.your_function()).done(function(result){     
                //continue
            });

Thx Thierry for reply, I'll tell you whether it succeed once I try it.

Replicateur
on 10/13/14, 11:07 AM

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

2 follower(s)

Stats

Asked: 10/8/14, 4:39 AM
Seen: 1835 times
Last updated: 3/16/15, 8:10 AM