Browse Source

[FIX] rename controller

[IMP] launch openerp.web.Dialog instead of an alert()
pull/144/head
Damien Crier 10 years ago
parent
commit
239cc13fff
  1. 4
      web_warning_on_save/README.rst
  2. 6
      web_warning_on_save/controller.py
  3. 17
      web_warning_on_save/static/src/js/web_warning_on_save.js

4
web_warning_on_save/README.rst

@ -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

6
web_warning_on_save/controller.py

@ -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

17
web_warning_on_save/static/src/js/web_warning_on_save.js

@ -4,16 +4,21 @@ openerp.web_warning_on_save = function (instance) {
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;
self._super.apply(this, arguments).done(function(id){
return self._super.apply(this, arguments).done(function(id){
var model = self.model; 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)
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) { .done(function(res) {
if (res != false){ if (res != false){
alert(res);
var dialog = new instance.web.Dialog(this, {
title: _t("Warning"),
width: 850,
}).open();
dialog.$el.html(res);
} }
}); });
}) })

Loading…
Cancel
Save