Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0][ADD][website_snippet_mass_mailing_name] Snippet + name #66

Merged
merged 2 commits into from
Jun 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
crm
67 changes: 67 additions & 0 deletions website_mass_mailing_name/README.rst
Original file line number Diff line number Diff line change
@@ -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
<https://www.odoo.com/apps/modules/8.0/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
<https://github.com/OCA/website/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 <jairo.llopis@tecnativa.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 https://odoo-community.org.
5 changes: 5 additions & 0 deletions website_mass_mailing_name/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import controllers
21 changes: 21 additions & 0 deletions website_mass_mailing_name/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# 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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

website?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mass_mailing depends on website.

],
"data": [
"views/assets.xml",
"views/snippets.xml",
],
}
5 changes: 5 additions & 0 deletions website_mass_mailing_name/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import main
22 changes: 22 additions & 0 deletions website_mass_mailing_name/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# 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
23 changes: 23 additions & 0 deletions website_mass_mailing_name/i18n/es.po
Original file line number Diff line number Diff line change
@@ -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..."
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@charset "UTF-8"
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* 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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* 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",
},
// Expect this test to work in v9 when uncommenting this
// {
// title: "Subscription successful",
// waitFor: ".js_subscribe:not(.has-error) \
// .alert-success:visible",
// },
],
});
})(jQuery);
5 changes: 5 additions & 0 deletions website_mass_mailing_name/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_ui
Loading