From 239cc13fffd369ffa7aa081549100345fda9ffbf Mon Sep 17 00:00:00 2001 From: Damien Crier Date: Mon, 8 Jun 2015 10:58:59 +0200 Subject: [PATCH] [FIX] rename controller [IMP] launch openerp.web.Dialog instead of an alert() --- web_warning_on_save/README.rst | 4 +- web_warning_on_save/controller.py | 6 +-- .../static/src/js/web_warning_on_save.js | 39 +++++++++++-------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/web_warning_on_save/README.rst b/web_warning_on_save/README.rst index b35968aa..611f2756 100644 --- a/web_warning_on_save/README.rst +++ b/web_warning_on_save/README.rst @@ -1,8 +1,8 @@ .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg :alt: License: AGPL-3 -web_warning_on_save -=========== +Raise warning when saving +========================= This module was written to extend the functionality of saving a record in the web interface. /!\/!\/!\ In no way this module stops the save of the record. You must consider this as a warning displayed diff --git a/web_warning_on_save/controller.py b/web_warning_on_save/controller.py index fbd48584..9680e33d 100644 --- a/web_warning_on_save/controller.py +++ b/web_warning_on_save/controller.py @@ -23,7 +23,7 @@ import openerp class WarningOnSaveController(openerp.addons.web.http.Controller): - _cp_path = "/web/warning_on_save" + _cp_path = "/web_warning_on_save" @openerp.addons.web.http.jsonrequest def check_warning_on_save(self, req, model, id): @@ -32,8 +32,8 @@ class WarningOnSaveController(openerp.addons.web.http.Controller): if method does not exist in the model, do nothing """ m = req.session.model(model) - try: + if hasattr(m, 'check_warning_on_save'): return getattr(m, 'check_warning_on_save')(id, req.context) - except: + else: return False diff --git a/web_warning_on_save/static/src/js/web_warning_on_save.js b/web_warning_on_save/static/src/js/web_warning_on_save.js index acbd5e3b..7f91baf6 100644 --- a/web_warning_on_save/static/src/js/web_warning_on_save.js +++ b/web_warning_on_save/static/src/js/web_warning_on_save.js @@ -1,23 +1,28 @@ openerp.web_warning_on_save = function (instance) { - instance.web.FormView.include({ - on_button_save: function(e) { + instance.web.FormView.include({ + on_button_save: function(e) { // inherit method to be able to display an alert if // method called returns a string - var id = 0; - var self = this; - self._super.apply(this, arguments).done(function(id){ - var model = self.model; - var param = {'model': model, - 'id': self.datarecord.id ? self.datarecord.id : id}; - self.rpc('/web/warning_on_save/check_warning_on_save', param) - .done(function(res) { - if (res != false){ - alert(res); - } - }); - }) - }, - }); + var self = this; + return self._super.apply(this, arguments).done(function(id){ + var model = self.model; + var param = { + 'model': model, + 'id': self.datarecord.id ? self.datarecord.id : id + }; + self.rpc('/web_warning_on_save/check_warning_on_save', param) + .done(function(res) { + if (res != false){ + var dialog = new instance.web.Dialog(this, { + title: _t("Warning"), + width: 850, + }).open(); + dialog.$el.html(res); + } + }); + }) + }, + }); };