3
0
Fork 0

[FIX] rename controller

[IMP] launch openerp.web.Dialog instead of an alert()
7.0
Damien Crier 2015-06-08 10:58:59 +02:00
parent a5dfee75b6
commit 239cc13fff
3 changed files with 27 additions and 22 deletions

View File

@ -1,8 +1,8 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg .. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3 :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. 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 /!\/!\/!\ In no way this module stops the save of the record. You must consider this as a warning displayed

View File

@ -23,7 +23,7 @@ import openerp
class WarningOnSaveController(openerp.addons.web.http.Controller): class WarningOnSaveController(openerp.addons.web.http.Controller):
_cp_path = "/web/warning_on_save" _cp_path = "/web_warning_on_save"
@openerp.addons.web.http.jsonrequest @openerp.addons.web.http.jsonrequest
def check_warning_on_save(self, req, model, id): 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 if method does not exist in the model, do nothing
""" """
m = req.session.model(model) m = req.session.model(model)
try: if hasattr(m, 'check_warning_on_save'):
return getattr(m, 'check_warning_on_save')(id, req.context) return getattr(m, 'check_warning_on_save')(id, req.context)
except: else:
return False return False

View File

@ -1,23 +1,28 @@
openerp.web_warning_on_save = function (instance) { openerp.web_warning_on_save = function (instance) {
instance.web.FormView.include({ instance.web.FormView.include({
on_button_save: function(e) { on_button_save: function(e) {
// inherit method to be able to display an alert if // inherit method to be able to display an alert if
// method called returns a string // method called returns a string
var id = 0; var self = this;
var self = this; return self._super.apply(this, arguments).done(function(id){
self._super.apply(this, arguments).done(function(id){ var model = self.model;
var model = self.model; var param = {
var param = {'model': model, 'model': model,
'id': self.datarecord.id ? self.datarecord.id : id}; 'id': self.datarecord.id ? self.datarecord.id : id
self.rpc('/web/warning_on_save/check_warning_on_save', param) };
.done(function(res) { self.rpc('/web_warning_on_save/check_warning_on_save', param)
if (res != false){ .done(function(res) {
alert(res); if (res != false){
} var dialog = new instance.web.Dialog(this, {
}); title: _t("Warning"),
}) width: 850,
}, }).open();
}); dialog.$el.html(res);
}
});
})
},
});
}; };