summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/views')
-rw-r--r--addons/web/static/src/js/views/abstract_controller.js1
-rw-r--r--addons/web/static/src/js/views/abstract_view.js11
-rw-r--r--addons/web/static/src/js/views/action_model.js52
3 files changed, 56 insertions, 8 deletions
diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js
index 5128fa6d9a8..2f819bff7a5 100644
--- a/addons/web/static/src/js/views/abstract_controller.js
+++ b/addons/web/static/src/js/views/abstract_controller.js
@@ -222,7 +222,6 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
reload: async function (params = {}) {
if (params.controllerState) {
this.importState(params.controllerState);
- await this.searchModel.load();
Object.assign(params, this.searchModel.get('query'));
}
return this.update(params, {});
diff --git a/addons/web/static/src/js/views/abstract_view.js b/addons/web/static/src/js/views/abstract_view.js
index 04b1b781848..129cb6817b3 100644
--- a/addons/web/static/src/js/views/abstract_view.js
+++ b/addons/web/static/src/js/views/abstract_view.js
@@ -306,13 +306,16 @@ var AbstractView = Factory.extend({
*/
getController: async function () {
const _super = this._super.bind(this);
- await this.controllerParams.searchModel.load();
- const query = this.controllerParams.searchModel.get('query');
- this._updateMVCParams(query);
+ const { searchModel } = this.controllerParams;
+ await searchModel.load();
+ this._updateMVCParams(searchModel.get("query"));
// get the parent of the model if it already exists, as _super will
// set the new controller as parent, which we don't want
const modelParent = this.model && this.model.getParent();
- const controller = await _super(...arguments);
+ const [controller] = await Promise.all([
+ _super(...arguments),
+ searchModel.isReady(),
+ ]);
if (modelParent) {
// if we already add a model, restore its parent
this.model.setParent(modelParent);
diff --git a/addons/web/static/src/js/views/action_model.js b/addons/web/static/src/js/views/action_model.js
index 382aa30531b..c3b69271a07 100644
--- a/addons/web/static/src/js/views/action_model.js
+++ b/addons/web/static/src/js/views/action_model.js
@@ -17,6 +17,29 @@ odoo.define("web/static/src/js/views/action_model.js", function (require) {
class ActionModelExtension extends Model.Extension {
//---------------------------------------------------------------------
+ // Public
+ //---------------------------------------------------------------------
+
+ /**
+ * Initiates the asynchronous tasks of the extension and returns a
+ * promise resolved as soon as all the informations necessary to build
+ * the search query are ready.
+ * @returns {Promise}
+ */
+ async callLoad() {
+ this.loadPromise = super.callLoad(...arguments);
+ await this.loadPromise;
+ }
+
+ /**
+ * Returns a promise resolved when the extension is completely ready.
+ * @returns {Promise}
+ */
+ async isReady() {
+ await this.loadPromise;
+ }
+
+ //---------------------------------------------------------------------
// Static
//---------------------------------------------------------------------
@@ -51,11 +74,29 @@ odoo.define("web/static/src/js/views/action_model.js", function (require) {
return super.get(...arguments);
}
+ /**
+ * Returns a promise resolved when all extensions are completely ready.
+ * @returns {Promise}
+ */
+ async isReady() {
+ await this._awaitExtensions();
+ }
+
//---------------------------------------------------------------------
// Private
//---------------------------------------------------------------------
/**
+ * @private
+ * @returns {Promise}
+ */
+ async _awaitExtensions() {
+ await Promise.all(this.extensions.flat().map(
+ (extension) => extension.isReady()
+ ));
+ }
+
+ /**
* @override
*/
__get(excluded, property) {
@@ -140,11 +181,16 @@ odoo.define("web/static/src/js/views/action_model.js", function (require) {
}
/**
+ * Overridden to trigger a "search" event as soon as the query data
+ * are ready.
* @override
*/
- _notifyComponents() {
- this.trigger("search", this.get("query"));
- super._notifyComponents(...arguments);
+ async _loadExtensions({ isInitialLoad }) {
+ await super._loadExtensions(...arguments);
+ if (!isInitialLoad) {
+ this.trigger("search", this.get("query"));
+ await this._awaitExtensions();
+ }
}
//---------------------------------------------------------------------