diff options
Diffstat (limited to 'addons/web/static/src/js/core/widget.js')
| -rw-r--r-- | addons/web/static/src/js/core/widget.js | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/addons/web/static/src/js/core/widget.js b/addons/web/static/src/js/core/widget.js index d3b9cc1033c..0de8c6aa1cd 100644 --- a/addons/web/static/src/js/core/widget.js +++ b/addons/web/static/src/js/core/widget.js @@ -31,7 +31,7 @@ var ServicesMixin = require('web.ServicesMixin'); * }, * willStart: function () { * // async work that need to be done before the widget is ready - * // this method should return a deferred + * // this method should return a promise * }, * start: function() { * // stuff you want to make after the rendering, `this.$el` holds a correct value @@ -135,45 +135,47 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * Method called between @see init and @see start. Performs asynchronous * calls required by the rendering and the start method. * - * This method should return a Deferred which is resolved when start can be + * This method should return a Promose which is resolved when start can be * executed. * - * @returns {Deferred} + * @returns {Promise} */ willStart: function () { - var defs = []; + var proms = []; if (this.xmlDependencies) { - defs.push.apply(defs, _.map(this.xmlDependencies, function (xmlPath) { + proms.push.apply(proms, _.map(this.xmlDependencies, function (xmlPath) { return ajax.loadXML(xmlPath, core.qweb); })); } if (this.jsLibs || this.cssLibs || this.assetLibs) { - defs.push(ajax.loadLibs(this)); + proms.push(ajax.loadLibs(this)); } - return $.when.apply($, defs); + return Promise.all(proms); }, /** * Method called after rendering. Mostly used to bind actions, perform * asynchronous calls, etc... * * By convention, this method should return an object that can be passed to - * $.when() to inform the caller when this widget has been initialized. + * Promise.resolve() to inform the caller when this widget has been initialized. * * Note that, for historic reasons, many widgets still do work in the start * method that would be more suited to the willStart method. * - * @returns {Deferred} + * @returns {Promise} */ start: function () { - return $.when(); + return Promise.resolve(); }, /** * Destroys the current widget, also destroys all its children before * destroying itself. */ destroy: function () { - _.invoke(this.getChildren(), 'destroy'); - if(this.$el) { + this.getChildren().forEach(function (child) { + child.destroy(); + }); + if (this.$el) { this.$el.remove(); } mixins.PropertiesMixin.destroy.call(this); @@ -187,6 +189,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * Renders the current widget and appends it to the given jQuery object. * * @param {jQuery} target + * @returns {Promise} */ appendTo: function (target) { var self = this; @@ -198,6 +201,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * Attach the current widget to a dom element * * @param {jQuery} target + * @returns {Promise} */ attachTo: function (target) { var self = this; @@ -234,6 +238,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * object. * * @param {jQuery} target + * @returns {Promise} */ insertAfter: function (target) { var self = this; @@ -246,6 +251,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * object. * * @param {jQuery} target + * @returns {Promise} */ insertBefore: function (target) { var self = this; @@ -257,6 +263,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * Renders the current widget and prepends it to the given jQuery object. * * @param {jQuery} target + * @returns {Promise} */ prependTo: function (target) { var self = this; @@ -282,6 +289,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * Renders the current widget and replaces the given jQuery object. * * @param target A jQuery object or a Widget instance. + * @returns {Promise} */ replace: function (target) { return this._widgetRenderAndInsert(_.bind(function (t) { @@ -415,7 +423,7 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, { * @private * @param {function: jQuery -> any} insertion * @param {jQuery} target - * @returns {Deferred} + * @returns {Promise} */ _widgetRenderAndInsert: function (insertion, target) { var self = this; |
