diff options
| author | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-02-27 15:20:21 +0100 |
|---|---|---|
| committer | niv-openerp <nicolas.vanhoren@openerp.com> | 2013-02-27 15:20:21 +0100 |
| commit | d04d532201122de59467fcb10d4bab9e645b56b6 (patch) | |
| tree | 9ba7a31e432489405160db1ca7c9ae6224962d63 /addons/web/static/src/js/corelib.js | |
| parent | 6bc2c8f25365eda664bc5b59b8474d17fbe03136 (diff) | |
| parent | 5c3eebcb4dc2b27cfb686573888728bb10ba0c88 (diff) | |
[MERGE] some others fixes from 7.0
bzr revid: nicolas.vanhoren@openerp.com-20130227141209-kemu3v78npynip87
bzr revid: nicolas.vanhoren@openerp.com-20130227142021-oc8i22kpfgmgv9jh
Diffstat (limited to 'addons/web/static/src/js/corelib.js')
| -rw-r--r-- | addons/web/static/src/js/corelib.js | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index edd23e14522..63e22672bd7 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -229,6 +229,38 @@ instance.web.ParentedMixin = { return this.__parentedDestroyed; }, /** + Utility method to only execute asynchronous actions if the current + object has not been destroyed. + + @param {Promise} promise The promise representing the asynchronous action. + @param {bool} reject Defaults to false. If true, the returned promise will be + rejected with no arguments if the current object is destroyed. If false, + the returned promise will never be resolved nor rejected. + @returns {Promise} A promise that will mirror the given promise if everything goes + fine but will either be rejected with no arguments or never resolved if the + current object is destroyed. + */ + alive: function(promise, reject) { + var def = $.Deferred(); + var self = this; + promise.done(function() { + if (! self.isDestroyed()) { + if (! reject) + def.resolve.apply(def, arguments); + else + def.reject(); + } + }).fail(function() { + if (! self.isDestroyed()) { + if (! reject) + def.reject.apply(def, arguments); + else + def.reject(); + } + }); + return def.promise(); + }, + /** * Inform the object it should destroy itself, releasing any * resource it could have reserved. */ @@ -495,16 +527,7 @@ instance.web.Controller = instance.web.Class.extend(instance.web.PropertiesMixin return false; }, rpc: function(url, data, options) { - var def = $.Deferred(); - var self = this; - instance.session.rpc(url, data, options).done(function() { - if (!self.isDestroyed()) - def.resolve.apply(def, arguments); - }).fail(function() { - if (!self.isDestroyed()) - def.reject.apply(def, arguments); - }); - return def.promise(); + return this.alive(instance.session.rpc(url, data, options)); } }); |
