From bd3d0384fd49ecdf70ca4001e629d0e05d6f5191 Mon Sep 17 00:00:00 2001 From: niv-openerp Date: Wed, 30 Jan 2013 17:15:34 +0100 Subject: [PATCH] [IMP] added mechanism to implement exception handlers bzr revid: nicolas.vanhoren@openerp.com-20130130161534-m81tj4h3dgsoprh3 --- addons/web/static/src/js/chrome.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index bdc1dd4c02c..1407df4d33f 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -247,6 +247,11 @@ instance.web.CrashManager = instance.web.Class.extend({ if (!this.active) { return; } + var handler = instance.web.crash_manager_registry.get_object(error.data.name, true); + if (handler) { + new (handler)(this, error).display(); + return; + }; if (error.data.name === "openerp.addons.web.session SessionExpiredException") { this.show_warning({type: "Session Expired", data: { message: "Your OpenERP session expired. Please refresh the current web page." }}); return; @@ -299,6 +304,29 @@ instance.web.CrashManager = instance.web.Class.extend({ }, }); +/** + An interface to implement to handle exceptions. Register implementation in instance.web.crash_manager_registry. +*/ +instance.web.ExceptionHandler = { + /** + @param parent The parent. + @param error The error object as returned by the JSON-RPC implementation. + */ + init: function(parent, error) {}, + /** + Called to inform to display the widget, if necessary. A typical way would be to implement + this interface in a class extending instance.web.Dialog and simply display the dialog in this + method. + */ + display: function() {}, +}; + +/** + The registry to handle exceptions. It associate a fully qualified python exception name with a class implementing + instance.web.ExceptionHandler. +*/ +instance.web.crash_manager_registry = new instance.web.Registry(); + instance.web.Loading = instance.web.Widget.extend({ template: _t("Loading"), init: function(parent) {