From 78f651a06e5799878cde5b23d30400a903adcd7b Mon Sep 17 00:00:00 2001 From: Carlos Roca Date: Thu, 9 Mar 2023 16:22:06 +0100 Subject: [PATCH 01/10] [ADD] website_form_require_legal: New module to add terms acceptance at website form level --- website_form_require_legal/README.rst | 95 ++++ website_form_require_legal/__init__.py | 0 website_form_require_legal/__manifest__.py | 23 + website_form_require_legal/i18n/es.po | 44 ++ .../i18n/website_form_require_legal.pot | 42 ++ .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + website_form_require_legal/readme/ROADMAP.rst | 2 + website_form_require_legal/readme/USAGE.rst | 10 + .../static/description/index.html | 442 ++++++++++++++++++ .../static/src/js/options.js | 60 +++ .../static/src/scss/website_form_legal.scss | 8 + .../static/src/xml/website_form_editor.xml | 31 ++ website_form_require_legal/views/snippets.xml | 15 + 14 files changed, 776 insertions(+) create mode 100644 website_form_require_legal/README.rst create mode 100644 website_form_require_legal/__init__.py create mode 100644 website_form_require_legal/__manifest__.py create mode 100644 website_form_require_legal/i18n/es.po create mode 100644 website_form_require_legal/i18n/website_form_require_legal.pot create mode 100644 website_form_require_legal/readme/CONTRIBUTORS.rst create mode 100644 website_form_require_legal/readme/DESCRIPTION.rst create mode 100644 website_form_require_legal/readme/ROADMAP.rst create mode 100644 website_form_require_legal/readme/USAGE.rst create mode 100644 website_form_require_legal/static/description/index.html create mode 100644 website_form_require_legal/static/src/js/options.js create mode 100644 website_form_require_legal/static/src/scss/website_form_legal.scss create mode 100644 website_form_require_legal/static/src/xml/website_form_editor.xml create mode 100644 website_form_require_legal/views/snippets.xml diff --git a/website_form_require_legal/README.rst b/website_form_require_legal/README.rst new file mode 100644 index 0000000000..7592c0d0d2 --- /dev/null +++ b/website_form_require_legal/README.rst @@ -0,0 +1,95 @@ +========================== +Website Form Require Legal +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github + :target: https://github.com/OCA/website/tree/13.0/website_form_require_legal + :alt: OCA/website +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/website-13-0/website-13-0-website_form_require_legal + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/website&target_branch=13.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds the possibility to require confirm legal terms at frontend forms. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +* Edit any page in your website. +* Add a form from the snippets. +* Modify the parameters. +* You will find the option "Legal terms acceptance". +* If you select it you will be able to modify the text shown and the link to the + page from the text editor. + +Note: Remember to change the terms and conditions link to redirect to the desired page. + +Known issues / Roadmap +====================== + +This module is aimed to deprecate website_crm_privacy_policy and modules similar to this +one. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `__: + + * Carlos Roca + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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/website `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_form_require_legal/__init__.py b/website_form_require_legal/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_form_require_legal/__manifest__.py b/website_form_require_legal/__manifest__.py new file mode 100644 index 0000000000..046fad6835 --- /dev/null +++ b/website_form_require_legal/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2023 Tecnativa - Carlos Roca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). +{ + "name": "Website Form Require Legal", + "summary": "Add possibility to require confirm legal terms.", + "version": "15.0.1.0.0", + "category": "Website", + "license": "LGPL-3", + "website": "https://github.com/OCA/website", + "author": "Tecnativa, Odoo Community Association (OCA)", + "application": False, + "installable": True, + "depends": ["website"], + "data": ["views/snippets.xml"], + "assets": { + "website.assets_wysiwyg": [ + "website_form_require_legal/static/src/js/options.js" + ], + "web.assets_frontend": [ + "website_form_require_legal/static/src/scss/website_form_legal.scss" + ], + }, +} diff --git a/website_form_require_legal/i18n/es.po b/website_form_require_legal/i18n/es.po new file mode 100644 index 0000000000..908f80b19a --- /dev/null +++ b/website_form_require_legal/i18n/es.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_form_require_legal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-03-09 15:06+0000\n" +"PO-Revision-Date: 2023-03-09 16:09+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.2.2\n" + +#. module: website_form_require_legal +#. openerp-web +#: code:addons/website_form_require_legal/static/src/xml/website_form_editor.xml:0 +#, python-format +msgid "Agree to" +msgstr "Aceptar los" + +#. module: website_form_require_legal +#: model_terms:ir.ui.view,arch_db:website_form_require_legal.s_website_form_options +msgid "Legal terms acceptance" +msgstr "Aceptación de los términos legales" + +#. module: website_form_require_legal +#. openerp-web +#: code:addons/website_form_require_legal/static/src/xml/website_form_editor.xml:0 +#, python-format +msgid "You must agree before submitting." +msgstr "Debe estar de acuerdo antes de enviarlo." + +#. module: website_form_require_legal +#. openerp-web +#: code:addons/website_form_require_legal/static/src/xml/website_form_editor.xml:0 +#, python-format +msgid "terms and conditions" +msgstr "términos y condiciones" diff --git a/website_form_require_legal/i18n/website_form_require_legal.pot b/website_form_require_legal/i18n/website_form_require_legal.pot new file mode 100644 index 0000000000..5c047bc8c6 --- /dev/null +++ b/website_form_require_legal/i18n/website_form_require_legal.pot @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_form_require_legal +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-03-09 15:06+0000\n" +"PO-Revision-Date: 2023-03-09 15:06+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: website_form_require_legal +#. openerp-web +#: code:addons/website_form_require_legal/static/src/xml/website_form_editor.xml:0 +#, python-format +msgid "Agree to" +msgstr "" + +#. module: website_form_require_legal +#: model_terms:ir.ui.view,arch_db:website_form_require_legal.s_website_form_options +msgid "Legal terms acceptance" +msgstr "" + +#. module: website_form_require_legal +#. openerp-web +#: code:addons/website_form_require_legal/static/src/xml/website_form_editor.xml:0 +#, python-format +msgid "You must agree before submitting." +msgstr "" + +#. module: website_form_require_legal +#. openerp-web +#: code:addons/website_form_require_legal/static/src/xml/website_form_editor.xml:0 +#, python-format +msgid "terms and conditions" +msgstr "" diff --git a/website_form_require_legal/readme/CONTRIBUTORS.rst b/website_form_require_legal/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..4228f4196a --- /dev/null +++ b/website_form_require_legal/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `__: + + * Carlos Roca diff --git a/website_form_require_legal/readme/DESCRIPTION.rst b/website_form_require_legal/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..29b28abf98 --- /dev/null +++ b/website_form_require_legal/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module adds the possibility to require confirm legal terms at frontend forms. diff --git a/website_form_require_legal/readme/ROADMAP.rst b/website_form_require_legal/readme/ROADMAP.rst new file mode 100644 index 0000000000..916f2a2498 --- /dev/null +++ b/website_form_require_legal/readme/ROADMAP.rst @@ -0,0 +1,2 @@ +This module is aimed to deprecate website_crm_privacy_policy and modules similar to this +one. diff --git a/website_form_require_legal/readme/USAGE.rst b/website_form_require_legal/readme/USAGE.rst new file mode 100644 index 0000000000..31ccfafe5e --- /dev/null +++ b/website_form_require_legal/readme/USAGE.rst @@ -0,0 +1,10 @@ +To use this module, you need to: + +* Edit any page in your website. +* Add a form from the snippets. +* Modify the parameters. +* You will find the option "Legal terms acceptance". +* If you select it you will be able to modify the text shown and the link to the + page from the text editor. + +Note: Remember to change the terms and conditions link to redirect to the desired page. diff --git a/website_form_require_legal/static/description/index.html b/website_form_require_legal/static/description/index.html new file mode 100644 index 0000000000..343165eff0 --- /dev/null +++ b/website_form_require_legal/static/description/index.html @@ -0,0 +1,442 @@ + + + + + + +Website Form Require Legal + + + + + + diff --git a/website_form_require_legal/static/src/js/options.js b/website_form_require_legal/static/src/js/options.js new file mode 100644 index 0000000000..1b66d2902c --- /dev/null +++ b/website_form_require_legal/static/src/js/options.js @@ -0,0 +1,60 @@ +odoo.define("website_form_require_legal.form_editor", function (require) { + "use strict"; + + const core = require("web.core"); + const options = require("web_editor.snippets.options"); + require("website.editor.snippets.options"); + + const qweb = core.qweb; + const WebsiteFormEditor = options.registry.WebsiteFormEditor; + + WebsiteFormEditor.include({ + xmlDependencies: (WebsiteFormEditor.prototype.xmlDependencies || []).concat([ + "/website_form_require_legal/static/src/xml/website_form_editor.xml", + ]), + /** + * @override + */ + start: function () { + const proms = [this._super(...arguments)]; + this.$target.find(".s_website_form_legal").attr("contentEditable", true); + return Promise.all(proms); + }, + /** + * Toggle the legal terms checkbox + */ + toggleLegalTerms: function () { + const legalTermsEl = this.$target[0].querySelector(".s_website_form_legal"); + if (legalTermsEl) { + legalTermsEl.remove(); + } else { + const template = document.createElement("template"); + const labelWidth = this.$target[0].querySelector( + ".s_website_form_label" + ).style.width; + $(template).html( + qweb.render("website_form_require_legal.s_website_form_legal", { + labelWidth: labelWidth, + termsURL: "terms", + }) + ); + const legal = template.content.firstElementChild; + legal.setAttribute("contentEditable", true); + if (this.$target.find(".s_website_form_recaptcha").length) { + this.$target.find(".s_website_form_recaptcha")[0].before(legal); + } else { + this.$target.find(".s_website_form_submit").before(legal); + } + } + }, + /** + * @override + */ + _computeWidgetState: function (methodName) { + if (methodName === "toggleLegalTerms") { + return !this.$target[0].querySelector(".s_website_form_legal") || ""; + } + return this._super(...arguments); + }, + }); +}); diff --git a/website_form_require_legal/static/src/scss/website_form_legal.scss b/website_form_require_legal/static/src/scss/website_form_legal.scss new file mode 100644 index 0000000000..f4e5f8863a --- /dev/null +++ b/website_form_require_legal/static/src/scss/website_form_legal.scss @@ -0,0 +1,8 @@ +.s_website_form[data-vcss="001"] { + .s_website_form_legal { + .s_website_form_label { + float: left; + height: 1px; + } + } +} diff --git a/website_form_require_legal/static/src/xml/website_form_editor.xml b/website_form_require_legal/static/src/xml/website_form_editor.xml new file mode 100644 index 0000000000..4771263cea --- /dev/null +++ b/website_form_require_legal/static/src/xml/website_form_editor.xml @@ -0,0 +1,31 @@ + + + +