[imp] implemented synchronized mode to be used in the o2m
bzr revid: nicolas.vanhoren@openerp.com-20111219161441-1117wec0btanqii2
This commit is contained in:
parent
95a3f10905
commit
10bd9f1aee
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue