summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-06-29 16:38:34 +0200
committerqsm-odoo <qsm@odoo.com>2017-07-24 13:41:50 +0200
commitdbfdd86cc2c49abdebfb3b31d6233f11368feb49 (patch)
tree487b8ccaac163db28b57156a191b284737eb1c32 /addons/web/static/src/js
parent417a664f16abc67bee40a0067103f9cf2c412aed (diff)
[IMP] web: add a widget property which allows to lazy load xml files
Add the 'xmlDependencies' key to the 'Widget' class. If defined, it is an array of URLs to XML files that the widget will need to work. Those are loaded in the `willStart` method so that they are available before all rendering parts.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/widget.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/addons/web/static/src/js/core/widget.js b/addons/web/static/src/js/core/widget.js
index 82e8041c98a..8ef141a6020 100644
--- a/addons/web/static/src/js/core/widget.js
+++ b/addons/web/static/src/js/core/widget.js
@@ -1,6 +1,7 @@
odoo.define('web.Widget', function (require) {
"use strict";
+var ajax = require('web.ajax');
var core = require('web.core');
var mixins = require('web.mixins');
var ServicesMixin = require('web.ServicesMixin');
@@ -70,6 +71,15 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, {
*/
template: null,
/**
+ * List of paths to xml files that need to be loaded before the widget can
+ * be rendered. This will not induce loading anything that has already been
+ * loaded.
+ *
+ * @type {string[]}
+ */
+ xmlDependencies: null,
+
+ /**
* Constructs the widget and sets its parent if a parent is given.
*
* @constructs openerp.Widget
@@ -94,13 +104,21 @@ var Widget = core.Class.extend(mixins.PropertiesMixin, ServicesMixin, {
this.setElement(this._make_descriptive());
},
/**
- * Method called between init and start. Performs asynchronous calls required by start.
+ * 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 executed.
+ * This method should return a Deferred which is resolved when start can be
+ * executed.
*
- * @return {jQuery.Deferred}
+ * @returns {Deferred}
*/
willStart: function () {
+ if (this.xmlDependencies) {
+ var defs = _.map(this.xmlDependencies, function (xmlPath) {
+ return ajax.loadXML(xmlPath, core.qweb);
+ });
+ return $.when.apply($, defs);
+ }
return $.when();
},
/**