summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src/js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2015-07-17 15:34:31 +0200
committerChristophe Matthieu <chm@odoo.com>2015-07-22 12:15:24 +0200
commit71732dceb6613dab28d6eef96fa155acc91af7ce (patch)
tree1f33280ca569fd23912a640a79ec8d878d934bfc /addons/web_editor/static/src/js
parentdfad968515b523ebc900a0ba0fa1b111626f6149 (diff)
[IMP] web: module can be asynchronous loaded if it return a deferred
Each module can return a deferred. In that case, the module is marked as loaded only when the deferred is resolved, and its value is equal to the resolved value. The module can be rejected (unloaded). This will be logged in the console as info. Remove if_dom_contains from the website, the modules return a rejected deferred if the DOM doesn't contains the seleted values.
Diffstat (limited to 'addons/web_editor/static/src/js')
-rw-r--r--addons/web_editor/static/src/js/base.js26
-rw-r--r--addons/web_editor/static/src/js/editor.js2
-rw-r--r--addons/web_editor/static/src/js/iframe.js2
3 files changed, 11 insertions, 19 deletions
diff --git a/addons/web_editor/static/src/js/base.js b/addons/web_editor/static/src/js/base.js
index 7046332289a..4d8d128f60c 100644
--- a/addons/web_editor/static/src/js/base.js
+++ b/addons/web_editor/static/src/js/base.js
@@ -6,8 +6,6 @@ var ajax = require('web.ajax');
var qweb = core.qweb;
var _t = core._t;
-//////////////////////////////////////////////////////////////////////////////////////////////////////////
-
var get_context = function (dict) {
var html = document.documentElement;
return _.extend({
@@ -16,20 +14,23 @@ var get_context = function (dict) {
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////
-/* ----------------------------------------------------
- Async Ready and Template loading
- ---------------------------------------------------- */
+
+var data = {
+ 'get_context': get_context,
+ 'url_translations': '/web/webclient/translations',
+};
+
var dom_ready = $.Deferred();
$(document).ready(function () {
- dom_ready.resolve();
+ dom_ready.resolve(data);
// fix for ie
if($.fn.placeholder) $('input, textarea').placeholder();
});
-
+data.dom_ready = dom_ready;
// todo: remove and load a bundle of translated templates
var all_ready;
-var ready = function() {
+data.ready = function() {
if (!all_ready) {
all_ready = $.when(dom_ready, ajax.loadXML()).then(translations);
} else if(all_ready.state() === "resolved") { // can add async template
@@ -63,13 +64,6 @@ function translations() {
}
}).promise();
}
-
-var data = {
- 'get_context': get_context,
- 'url_translations': '/web/webclient/translations',
- 'dom_ready': dom_ready,
- 'ready': ready,
-};
-return data;
+return dom_ready;
});
diff --git a/addons/web_editor/static/src/js/editor.js b/addons/web_editor/static/src/js/editor.js
index 2958d045d0f..f9255716697 100644
--- a/addons/web_editor/static/src/js/editor.js
+++ b/addons/web_editor/static/src/js/editor.js
@@ -19,7 +19,6 @@ editor.editable = !!$('html').data('editable');
ajax.loadXML('/web_editor/static/src/xml/editor.xml', qweb);
-base.dom_ready.done(function () {
$(document).on('click', '.note-editable', function (ev) {
ev.preventDefault();
});
@@ -37,7 +36,6 @@ base.dom_ready.done(function () {
ev.preventDefault();
}
});
-});
//////////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/addons/web_editor/static/src/js/iframe.js b/addons/web_editor/static/src/js/iframe.js
index 8b287064b7c..553c68b30af 100644
--- a/addons/web_editor/static/src/js/iframe.js
+++ b/addons/web_editor/static/src/js/iframe.js
@@ -74,5 +74,5 @@ translator.Class.include({
});
$(function () {
- odoo.init();
+ _.delay(odoo.init, 500);
});