From 2810ad33f354dc87489a24174e4fc57734518f5c Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Wed, 13 Jun 2018 08:54:46 +0200 Subject: [PATCH] [FIX] web_dialog_size: Fix usage for non-admins and reduce calls (#954) This addon had 2 problems after migrating to v11: 1. One call to backend's `ir.config_parameter.get_param` was done for each instantiated dialog, while the setting served for the whole session equally. 2. That model is now readable only by admin users, so non-admins couldn't use the default at all. Fixed now. --- web_dialog_size/README.rst | 67 ------------------- web_dialog_size/__init__.py | 3 +- web_dialog_size/__manifest__.py | 4 +- web_dialog_size/models/__init__.py | 1 + web_dialog_size/models/ir_config_parameter.py | 17 +++++ web_dialog_size/readme/CONFIGURATION.rst | 3 + web_dialog_size/readme/CONTRIBUTORS.rst | 14 ++++ web_dialog_size/readme/DESCRIPTION.rst | 3 + .../static/src/js/web_dialog_size.js | 15 +++-- 9 files changed, 49 insertions(+), 78 deletions(-) create mode 100644 web_dialog_size/models/__init__.py create mode 100644 web_dialog_size/models/ir_config_parameter.py create mode 100644 web_dialog_size/readme/CONFIGURATION.rst create mode 100644 web_dialog_size/readme/CONTRIBUTORS.rst create mode 100644 web_dialog_size/readme/DESCRIPTION.rst diff --git a/web_dialog_size/README.rst b/web_dialog_size/README.rst index 6cc0acf8d..e69de29bb 100644 --- a/web_dialog_size/README.rst +++ b/web_dialog_size/README.rst @@ -1,67 +0,0 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: https://www.gnu.org/licenses/agpl - :alt: License: AGPL-3 - -============= -Expand Dialog -============= - -A module that lets the user expand/restore the dialog box size through a button -in the upper right corner (mimicking most windows managers). -It does also add draggable support to the dialogs. - -Configuration -============= - -By default, the module respects the caller's `dialog_size` option. If you want -to override this and have all dialogs maximized by default, set the configuration -parameter `web_dialog_size.default_maximize` to `1`. - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/162/11.0 - -Bug Tracker -=========== - -Bugs are tracked on `GitHub Issues -`_. In case of trouble, please -check there if your issue has already been reported. If you spotted it first, -help us smash it by providing detailed and welcomed feedback. - -Credits -======= - -Images ------- - -* Odoo Community Association: `Icon `_. - -Contributors ------------- - -* Anthony Muschang -* Stéphane Bidoul -* Pedro M. Baeza -* Holger Brunn -* Siddharth Bhalgami -* Wolfgang Pichler -* David Vidal -* Quentin Theuret - -Do not contact contributors directly about support or help with technical issues. - -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 https://odoo-community.org. diff --git a/web_dialog_size/__init__.py b/web_dialog_size/__init__.py index 2b46a37e4..0650744f6 100644 --- a/web_dialog_size/__init__.py +++ b/web_dialog_size/__init__.py @@ -1,2 +1 @@ -# Copyright 2018 Quentin Theuret -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). \ No newline at end of file +from . import models diff --git a/web_dialog_size/__manifest__.py b/web_dialog_size/__manifest__.py index 3b032fe7f..4e799d1a5 100644 --- a/web_dialog_size/__manifest__.py +++ b/web_dialog_size/__manifest__.py @@ -13,9 +13,9 @@ "Tecnativa, " "Amaris, " "Odoo Community Association (OCA)", - 'website': "http://acsone.eu", + 'website': "http://github.com/OCA/web", 'category': 'web', - 'version': '11.0.1.0.2', + 'version': '11.0.1.0.3', 'license': 'AGPL-3', 'depends': [ 'web', diff --git a/web_dialog_size/models/__init__.py b/web_dialog_size/models/__init__.py new file mode 100644 index 000000000..bd3aa9f10 --- /dev/null +++ b/web_dialog_size/models/__init__.py @@ -0,0 +1 @@ +from . import ir_config_parameter diff --git a/web_dialog_size/models/ir_config_parameter.py b/web_dialog_size/models/ir_config_parameter.py new file mode 100644 index 000000000..bc916db00 --- /dev/null +++ b/web_dialog_size/models/ir_config_parameter.py @@ -0,0 +1,17 @@ +# Copyright 2018 Tecnativa - Jairo Llopis +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.models import api, Model +from odoo.tools.safe_eval import const_eval + + +class IrConfigParameter(Model): + _inherit = "ir.config_parameter" + + @api.model + def get_web_dialog_size_config(self): + get_param = self.sudo().get_param + return { + key: const_eval(get_param("web_dialog_size.%s" % key, "False")) + for key in ["default_maximize"] + } diff --git a/web_dialog_size/readme/CONFIGURATION.rst b/web_dialog_size/readme/CONFIGURATION.rst new file mode 100644 index 000000000..18b1ad078 --- /dev/null +++ b/web_dialog_size/readme/CONFIGURATION.rst @@ -0,0 +1,3 @@ +By default, the module respects the caller's ``dialog_size`` option. +If you want to override this and have all dialogs maximized by default, +set the configuration parameter ``web_dialog_size.default_maximize`` to ``1``. diff --git a/web_dialog_size/readme/CONTRIBUTORS.rst b/web_dialog_size/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..5e891187c --- /dev/null +++ b/web_dialog_size/readme/CONTRIBUTORS.rst @@ -0,0 +1,14 @@ +Contributors +------------ + +* Anthony Muschang +* Stéphane Bidoul +* Holger Brunn +* Siddharth Bhalgami +* Wolfgang Pichler +* David Vidal +* Quentin Theuret +* `Tecnativa `_: + + * Pedro M. Baeza + * Jairo Llopis diff --git a/web_dialog_size/readme/DESCRIPTION.rst b/web_dialog_size/readme/DESCRIPTION.rst new file mode 100644 index 000000000..398e72f50 --- /dev/null +++ b/web_dialog_size/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +A module that lets the user expand/restore the dialog box size through a button +in the upper right corner (imitating most windows managers). +It also adds draggable support to the dialogs. diff --git a/web_dialog_size/static/src/js/web_dialog_size.js b/web_dialog_size/static/src/js/web_dialog_size.js index 4aa412f4b..4ec942464 100644 --- a/web_dialog_size/static/src/js/web_dialog_size.js +++ b/web_dialog_size/static/src/js/web_dialog_size.js @@ -4,6 +4,11 @@ odoo.define('web_dialog_size.web_dialog_size', function (require) { var rpc = require('web.rpc'); var Dialog = require('web.Dialog'); +var config = rpc.query({ + model: 'ir.config_parameter', + method: 'get_web_dialog_size_config', +}); + Dialog.include({ willStart: function () { @@ -11,12 +16,8 @@ Dialog.include({ return this._super.apply(this, arguments).then(function () { self.$modal.find('.dialog_button_extend').on('click', self.proxy('_extending')); self.$modal.find('.dialog_button_restore').on('click', self.proxy('_restore')); - return rpc.query({ - model: 'ir.config_parameter', - method: 'get_param', - args: ['web_dialog_size.default_maximize',], - }).then(function(default_maximize) { - if (default_maximize === "True" || default_maximize === 1) { + return config.done(function(default_maximize) { + if (default_maximize) { self._extending(); } else { self._restore(); @@ -32,7 +33,7 @@ Dialog.include({ handle: '.modal-header', helper: false }); - }; + } return this; },