From 7ad14bd00c2c2315b959bd231e6df7c1fd2c70d3 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 | 88 ++-- 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 | 11 + web_dialog_size/readme/DESCRIPTION.rst | 3 + web_dialog_size/static/description/index.html | 436 ++++++++++++++++++ .../static/src/js/web_dialog_size.js | 15 +- 10 files changed, 537 insertions(+), 44 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 create mode 100644 web_dialog_size/static/description/index.html diff --git a/web_dialog_size/README.rst b/web_dialog_size/README.rst index 6cc0acf8..440f0633 100644 --- a/web_dialog_size/README.rst +++ b/web_dialog_size/README.rst @@ -1,67 +1,89 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: https://www.gnu.org/licenses/agpl - :alt: License: AGPL-3 - -============= -Expand Dialog -============= +=============== +Web Dialog Size +=============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/11.0/web_dialog_size + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-11-0/web-11-0-web_dialog_size + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/11.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| 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 -============= +in the upper right corner (imitating most windows managers). +It also adds draggable support to the dialogs. -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`. +**Table of contents** -.. 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 +.. contents:: + :local: 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. +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* ACSONE SA/NV +* Therp BV +* Siddharth Bhalgami +* Tecnativa +* Amaris Contributors ------------- +~~~~~~~~~~~~ * Anthony Muschang * Stéphane Bidoul -* Pedro M. Baeza * Holger Brunn * Siddharth Bhalgami * Wolfgang Pichler * David Vidal * Quentin Theuret +* `Tecnativa `_: -Do not contact contributors directly about support or help with technical issues. + * Pedro M. Baeza + * Jairo Llopis -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_dialog_size/__init__.py b/web_dialog_size/__init__.py index 2b46a37e..0650744f 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 3b032fe7..4e799d1a 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 00000000..bd3aa9f1 --- /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 00000000..bc916db0 --- /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 00000000..18b1ad07 --- /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 00000000..0641b1d1 --- /dev/null +++ b/web_dialog_size/readme/CONTRIBUTORS.rst @@ -0,0 +1,11 @@ +* 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 00000000..398e72f5 --- /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/description/index.html b/web_dialog_size/static/description/index.html new file mode 100644 index 00000000..ce5afa56 --- /dev/null +++ b/web_dialog_size/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +Web Dialog Size + + + +
+

Web Dialog Size

+ + +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

+

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.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
  • Therp BV
  • +
  • Siddharth Bhalgami
  • +
  • Tecnativa
  • +
  • Amaris
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + 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 4aa412f4..4ec94246 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; },