From db592efca282d12f6fcef38a13dc2cbff31522b8 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Fri, 20 Feb 2015 11:18:54 +0100 Subject: [PATCH] [ADD] Web: openerpframework.js: willStart() function Add the willStart() function to Widgets. This function is executed between init() and start() and its purpose is to perform various asynchronous calls required for start() to be executed. It is automatically called after rendering a Widget, and start() is called once the Deferred returned by willStart() is resolved. --- addons/web/static/src/js/framework/widget.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/framework/widget.js b/addons/web/static/src/js/framework/widget.js index aae0ed36c19..ad68f4e9410 100644 --- a/addons/web/static/src/js/framework/widget.js +++ b/addons/web/static/src/js/framework/widget.js @@ -95,6 +95,16 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, { // FIXME: this should not be this.setElement(this._make_descriptive()); }, + /** + * Method called between init and start. Performs asynchronous calls required by start. + * + * This method should return a Deferred which is resolved when start can be executed. + * + * @return {jQuery.Deferred} + */ + willStart: function() { + return $.when(); + }, /** * Destroys the current widget, also destroys all its children before destroying itself. */ @@ -162,9 +172,12 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, { }, this), target); }, __widgetRenderAndInsert: function(insertion, target) { - this.renderElement(); - insertion(target); - return this.start(); + var self = this; + return this.willStart().then(function() { + self.renderElement(); + insertion(target); + return self.start(); + }); }, /** * Method called after rendering. Mostly used to bind actions, perform asynchronous