diff --git a/website_mass_mailing_name/README.rst b/website_mass_mailing_name/README.rst new file mode 100644 index 00000000..7a0a47b0 --- /dev/null +++ b/website_mass_mailing_name/README.rst @@ -0,0 +1,67 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=========================================== +Mass Mailing Subscription Snippet With Name +=========================================== + +This module extends the functionality of mass mailings to support asking for +the contact name directly in the subscription snippet. + +If you want to get partners created automatically and linked to the contacts, +you can additionally install the `mass_mailing_partner +`_ module. + +Usage +===== + +To use this module, you need to: + +#. Go to any website page. +#. Insert any structure block. +#. Insert the *Newsletter* block as you would usually, inside a structure one. +#. Choose the newsletter of your liking. +#. Press *Save*. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/186/8.0 + +Known issues / Roadmap +====================== + +* If you use Firefox, you could hit https://github.com/odoo/odoo/issues/7722. + Just use Chromium to work with this snippet until you update to Odoo 9.0. +* When migrating to v9, improve the tour test to check autofilling of inputs. + +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. + +Credits +======= + +Contributors +------------ + +* Jairo Llopis + +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/website_mass_mailing_name/__init__.py b/website_mass_mailing_name/__init__.py new file mode 100644 index 00000000..6b59127e --- /dev/null +++ b/website_mass_mailing_name/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import controllers diff --git a/website_mass_mailing_name/__openerp__.py b/website_mass_mailing_name/__openerp__.py new file mode 100644 index 00000000..a547e36a --- /dev/null +++ b/website_mass_mailing_name/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Mass Mailing Subscription Snippet With Name", + "summary": "Ask for name when subscribing, and create and/or link partner", + "version": "8.0.1.0.0", + "category": "Website", + "website": "https://tecnativa.com/", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mass_mailing", + ], + "data": [ + "views/assets.xml", + "views/snippets.xml", + ], +} diff --git a/website_mass_mailing_name/controllers/__init__.py b/website_mass_mailing_name/controllers/__init__.py new file mode 100644 index 00000000..49478571 --- /dev/null +++ b/website_mass_mailing_name/controllers/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import main diff --git a/website_mass_mailing_name/controllers/main.py b/website_mass_mailing_name/controllers/main.py new file mode 100644 index 00000000..069de5d1 --- /dev/null +++ b/website_mass_mailing_name/controllers/main.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.addons.mass_mailing.controllers.main import MassMailController +from openerp.http import request, route + + +class MassMailingPartner(MassMailController): + @route() + def is_subscriber(self, *args, **kwargs): + """Get user name too.""" + result = super(MassMailingPartner, self).is_subscriber(*args, **kwargs) + email = result.get("email") or "" + if request.website.user_id != request.env.user: + name = request.env.user.name + else: + name, email = (request.env["mail.mass_mailing.contact"] + .get_name_email(email, context=request.context)) + result["name"] = name + result["email"] = email + return result diff --git a/website_mass_mailing_name/i18n/es.po b/website_mass_mailing_name/i18n/es.po new file mode 100644 index 00000000..414d9440 --- /dev/null +++ b/website_mass_mailing_name/i18n/es.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_mass_mailing_name +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-05-24 15:03+0000\n" +"PO-Revision-Date: 2016-05-24 17:04+0200\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"Language: es\n" +"X-Generator: Poedit 1.8.7.1\n" + +#. module: website_mass_mailing_name +#: view:website:website.snippets +msgid "your name..." +msgstr "su nombre..." diff --git a/website_mass_mailing_name/static/description/icon.png b/website_mass_mailing_name/static/description/icon.png new file mode 100644 index 00000000..b18b21a1 Binary files /dev/null and b/website_mass_mailing_name/static/description/icon.png differ diff --git a/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css b/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css new file mode 100644 index 00000000..03ed9d36 --- /dev/null +++ b/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css @@ -0,0 +1,9 @@ +@charset "UTF-8"; +/* © 2016 Jairo Llopis + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ +.js_subscribe .form-control { + width: 50%; } +.js_subscribe[data-subscribe=on] .js_subscribe_name { + display: none; } + +/*# sourceMappingURL=website_mass_mailing_name.css.map */ diff --git a/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map b/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map new file mode 100644 index 00000000..6c806587 --- /dev/null +++ b/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map @@ -0,0 +1,7 @@ +{ +"version": 3, +"mappings": ";;;AAKI,2BAAa;EACT,KAAK,EAAE,GAAG;AAGV,mDAAkB;EACd,OAAO,EAAE,IAAI", +"sources": ["website_mass_mailing_name.sass"], +"names": [], +"file": "website_mass_mailing_name.css" +} \ No newline at end of file diff --git a/website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass b/website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass new file mode 100644 index 00000000..5271c91b --- /dev/null +++ b/website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass @@ -0,0 +1,11 @@ +@charset "UTF-8" +/* © 2016 Jairo Llopis + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +.js_subscribe + .form-control + width: 50% + + &[data-subscribe=on] + .js_subscribe_name + display: none diff --git a/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js b/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js new file mode 100644 index 00000000..ffbe2e58 --- /dev/null +++ b/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js @@ -0,0 +1,61 @@ +/* © 2016 Jairo Llopis + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +"use strict"; +(function ($) { + openerp.website.snippet.animationRegistry.subscribe.include({ + start: function(editable_mode) { + var self = this; + self.$email = self.$target.find(".js_subscribe_email"); + self.$name = self.$target.find(".js_subscribe_name"); + + // Thanks upstream for your @$&#?!! inheritance-ready code. + // Injecting ajax events to modify behavior of snippet. + if (self.$name) { + $(document).ajaxSend(function(event, jqXHR, ajaxOptions) { + return self.on_ajax_send(event, jqXHR, ajaxOptions); + }); + } + + return self._super(editable_mode); + }, + on_click: function() { + var self = this, + email_error = !self.$email.val().match(/.+@.+/), + name_error = self.$name.length && !self.$name.val(), + values = { + "list_id": self.$target.data('list-id'), + "email": self.$email.val(), + }; + + // Stop on error + if (email_error || name_error) { + self.$target.addClass("has-error") + return false; + } + return self._super(); + }, + on_ajax_send: function(event, jqXHR, ajaxOptions) { + var self = this; + + // Add handlers on correct requests + if (ajaxOptions.url == "/website_mass_mailing/is_subscriber") { + jqXHR.then(function(data) { + return self.on_start(data); + }); + } else if (ajaxOptions.url == "/website_mass_mailing/subscribe") { + var data = JSON.parse(ajaxOptions.data); + data.params.email = + self.$name.val() + " <" + data.params.email + ">"; + ajaxOptions.data = JSON.stringify(data); + } + }, + on_start: function(data) { + this.$name.val(data.result.name) + .attr( + "disabled", + Boolean(data.result.is_subscriber && data.result.name.length) + ); + }, + }); +})(jQuery); diff --git a/website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js b/website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js new file mode 100644 index 00000000..fee76b10 --- /dev/null +++ b/website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js @@ -0,0 +1,137 @@ +/* © 2016 Jairo Llopis + * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ + +"use strict"; +(function ($) { + openerp.Tour.register({ + id: "mass_mailing_partner", + name: "Insert a newsletter snippet and subscribe", + path: "/", + mode: "test", + steps: [ + { + title: "Edit the homepage", + waitFor: "button[data-action=edit]", + element: "button[data-action=edit]", + }, + { + title: "Click on Insert Blocks", + waitFor: "button[data-action=snippet]", + element: "button[data-action=snippet]", + }, + { + title: "Click on Structure", + waitFor: "a[href='#snippet_structure']", + element: "a[href='#snippet_structure']", + }, + { + title: "Drag and drop a text snippet", + waitFor: ".oe_snippet:contains('Text Block'):visible", + snippet: ".oe_snippet:contains('Text Block')", + }, + { + title: "Click on Insert Blocks again", + waitFor: "#wrap h2:contains('A Great Headline'), \ + button[data-action=snippet]", + element: "button[data-action=snippet]", + }, + { + title: "Click on Content", + waitFor: "a[href='#snippet_content']", + element: "a[href='#snippet_content']", + }, + { + title: "Drag and drop a newsletter snippet", + waitFor: ".oe_snippet:contains('Newsletter'):visible", + snippet: ".oe_snippet:contains('Newsletter')", + }, + { + title: "Let the default mailing list", + waitFor: ".modal button:contains('Continue'):visible", + element: ".modal button:contains('Continue'):visible", + }, + { + title: "Save changes", + waitNot: ".modal:visible", + element: "button[data-action=save]", + }, + { + title: "Subscribe Administrator", + waitFor: "button[data-action=edit]:visible, \ + .js_subscribe_btn:visible", + element: ".js_subscribe_btn", + }, + { + title: "Open user menu", + waitFor: ".js_subscribe .alert-success:visible", + element: "#top_menu span:contains('Administrator')", + }, + { + title: "Log out", + waitFor: ".js_usermenu a:contains('Logout'):visible", + element: ".js_usermenu a:contains('Logout'):visible", + }, + { + title: "Try to subscribe without data", + waitFor: "#top_menu a[href='/web/login']:visible, \ + .js_subscribe_btn:visible", + element: ".js_subscribe_btn", + }, + { + title: "Enter a name", + waitFor: ".js_subscribe.has-error", + element: ".js_subscribe_name", + sampleText: "Visitor", + }, + { + title: "Try to subscribe without email", + element: ".js_subscribe_btn", + }, + { + title: "Remove the name", + waitFor: ".js_subscribe.has-error", + element: ".js_subscribe_name", + sampleText: "", + }, + { + title: "Enter an email", + element: ".js_subscribe_email", + sampleText: "example@example.com", + }, + { + title: "Try to subscribe without name", + element: ".js_subscribe_btn", + }, + { + title: "Enter the name again", + waitFor: ".js_subscribe.has-error", + element: ".js_subscribe_name", + sampleText: "Visitor", + }, + { + title: "Enter a wrong email", + element: ".js_subscribe_email", + sampleText: "bad email", + }, + { + title: "Try to subscribe with a bad email", + element: ".js_subscribe_btn", + }, + { + title: "Enter the good email", + waitFor: ".js_subscribe.has-error", + element: ".js_subscribe_email", + sampleText: "example@example.com", + }, + { + title: "Try to subscribe with good information", + element: ".js_subscribe_btn", + }, + { + title: "Subscription successful", + waitFor: ".js_subscribe:not(.has-error) \ + .alert-success:visible", + }, + ], + }); +})(jQuery); diff --git a/website_mass_mailing_name/tests/__init__.py b/website_mass_mailing_name/tests/__init__.py new file mode 100644 index 00000000..16a388f0 --- /dev/null +++ b/website_mass_mailing_name/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_ui diff --git a/website_mass_mailing_name/tests/test_ui.py b/website_mass_mailing_name/tests/test_ui.py new file mode 100644 index 00000000..ea8f36cc --- /dev/null +++ b/website_mass_mailing_name/tests/test_ui.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# © 2016 Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.tests.common import HttpCase + + +class UICase(HttpCase): + def test_ui(self): + """Test snippet behavior.""" + self.phantom_js( + "/", + "openerp.Tour.run('mass_mailing_partner', 'test')", + "openerp.Tour.tours.mass_mailing_partner", + "admin") diff --git a/website_mass_mailing_name/views/assets.xml b/website_mass_mailing_name/views/assets.xml new file mode 100644 index 00000000..0f4c2806 --- /dev/null +++ b/website_mass_mailing_name/views/assets.xml @@ -0,0 +1,23 @@ + + + + + + +