Skip to content

Commit ea0362a

Browse files
author
Korshenko, Olexii(okorshenko)
committed
Merge pull request #51 from magento-folks/merchant_beta
[Folks] Bugfixes
2 parents 193a970 + df095d2 commit ea0362a

File tree

2 files changed

+68
-36
lines changed

2 files changed

+68
-36
lines changed

app/code/Magento/Customer/view/frontend/web/js/view/customer-email.js

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
*/
55
/*browser:true*/
66
/*global define*/
7-
define(
8-
[
7+
define([
98
'jquery',
109
'uiComponent',
1110
'ko',
@@ -16,13 +15,19 @@ define(
1615
'mage/validation'
1716
],
1817
function ($, Component, ko, customer, checkEmailAvailability, loginAction, quote) {
19-
"use strict";
18+
'use strict';
19+
2020
return Component.extend({
2121
defaults: {
2222
template: 'Magento_Customer/customer-email',
2323
email: '',
24+
emailFocused: false,
2425
isLoading: false,
25-
isPasswordVisible: false
26+
isPasswordVisible: false,
27+
listens: {
28+
email: 'emailHasChanged',
29+
emailFocused: 'validateEmail'
30+
}
2631
},
2732
checkDelay: 2000,
2833
checkRequest: null,
@@ -31,24 +36,26 @@ define(
3136
forgotPasswordUrl: window.checkoutConfig.forgotPasswordUrl,
3237
emailCheckTimeout: 0,
3338

34-
initialize: function() {
35-
this._super();
36-
var self = this;
37-
this.email.subscribe(function() {
38-
self.emailHasChanged();
39-
});
40-
},
41-
42-
/** Initialize observable properties */
39+
/**
40+
* Initialize observable properties of instance
41+
*
42+
* @returns {Object} Chainable.
43+
*/
4344
initObservable: function () {
4445
this._super()
45-
.observe(['email', 'isLoading', 'isPasswordVisible']);
46+
.observe(['email', 'emailFocused', 'isLoading', 'isPasswordVisible']);
47+
4648
return this;
4749
},
4850

51+
/**
52+
* Callback on changing email property
53+
*/
4954
emailHasChanged: function () {
5055
var self = this;
56+
5157
clearTimeout(this.emailCheckTimeout);
58+
5259
if (self.validateEmail()) {
5360
quote.guestEmail = self.email();
5461
}
@@ -62,54 +69,77 @@ define(
6269

6370
},
6471

65-
checkEmailAvailability: function() {
72+
/**
73+
* Check email existing.
74+
*/
75+
checkEmailAvailability: function () {
6676
var self = this;
6777
this.validateRequest();
6878
this.isEmailCheckComplete = $.Deferred();
6979
this.isLoading(true);
7080
this.checkRequest = checkEmailAvailability(this.isEmailCheckComplete, this.email());
7181

72-
$.when(this.isEmailCheckComplete).done(function() {
82+
$.when(this.isEmailCheckComplete).done(function () {
7383
self.isPasswordVisible(false);
74-
}).fail( function() {
84+
}).fail(function () {
7585
self.isPasswordVisible(true);
7686
}).always(function () {
7787
self.isLoading(false);
7888
});
7989
},
8090

81-
validateRequest: function() {
82-
/*
83-
* If request has been sent -> abort it.
84-
* ReadyStates for request aborting:
85-
* 1 - The request has been set up
86-
* 2 - The request has been sent
87-
* 3 - The request is in process
88-
*/
91+
/**
92+
* If request has been sent -> abort it.
93+
* ReadyStates for request aborting:
94+
* 1 - The request has been set up
95+
* 2 - The request has been sent
96+
* 3 - The request is in process
97+
*/
98+
validateRequest: function () {
99+
89100
if (this.checkRequest != null && $.inArray(this.checkRequest.readyState, [1, 2, 3])) {
90101
this.checkRequest.abort();
91102
this.checkRequest = null;
92103
}
93104
},
94105

95-
validateEmail: function() {
96-
var loginFormSelector = 'form[data-role=email-with-possible-login]';
97-
$(loginFormSelector).validation();
98-
var validationResult = $(loginFormSelector + ' input[name=username]').valid();
99-
return Boolean(validationResult);
106+
/**
107+
* Local email validation.
108+
*
109+
* @param {Boolean} focused - input focus.
110+
* @returns {Boolean} - validation result.
111+
*/
112+
validateEmail: function (focused) {
113+
var loginFormSelector = 'form[data-role=email-with-possible-login]',
114+
usernameSelector = loginFormSelector + ' input[name=username]',
115+
loginForm = $(loginFormSelector),
116+
validator;
117+
118+
loginForm.validation();
119+
120+
if (focused === false) {
121+
return !!$(usernameSelector).valid();
122+
}
123+
124+
validator = loginForm.validate();
125+
126+
return validator.check(usernameSelector);
100127
},
101128

102-
login: function(loginForm) {
129+
/**
130+
* Log in form submitting callback.
131+
*
132+
* @param {HTMLElement} loginForm - form element
133+
*/
134+
login: function (loginForm) {
103135
var loginData = {},
104136
formDataArray = $(loginForm).serializeArray();
105137

106138
formDataArray.forEach(function (entry) {
107139
loginData[entry.name] = entry.value;
108140
});
109-
if (this.isPasswordVisible()
110-
&& $(loginForm).validation()
111-
&& $(loginForm).validation('isValid')
112-
) {
141+
142+
if (this.isPasswordVisible() && $(loginForm).validation() && $(loginForm).validation('isValid')) {
113143
loginAction(loginData);
114144
}
115145
}

app/code/Magento/Customer/view/frontend/web/template/customer-email.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
<div class="control _with-tooltip">
2121
<input class="input-text"
2222
type="email"
23-
data-bind="textInput: email"
23+
data-bind="
24+
textInput: email,
25+
hasFocus: emailFocused"
2426
name="username"
2527
data-validate="{required:true, 'validate-email':true}"
2628
id="customer-email" />

0 commit comments

Comments
 (0)