diff --git a/addons/sale/static/src/js/product_configurator_controller.js b/addons/sale/static/src/js/product_configurator_controller.js index bf45779bd31..7ca3d32c292 100644 --- a/addons/sale/static/src/js/product_configurator_controller.js +++ b/addons/sale/static/src/js/product_configurator_controller.js @@ -94,14 +94,12 @@ var ProductConfiguratorFormController = FormController.extend({ ]; var productId = parseInt($modal.find(productSelector.join(', ')).first().val(), 10); - var productReady = this.renderer.selectOrCreateProduct( + this.renderer.selectOrCreateProduct( $modal, productId, $modal.find('.product_template_id').val(), false - ); - - productReady.done(function (productId) { + ).then(function (productId) { $modal.find(productSelector.join(', ')).val(productId); var variantValues = self diff --git a/addons/sale/static/src/js/product_configurator_mixin.js b/addons/sale/static/src/js/product_configurator_mixin.js index 1a74764aacc..1bf7cca730a 100644 --- a/addons/sale/static/src/js/product_configurator_mixin.js +++ b/addons/sale/static/src/js/product_configurator_mixin.js @@ -280,25 +280,25 @@ var ProductConfiguratorMixin = { }, /** - * Will return a deferred: + * Will return a promise: * * - If the product already exists, immediately resolves it with the product_id * - If the product does not exist yet ("dynamic" variant creation), this method will - * create the product first and then resolve the deferred with the created product's id + * create the product first and then resolve the promise with the created product's id * * @param {$.Element} $container the container to look into * @param {integer} productId the product id * @param {integer} productTemplateId the corresponding product template id * @param {boolean} useAjax wether the rpc call should be done using ajax.jsonRpc or using _rpc - * @returns {$.Deferred} the deferred that will be resolved with a {integer} productId + * @returns {Promise} the promise that will be resolved with a {integer} productId */ selectOrCreateProduct: function ($container, productId, productTemplateId, useAjax) { var self = this; productId = parseInt(productId); productTemplateId = parseInt(productTemplateId); - var productReady = $.Deferred(); + var productReady = Promise.resolve(); if (productId) { - productReady.resolve(productId); + productReady = Promise.resolve(productId); } else { var params = { product_template_id: productTemplateId, diff --git a/addons/sale/static/src/js/product_configurator_modal.js b/addons/sale/static/src/js/product_configurator_modal.js index c30c10b92b9..e8ad60b66d6 100644 --- a/addons/sale/static/src/js/product_configurator_modal.js +++ b/addons/sale/static/src/js/product_configurator_modal.js @@ -103,7 +103,7 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi }); var parentInit = self._super.apply(self, arguments); - return $.when(getModalContent, parentInit); + return Promise.all([getModalContent, parentInit]); }, /** @@ -124,7 +124,7 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi self.$modal.removeAttr("aria-hidden"); self.$modal.modal().appendTo(self.container); self.$modal.focus(); - self._opened.resolve(); + self._openedResolver(); } }); if (options && options.shouldFocusButtons) { @@ -353,14 +353,12 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi $main_product.after($parent); } - var productReady = this.selectOrCreateProduct( + this.selectOrCreateProduct( $parent, $parent.find('.product_id').val(), productTemplateId, true - ); - - productReady.done(function (productId){ + ).then(function (productId) { $parent.find('.product_id').val(productId); ajax.jsonRpc(self._getUri("/product_configurator/optional_product_items"), 'call', { diff --git a/addons/sale/static/src/js/product_configurator_renderer.js b/addons/sale/static/src/js/product_configurator_renderer.js index 8d16f2a329a..f3f437461ea 100644 --- a/addons/sale/static/src/js/product_configurator_renderer.js +++ b/addons/sale/static/src/js/product_configurator_renderer.js @@ -16,8 +16,10 @@ var ProductConfiguratorFormRenderer = FormRenderer.extend(ProductConfiguratorMix * @override */ start: function () { - this._super.apply(this, arguments); - this.$el.append($('