[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.
This commit is contained in:
@@ -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;
|
||||
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -74,5 +74,5 @@ translator.Class.include({
|
||||
});
|
||||
|
||||
$(function () {
|
||||
odoo.init();
|
||||
_.delay(odoo.init, 500);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user