Browse Source

[MIG][website_mass_mailing_name] Migration to v10

- Relicense to LGPL.
- Fix all known issues.
- Enable tour only in demo instances.
- Fix Sass headers.
- Remove compiled css and maps.
- Update JS modules to new api.
- Update tour to new tours api.
- Update module structure to match latest template.
pull/342/merge
Jairo Llopis 7 years ago
committed by Jairo Llopis
parent
commit
bd4c3a4f70
  1. 17
      website_mass_mailing_name/README.rst
  2. 3
      website_mass_mailing_name/__init__.py
  3. 17
      website_mass_mailing_name/__manifest__.py
  4. 3
      website_mass_mailing_name/controllers/__init__.py
  5. 28
      website_mass_mailing_name/controllers/main.py
  6. 17
      website_mass_mailing_name/demo/assets.xml
  7. 12
      website_mass_mailing_name/i18n/de.po
  8. 23
      website_mass_mailing_name/i18n/es.po
  9. 12
      website_mass_mailing_name/i18n/fr.po
  10. 24
      website_mass_mailing_name/i18n/hr.po
  11. 12
      website_mass_mailing_name/i18n/sl.po
  12. 9
      website_mass_mailing_name/static/src/css/website_mass_mailing_name.css
  13. 7
      website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map
  14. 5
      website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass
  15. 50
      website_mass_mailing_name/static/src/js/editor_tour.js
  16. 77
      website_mass_mailing_name/static/src/js/public_tour.js
  17. 60
      website_mass_mailing_name/static/src/js/website_mass_mailing_name.js
  18. 138
      website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js
  19. 17
      website_mass_mailing_name/templates/assets.xml
  20. 14
      website_mass_mailing_name/templates/snippets.xml
  21. 3
      website_mass_mailing_name/tests/__init__.py
  22. 22
      website_mass_mailing_name/tests/test_ui.py
  23. 23
      website_mass_mailing_name/views/assets.xml

17
website_mass_mailing_name/README.rst

@ -1,6 +1,6 @@
.. 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
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
=========================================== ===========================================
Mass Mailing Subscription Snippet With Name Mass Mailing Subscription Snippet With Name
@ -11,7 +11,7 @@ the contact name directly in the subscription snippet.
If you want to get partners created automatically and linked to the contacts, If you want to get partners created automatically and linked to the contacts,
you can additionally install the `mass_mailing_partner you can additionally install the `mass_mailing_partner
<https://www.odoo.com/apps/modules/8.0/mass_mailing_partner/>`_ module.
<https://www.odoo.com/apps/modules/10.0/mass_mailing_partner/>`_ module.
Usage Usage
===== =====
@ -26,14 +26,7 @@ To use this module, you need to:
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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.
:target: https://runbot.odoo-community.org/runbot/186/10.0
Bug Tracker Bug Tracker
=========== ===========

3
website_mass_mailing_name/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import controllers from . import controllers

17
website_mass_mailing_name/__openerp__.py → website_mass_mailing_name/__manifest__.py

@ -1,21 +1,24 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{ {
"name": "Mass Mailing Subscription Snippet With Name", "name": "Mass Mailing Subscription Snippet With Name",
"summary": "Ask for name when subscribing, and create and/or link partner", "summary": "Ask for name when subscribing, and create and/or link partner",
"version": "8.0.1.0.0",
"version": "10.0.1.0.0",
"category": "Website", "category": "Website",
"website": "https://tecnativa.com/", "website": "https://tecnativa.com/",
"author": "Tecnativa, Odoo Community Association (OCA)", "author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"license": "LGPL-3",
"application": False, "application": False,
"installable": True, "installable": True,
"depends": [ "depends": [
"mass_mailing",
"website_mass_mailing",
],
"demo": [
"demo/assets.xml",
], ],
"data": [ "data": [
"views/assets.xml",
"views/snippets.xml",
"templates/assets.xml",
"templates/snippets.xml",
], ],
} }

3
website_mass_mailing_name/controllers/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import main from . import main

28
website_mass_mailing_name/controllers/main.py

@ -1,22 +1,28 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openerp.addons.mass_mailing.controllers.main import MassMailController
from openerp.http import request, route
from odoo.addons.website_mass_mailing.controllers import main
from odoo.http import request, route
class MassMailingPartner(MassMailController):
class MassMailController(main.MassMailController):
@route() @route()
def is_subscriber(self, *args, **kwargs): def is_subscriber(self, *args, **kwargs):
"""Get user name too.""" """Get user name too."""
result = super(MassMailingPartner, self).is_subscriber(*args, **kwargs)
email = result.get("email") or ""
result = super(MassMailController, self).is_subscriber(*args, **kwargs)
if request.website.user_id != request.env.user: if request.website.user_id != request.env.user:
name = request.env.user.name name = request.env.user.name
else: else:
name, email = (request.env["mail.mass_mailing.contact"]
.get_name_email(email, context=request.context))
result["name"] = name
result["email"] = email
name = request.session.get("mass_mailing_name", "")
return dict(result, name=name)
@route()
def subscribe(self, list_id, email, **post):
"""Store email with name in session."""
result = super(MassMailController, self).subscribe(
list_id, email, **post)
name, email = request.env['mail.mass_mailing.contact'].sudo() \
.get_name_email(email)
request.session["mass_mailing_name"] = name if name != email else ""
return result return result

17
website_mass_mailing_name/demo/assets.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="assets_frontend_demo"
inherit_id="website.assets_frontend">
<xpath expr=".">
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/editor_tour.js"/>
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/public_tour.js"/>
</xpath>
</template>
</odoo>

12
website_mass_mailing_name/i18n/de.po

@ -3,14 +3,14 @@
# * website_mass_mailing_name # * website_mass_mailing_name
# #
# Translators: # Translators:
# Rudolf Schnapka <rs@techno-flex.de>, 2017
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-04-30 10:22+0000\n"
"PO-Revision-Date: 2017-04-30 10:22+0000\n"
"Last-Translator: Rudolf Schnapka <rs@techno-flex.de>, 2017\n"
"POT-Creation-Date: 2017-07-22 00:51+0000\n"
"PO-Revision-Date: 2017-07-22 00:51+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" "Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -19,6 +19,6 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: website_mass_mailing_name #. module: website_mass_mailing_name
#: view:website:website.snippets
#: model:ir.ui.view,arch_db:website_mass_mailing_name.s_newsletter_subscribe_form
msgid "your name..." msgid "your name..."
msgstr "Ihr Name..." msgstr "Ihr Name..."

23
website_mass_mailing_name/i18n/es.po

@ -1,23 +1,24 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * website_mass_mailing_name
#
# * website_mass_mailing_name
#
# Translators:
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \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"
"POT-Creation-Date: 2017-07-22 00:51+0000\n"
"PO-Revision-Date: 2017-07-22 00:51+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"Content-Transfer-Encoding: \n"
"Language: es\n" "Language: es\n"
"X-Generator: Poedit 1.8.7.1\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#. module: website_mass_mailing_name #. module: website_mass_mailing_name
#: view:website:website.snippets
#: model:ir.ui.view,arch_db:website_mass_mailing_name.s_newsletter_subscribe_form
msgid "your name..." msgid "your name..."
msgstr "su nombre..." msgstr "su nombre..."

12
website_mass_mailing_name/i18n/fr.po

@ -3,14 +3,14 @@
# * website_mass_mailing_name # * website_mass_mailing_name
# #
# Translators: # Translators:
# Christophe CHAUVET <christophe.chauvet@gmail.com>, 2016
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-06-30 01:08+0000\n"
"PO-Revision-Date: 2016-06-30 01:08+0000\n"
"Last-Translator: Christophe CHAUVET <christophe.chauvet@gmail.com>, 2016\n"
"POT-Creation-Date: 2017-07-22 00:51+0000\n"
"PO-Revision-Date: 2017-07-22 00:51+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" "Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -19,6 +19,6 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n > 1);\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. module: website_mass_mailing_name #. module: website_mass_mailing_name
#: view:website:website.snippets
#: model:ir.ui.view,arch_db:website_mass_mailing_name.s_newsletter_subscribe_form
msgid "your name..." msgid "your name..."
msgstr "votre nom..." msgstr "votre nom..."

24
website_mass_mailing_name/i18n/hr.po

@ -0,0 +1,24 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_mass_mailing_name
#
# Translators:
# Bole <bole@dajmi5.com>, 2017
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-12-01 02:19+0000\n"
"PO-Revision-Date: 2017-12-01 02:19+0000\n"
"Last-Translator: Bole <bole@dajmi5.com>, 2017\n"
"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Language: hr\n"
"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
#. module: website_mass_mailing_name
#: model:ir.ui.view,arch_db:website_mass_mailing_name.s_newsletter_subscribe_form
msgid "your name..."
msgstr "vaše ime..."

12
website_mass_mailing_name/i18n/sl.po

@ -3,14 +3,14 @@
# * website_mass_mailing_name # * website_mass_mailing_name
# #
# Translators: # Translators:
# Matjaž Mozetič <m.mozetic@matmoz.si>, 2016
# OCA Transbot <transbot@odoo-community.org>, 2017
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-06-30 01:08+0000\n"
"PO-Revision-Date: 2016-06-30 01:08+0000\n"
"Last-Translator: Matjaž Mozetič <m.mozetic@matmoz.si>, 2016\n"
"POT-Creation-Date: 2017-07-22 00:51+0000\n"
"PO-Revision-Date: 2017-07-22 00:51+0000\n"
"Last-Translator: OCA Transbot <transbot@odoo-community.org>, 2017\n"
"Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n" "Language-Team: Slovenian (https://www.transifex.com/oca/teams/23907/sl/)\n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -19,6 +19,6 @@ msgstr ""
"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" "Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n"
#. module: website_mass_mailing_name #. module: website_mass_mailing_name
#: view:website:website.snippets
#: model:ir.ui.view,arch_db:website_mass_mailing_name.s_newsletter_subscribe_form
msgid "your name..." msgid "your name..."
msgstr "vaše ime..." msgstr "vaše ime..."

9
website_mass_mailing_name/static/src/css/website_mass_mailing_name.css

@ -1,9 +0,0 @@
@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%; }
.js_subscribe[data-subscribe="on"] .js_subscribe_name:not([disabled]) {
display: none; }
/*# sourceMappingURL=website_mass_mailing_name.css.map */

7
website_mass_mailing_name/static/src/css/website_mass_mailing_name.css.map

@ -1,7 +0,0 @@
{
"version": 3,
"mappings": ";;;AAKI,2BAAa;EACT,KAAK,EAAE,GAAG;AAGV,qEAAkC;EAC9B,OAAO,EAAE,IAAI",
"sources": ["website_mass_mailing_name.sass"],
"names": [],
"file": "website_mass_mailing_name.css"
}

5
website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass

@ -1,6 +1,5 @@
@charset "UTF-8"
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
/*! Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
.js_subscribe .js_subscribe
.form-control .form-control

50
website_mass_mailing_name/static/src/js/editor_tour.js

@ -0,0 +1,50 @@
/* Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
odoo.define("website_mass_mailing_name.editor_tour", function (require) {
"use strict";
var base = require("web_editor.base");
var tour = require("web_tour.tour");
tour.register(
"mass_mailing_name_editor",
{
test: true,
wait_for: base.ready(),
},
[
{
content: "Edit the homepage",
trigger: ".o_menu_systray a[data-action=edit]",
},
{
content: "Drag and drop a text snippet",
trigger: ".oe_snippet[name='Text Block'] .oe_snippet_thumbnail",
run: "drag_and_drop #wrap",
},
{
content: "Drag and drop a newsletter snippet",
trigger: ".oe_snippet[name='Newsletter'] .oe_snippet_thumbnail",
run: "drag_and_drop #wrap .s_text_block",
},
{
content: "Let the default mailing list",
trigger: ".modal-dialog button:contains('Continue')",
},
{
content: "Save changes",
extra_trigger: "body:not(:has(.modal:visible))",
trigger: "#web_editor-top-edit button[data-action=save]",
},
{
content: "Subscribe Administrator",
extra_trigger: "body:not(:has(#web_editor-top-edit))",
trigger: ".js_subscribe_btn",
},
{
content: "Open user menu",
extra_trigger: ".js_subscribe .alert-success",
trigger: "#top_menu span:contains('Administrator')",
},
]
);
});

77
website_mass_mailing_name/static/src/js/public_tour.js

@ -0,0 +1,77 @@
/* Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
odoo.define("website_mass_mailing_name.public_tour", function (require) {
"use strict";
var base = require("web_editor.base");
var tour = require("web_tour.tour");
tour.register(
"mass_mailing_name_public",
{
test: true,
wait_for: base.ready(),
},
[
{
content: "Try to subscribe without data",
trigger: ".js_subscribe_btn",
},
{
content: "Enter a name",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_name",
run: "text Visitor",
},
{
content: "Try to subscribe without email",
trigger: ".js_subscribe_btn",
},
{
content: "Remove the name",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_name",
run: function () {
$(".js_subscribe_name").val("");
},
},
{
content: "Enter an email",
trigger: ".js_subscribe_email",
run: "text example@example.com",
},
{
content: "Try to subscribe without name",
trigger: ".js_subscribe_btn",
},
{
content: "Enter the name again",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_name",
run: "text Visitor",
},
{
content: "Enter a wrong email",
trigger: ".js_subscribe_email",
run: "text bad email",
},
{
content: "Try to subscribe with a bad email",
trigger: ".js_subscribe_btn",
},
{
content: "Enter the good email",
extra_trigger: ".js_subscribe.has-error",
trigger: ".js_subscribe_email",
run: "text example@example.com",
},
{
content: "Try to subscribe with good information",
trigger: ".js_subscribe_btn",
},
{
content: "Subscription successful",
trigger: ".js_subscribe:not(.has-error) .alert-success",
},
]
);
});

60
website_mass_mailing_name/static/src/js/website_mass_mailing_name.js

@ -1,55 +1,53 @@
/* © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
/* Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
* License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). */
"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");
odoo.define("website_mass_mailing_name.subscribe", function (require) {
"use strict";
require("mass_mailing.website_integration");
var animation = require("web_editor.snippets.animation");
animation.registry.subscribe.include({
start: function(editable_mode) {
this.$email = this.$target.find(".js_subscribe_email");
this.$name = this.$target.find(".js_subscribe_name");
// Thanks upstream for your @$&#?!! inheritance-ready code. // Thanks upstream for your @$&#?!! inheritance-ready code.
// Injecting ajax events to modify behavior of snippet. // 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);
});
if (this.$name) {
$(document).ajaxSend($.proxy(this.on_ajax_send, this));
} }
return self._super(editable_mode);
return this._super(editable_mode);
}, },
on_click: function() { on_click: function() {
var self = this,
email_error = !self.$email.val().match(/.+@.+/),
name_error = self.$name.length && !self.$name.val(),
var email_error = !this.$email.val().match(/.+@.+/),
name_error = this.$name.length && !this.$name.val(),
values = { values = {
"list_id": self.$target.data('list-id'),
"email": self.$email.val(),
"list_id": this.$target.data('list-id'),
"email": this.$email.val(),
}; };
// Stop on error // Stop on error
if (email_error || name_error) { if (email_error || name_error) {
self.$target.addClass("has-error")
this.$target.addClass("has-error")
return false; return false;
} }
return self._super();
return this._super.apply(this, arguments);
}, },
on_ajax_send: function(event, jqXHR, ajaxOptions) {
var self = this;
on_ajax_send: function(event, jqXHR, ajaxOptions) {
// Add handlers on correct requests // Add handlers on correct requests
if (ajaxOptions.url == "/website_mass_mailing/is_subscriber") { if (ajaxOptions.url == "/website_mass_mailing/is_subscriber") {
jqXHR.then(function(data) {
return self.on_start(data);
});
jqXHR.done($.proxy(this.on_start, this));
} else if (ajaxOptions.url == "/website_mass_mailing/subscribe") { } else if (ajaxOptions.url == "/website_mass_mailing/subscribe") {
var data = JSON.parse(ajaxOptions.data); var data = JSON.parse(ajaxOptions.data);
data.params.email =
self.$name.val() + " <" + data.params.email + ">";
data.params.email = _.str.sprintf(
"%s <%s>",
this.$name.val(),
data.params.email
);
ajaxOptions.data = JSON.stringify(data); ajaxOptions.data = JSON.stringify(data);
} }
}, },
on_start: function(data) { on_start: function(data) {
this.$name.val(data.result.name) this.$name.val(data.result.name)
.attr( .attr(
@ -58,4 +56,4 @@
); );
}, },
}); });
})(jQuery);
});

138
website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js

@ -1,138 +0,0 @@
/* © 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);

17
website_mass_mailing_name/templates/assets.xml

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<odoo>
<template id="assets_frontend"
inherit_id="website.assets_frontend">
<xpath expr=".">
<link rel="stylesheet"
href="/website_mass_mailing_name/static/src/css/website_mass_mailing_name.sass"/>
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js"/>
</xpath>
</template>
</odoo>

14
website_mass_mailing_name/views/snippets.xml → website_mass_mailing_name/templates/snippets.xml

@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<!-- Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
<openerp>
<data>
<odoo>
<template id="mailing_list_subscribe"
inherit_id="mass_mailing.mailing_list_subscribe">
<template id="s_newsletter_subscribe_form"
inherit_id="website_mass_mailing.s_newsletter_subscribe_form">
<xpath expr="//input[@class='js_subscribe_email form-control']" <xpath expr="//input[@class='js_subscribe_email form-control']"
position="before"> position="before">
<input <input
@ -16,5 +15,4 @@
</xpath> </xpath>
</template> </template>
</data>
</openerp>
</odoo>

3
website_mass_mailing_name/tests/__init__.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from . import test_ui from . import test_ui

22
website_mass_mailing_name/tests/test_ui.py

@ -1,15 +1,25 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# Copyright 2016-2017 Jairo Llopis <jairo.llopis@tecnativa.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
from openerp.tests.common import HttpCase
from odoo.http import root
from odoo.tests.common import HttpCase
class UICase(HttpCase): class UICase(HttpCase):
def test_ui(self): def test_ui(self):
"""Test snippet behavior.""" """Test snippet behavior."""
tour = "odoo.__DEBUG__.services['web_tour.tour'].%s"
# Admin edits home page and adds subscription snippet
self.phantom_js( self.phantom_js(
"/", "/",
"openerp.Tour.run('mass_mailing_partner', 'test')",
"openerp.Tour.tours.mass_mailing_partner",
"admin")
tour % "run('mass_mailing_name_editor')",
tour % "tours.mass_mailing_name_editor.ready",
login="admin")
# Forced log out
root.session_store.delete(self.session)
# Public user uses subscription snippet
self.phantom_js(
"/",
tour % "run('mass_mailing_name_public')",
tour % "tours.mass_mailing_name_public.ready")

23
website_mass_mailing_name/views/assets.xml

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- © 2016 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data>
<template id="assets_frontend"
inherit_id="mass_mailing.assets_frontend">
<xpath expr=".">
<link rel="stylesheet"
href="/website_mass_mailing_name/static/src/css/website_mass_mailing_name.css"/>
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/website_mass_mailing_name.js"/>
<t t-if="request.registry.test_cr">
<script type="text/javascript"
src="/website_mass_mailing_name/static/src/js/website_mass_mailing_name.tour.js"/>
</t>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save