Skip to content

[9.0] [WIP] website_crm_privacy_policy module migrate - #302

Merged
pedrobaeza merged 4 commits into
OCA:9.0from
Tecnativa:9.0-mig-website_crm_privacy_policy
Jan 9, 2017
Merged

pedrobaeza merged 4 commits into
OCA:9.0from
Tecnativa:9.0-mig-website_crm_privacy_policy

Conversation

@cubells

@cubells cubells commented Dec 20, 2016

Copy link
Copy Markdown
Member
  • Updated README
  • Updated views
  • Updated js

WIP

cc @Tecnativa

@cubells
cubells force-pushed the 9.0-mig-website_crm_privacy_policy branch from 1ecc11c to 0d68c36 Compare December 20, 2016 17:27
@yajo yajo added this to the 9.0 milestone Dec 21, 2016
if (typeof jQuery === 'undefined') { throw new Error('Website CRM privacy policy addon requires jQuery') }
var core = require('web.core');
var ajax = require('web.ajax');
var _t = core._t;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add var animation = require('web_editor.snippets.animation');


+function ($) {
'use strict';
crm_policy.registry.accept_policy = snippet_animation.Class.extend({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

return animation.registry.accept_policy = animation.Class.extend({

$(document).ready(function() {
var _t = openerp._t;
start: function() {
var self = this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Delete this line.

var _t = openerp._t;
start: function() {
var self = this;
this.$target.find('.o_website_form_send').on('click', function (e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Better get used to proxies: this.$('.o_website_form_send').on('click', $.proxy(this.accept_policy, this));

$('form[action="/crm/contactus"]').on('submit', function(e) {
// Validate privacy_policy is checked
if(!$('input[name="privacy_policy"]').is(':checked')) {
accept_policy: function(e) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other developers appreciate real names for variables, functions, etc. Use event instead of e for the sake of readability please.

e.preventDefault(); // Prevent the default submit behavior
this.$target.find('.o_website_form_send').off(); // Prevent users from crazy clicking

var self = this;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove this line, you are not using it.

@cubells
cubells force-pushed the 9.0-mig-website_crm_privacy_policy branch from 4ff63e8 to 0c23225 Compare December 21, 2016 11:51
e.preventDefault(); // Prevent the default submit behavior
accept_policy: function(event) {
event.preventDefault(); // Prevent the default submit behavior
this.$target.find('.o_website_form_send').off(); // Prevent users from crazy clicking

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The normal thing to do here is to disable the button instead of unbinding its events. Please make sure off() is doing what you expect.

var self = this;
if(!this.target.find('input[name="privacy_policy"]').is(':checked')) {
e.preventDefault(); // Prevent form from submitting
if(!this.$target.find('input[name="privacy_policy"]').is(':checked')) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use the this.$('input[name="privacy_policy"]') shorthand available in animations.

crm_policy.registry.accept_policy = snippet_animation.Class.extend({

return animation.registry.accept_policy = animation.Class.extend({
selector: '.s_website_form',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You are affecting more forms than just the website_crm one, right? Shouldn't this be reflected in the addon name?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

How can affect "only" the website_crm form?

@@ -9,28 +9,24 @@ odoo.define('website_crm_privacy_policy.crm_policy', function (require) {
var core = require('web.core');
var ajax = require('web.ajax');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you are not using this dependency. Please check and drop it if so.

@yajo yajo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have tested in runbot and current behavior is plainly broken. Alert triggers twice and form is never sent.

However, I checked that nowadays every major browser supports HTML5 validation, so how about simply removing all the JS stuff and replacing it by a required="required" attribute in the legal terms checkbox? That will trigger the native, beautiful and automatic browser validation with no extra work.

@pedrobaeza

Copy link
Copy Markdown
Member

@yajo, please make the change as you have proposed.

@pedrobaeza pedrobaeza mentioned this pull request Jan 4, 2017
34 tasks
@yajo

yajo commented Jan 4, 2017

Copy link
Copy Markdown
Member

I just did a quick update, so you can see the idea, but did not test it. Let's wait for runbot and see.

@yajo
yajo force-pushed the 9.0-mig-website_crm_privacy_policy branch from b732f62 to 4dee297 Compare January 5, 2017 09:05
@yajo

yajo commented Jan 5, 2017

Copy link
Copy Markdown
Member

OK @pedrobaeza @cubells, this is interesting. With 4dee297 it works now.

The problem is not about using or not HTML5 validation, the problem is that the new website_form addon disables it.

I decided to write the long explanation of the problem as a bug in odoo/odoo#14942, to keep it as a reference. Please check it out.

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well, there's no visual sign that you lack of clicking on the accept terms, only "Invalid form". Can this be due to a missing class? For now, I'm merging, and if it can be improved, we make another PR.

oca-transbot and others added 4 commits January 5, 2017 21:58
New `website_form` addon includes an undocumented validation system.
By simply adapting layout to what it wants, we get validation for free.
@pedrobaeza
pedrobaeza force-pushed the 9.0-mig-website_crm_privacy_policy branch from 4dee297 to 542c37f Compare January 5, 2017 20:58
@pedrobaeza

Copy link
Copy Markdown
Member

In website_sale_require_legal we have a balloon:

seleccion_003

Why don't we have it here?

@pedrobaeza

Copy link
Copy Markdown
Member

I wait for merging until the question is solved.

@yajo

yajo commented Jan 9, 2017

Copy link
Copy Markdown
Member

Yep, that's all explained in odoo/odoo#14942.

The contactus form uses the website_form tools, which has these drawbacks. OTOH the checkout form is a pseudo-standard HTML5 form (with the pseudo part fixed in that addon) and thus benefits from having a clear & standard UI feedback on validation error.

Avoiding the website_form dependency would mean to refactor the whole website_crm addon, so this should be fixed upstream in master. For now, this is what we have.

BTW, doesn't the label get red when you don't check it?

@pedrobaeza

Copy link
Copy Markdown
Member

No, it doesn't. You don't have any visual sign of what is incorrect, which is very anti-user friendly.

@yajo

yajo commented Jan 9, 2017

Copy link
Copy Markdown
Member

Sorry to correct you but it does:

captura de pantalla de 2017-01-09 10-58-56

It gets red, and the field has an *. This is the expected behavior for a website_form-based form. I agree it's a 💩, but that must be fixed in odoo/odoo#14942 😞

@pedrobaeza

Copy link
Copy Markdown
Member

OK, it's very weird indeed and I didn't even noticed about the text turning into red (I was expecting the checkbox is surrounded by red). Anyway, if there's no other solution, let's go this way.

@pedrobaeza
pedrobaeza merged commit d954c8b into OCA:9.0 Jan 9, 2017
@pedrobaeza
pedrobaeza deleted the 9.0-mig-website_crm_privacy_policy branch January 9, 2017 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants