Browse Source

[ADD] add module 'web_warning_on_save'

pull/144/head
Damien Crier 10 years ago
parent
commit
392f0ef14a
  1. 86
      web_warning_on_save/README.rst
  2. 22
      web_warning_on_save/__init__.py
  3. 40
      web_warning_on_save/__openerp__.py
  4. 39
      web_warning_on_save/controller.py
  5. 28
      web_warning_on_save/static/src/js/web_warning_on_save.js

86
web_warning_on_save/README.rst

@ -0,0 +1,86 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
Module name
===========
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
to the user AFTER save completed. /!\/!\/!\
Installation
============
To install this module, you need to:
* install it
Configuration
=============
To configure this module, you need to:
* nothing
Usage
=====
To use this module, you need to:
* write a method called 'check_warning_on_save' which will make some checks and return a string
example :
def check_warning_on_save(self, cr, uid, id, context=None):
"""
@param: int: record_id
@return: string: message that should be displayed to the user
"""
res = ""
record = self.browse(cr, uid, id, context=context)
# ... make some checks
return res
For further information, please visit:
* https://www.odoo.com/forum/help-1
Known issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/{project_repo}/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/{project_repo}/issues/new?body=module:%20{module_name}%0Aversion:%20{version}%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Damien Crier <damien.crier@camptocamp.com>
* Vincent Renaville <vincent.renaville@camptocamp.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

22
web_warning_on_save/__init__.py

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Damien Crier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import controller

40
web_warning_on_save/__openerp__.py

@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Damien Crier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"name": "Web warning on save",
"version": "1.0",
"depends": ['web'],
"author": "Camptocamp,Odoo Community Association (OCA)",
'license': 'AGPL-3',
'website': 'http://www.camptocamp.com',
'data': [
],
'js': [
'static/src/js/web_warning_on_save.js',
],
'css': [
],
'qweb': [
],
'installable': True,
'auto_install': False,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

39
web_warning_on_save/controller.py

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: Damien Crier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import openerp
class WarningOnSaveController(openerp.addons.web.http.Controller):
_cp_path = "/web/warning_on_save"
@openerp.addons.web.http.jsonrequest
def check_warning_on_save(self, req, model, id):
"""
try to call a method on the model given in parameter
if method does not exist in the model, do nothing
"""
m = req.session.model(model)
try:
return getattr(m, 'check_warning_on_save')(id, req.context)
except:
return False

28
web_warning_on_save/static/src/js/web_warning_on_save.js

@ -0,0 +1,28 @@
openerp.web_warning_on_save = function (instance) {
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};
// try {
self.rpc('/web/warning_on_save/check_warning_on_save', param)
.done(function(res) {
if (res != false){
alert(res);
}
});
// }
// catch(err){
// // nothing
// }
})
},
});
};
Loading…
Cancel
Save