From 10bd9f1aee190f34391775e2c119e5f289d64fa8 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Mon, 19 Dec 2011 17:14:41 +0100 Subject: [PATCH] [imp] implemented synchronized mode to be used in the o2m bzr revid: nicolas.vanhoren@openerp.com-20111219161441-1117wec0btanqii2 --- addons/web/static/src/js/core.js | 24 ++++++++++++++- addons/web/static/src/js/view_form.js | 42 +++++++++++++-------------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index 3bbf94379cf..bb3c209a8c3 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -462,6 +462,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. data: JSON.stringify(payload), processData: false, }, url); + if (this.synch) + ajax.async = false; return $.ajax(ajax); }, rpc_jsonp: function(url, payload) { @@ -479,6 +481,8 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. cache: false, data: data }, url); + if (this.synch) + ajax.async = false; var payload_str = JSON.stringify(payload); var payload_url = $.param({r:payload_str}); if(payload_url.length < 2000) { @@ -805,7 +809,16 @@ openerp.web.Connection = openerp.web.CallbackEnabled.extend( /** @lends openerp. } }; timer = setTimeout(waitLoop, CHECK_INTERVAL); - } + }, + synchronized_mode: function(to_execute) { + var synch = this.synch; + this.synch = true; + try { + return to_execute(); + } finally { + this.synch = synch; + } + }, }); /** @@ -1220,6 +1233,15 @@ $.async_when = function() { return def; }; +// special tweak for the web client +var old_async_when = $.async_when; +$.async_when = function() { + if (openerp.connection.synch) + return $.when.apply(this, arguments); + else + return old_async_when.apply(this, arguments); +}; + }; // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 34bfe15bd4c..2bc6f13a741 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -2221,27 +2221,27 @@ openerp.web.form.FieldOne2Many = openerp.web.form.Field.extend({ return commands['delete'](x.id);})); }, save_any_view: function() { - if (this.viewmanager && this.viewmanager.views && this.viewmanager.active_view && - this.viewmanager.views[this.viewmanager.active_view] && - this.viewmanager.views[this.viewmanager.active_view].controller) { - var view = this.viewmanager.views[this.viewmanager.active_view].controller; - if (this.viewmanager.active_view === "form") { - var res = $.when(view.do_save()); - // it seems line there are some cases when this happens - /*if (!res.isResolved() && !res.isRejected()) { - console.warn("Asynchronous get_value() is not supported in form view."); - }*/ - return res; - } else if (this.viewmanager.active_view === "list") { - var res = $.when(view.ensure_saved()); - // it seems line there are some cases when this happens - /*if (!res.isResolved() && !res.isRejected()) { - console.warn("Asynchronous get_value() is not supported in list view."); - }*/ - return res; - } - } - return false; + return this.session.synchronized_mode(_.bind(function() { + if (this.viewmanager && this.viewmanager.views && this.viewmanager.active_view && + this.viewmanager.views[this.viewmanager.active_view] && + this.viewmanager.views[this.viewmanager.active_view].controller) { + var view = this.viewmanager.views[this.viewmanager.active_view].controller; + if (this.viewmanager.active_view === "form") { + var res = $.when(view.do_save()); + if (!res.isResolved() && !res.isRejected()) { + console.warn("Asynchronous get_value() is not supported in form view."); + } + return res; + } else if (this.viewmanager.active_view === "list") { + var res = $.when(view.ensure_saved()); + if (!res.isResolved() && !res.isRejected()) { + console.warn("Asynchronous get_value() is not supported in list view."); + } + return res; + } + } + return false; + }, this)); }, is_valid: function() { this.validate();