![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-checkout/view/frontend/web/js/view/form/element/ |
/** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ define([ 'jquery', 'uiComponent', 'ko', 'Magento_Customer/js/model/customer', 'Magento_Customer/js/action/check-email-availability', 'Magento_Customer/js/action/login', 'Magento_Checkout/js/model/quote', 'Magento_Checkout/js/checkout-data', 'Magento_Checkout/js/model/full-screen-loader', 'mage/validation' ], function ($, Component, ko, customer, checkEmailAvailability, loginAction, quote, checkoutData, fullScreenLoader) { 'use strict'; var validatedEmail; if (!checkoutData.getValidatedEmailValue() && window.checkoutConfig.validatedEmailValue ) { checkoutData.setInputFieldEmailValue(window.checkoutConfig.validatedEmailValue); checkoutData.setValidatedEmailValue(window.checkoutConfig.validatedEmailValue); } validatedEmail = checkoutData.getValidatedEmailValue(); if (validatedEmail && !customer.isLoggedIn()) { quote.guestEmail = validatedEmail; } return Component.extend({ defaults: { template: 'Magento_Checkout/form/element/email', email: checkoutData.getInputFieldEmailValue(), emailFocused: false, isLoading: false, isPasswordVisible: false, listens: { email: 'emailHasChanged', emailFocused: 'validateEmail' }, ignoreTmpls: { email: true } }, checkDelay: 2000, checkRequest: null, isEmailCheckComplete: null, isCustomerLoggedIn: customer.isLoggedIn, forgotPasswordUrl: window.checkoutConfig.forgotPasswordUrl, emailCheckTimeout: 0, emailInputId: '#customer-email', /** * Initializes regular properties of instance. * * @returns {Object} Chainable. */ initConfig: function () { this._super(); this.isPasswordVisible = this.resolveInitialPasswordVisibility(); return this; }, /** * Initializes observable properties of instance * * @returns {Object} Chainable. */ initObservable: function () { this._super() .observe(['email', 'emailFocused', 'isLoading', 'isPasswordVisible']); return this; }, /** * Callback on changing email property */ emailHasChanged: function () { var self = this; clearTimeout(this.emailCheckTimeout); if (self.validateEmail()) { quote.guestEmail = self.email(); checkoutData.setValidatedEmailValue(self.email()); } this.emailCheckTimeout = setTimeout(function () { if (self.validateEmail()) { self.checkEmailAvailability(); } else { self.isPasswordVisible(false); } }, self.checkDelay); checkoutData.setInputFieldEmailValue(self.email()); }, /** * Check email existing. */ checkEmailAvailability: function () { this.validateRequest(); this.isEmailCheckComplete = $.Deferred(); // Clean up errors on email $(this.emailInputId).removeClass('mage-error').parent().find('.mage-error').remove(); this.isLoading(true); this.checkRequest = checkEmailAvailability(this.isEmailCheckComplete, this.email()); $.when(this.isEmailCheckComplete).done(function () { this.isPasswordVisible(false); checkoutData.setCheckedEmailValue(''); }.bind(this)).fail(function () { this.isPasswordVisible(true); checkoutData.setCheckedEmailValue(this.email()); }.bind(this)).always(function () { this.isLoading(false); }.bind(this)); }, /** * If request has been sent -> abort it. * ReadyStates for request aborting: * 1 - The request has been set up * 2 - The request has been sent * 3 - The request is in process */ validateRequest: function () { if (this.checkRequest != null && $.inArray(this.checkRequest.readyState, [1, 2, 3])) { this.checkRequest.abort(); this.checkRequest = null; } }, /** * Local email validation. * * @param {Boolean} focused - input focus. * @returns {Boolean} - validation result. */ validateEmail: function (focused) { var loginFormSelector = 'form[data-role=email-with-possible-login]', usernameSelector = loginFormSelector + ' input[name=username]', loginForm = $(loginFormSelector), validator, valid; loginForm.validation(); if (focused === false && !!this.email()) { valid = !!$(usernameSelector).valid(); if (valid) { $(usernameSelector).removeAttr('aria-invalid aria-describedby'); } return valid; } if (loginForm.is(':visible')) { validator = loginForm.validate(); return validator.check(usernameSelector); } return true; }, /** * Log in form submitting callback. * * @param {HTMLElement} loginForm - form element. */ login: function (loginForm) { var loginData = {}, formDataArray = $(loginForm).serializeArray(); formDataArray.forEach(function (entry) { loginData[entry.name] = entry.value; }); if (this.isPasswordVisible() && $(loginForm).validation() && $(loginForm).validation('isValid')) { fullScreenLoader.startLoader(); loginAction(loginData).always(function () { fullScreenLoader.stopLoader(); }); } }, /** * Resolves an initial state of a login form. * * @returns {Boolean} - initial visibility state. */ resolveInitialPasswordVisibility: function () { if (checkoutData.getInputFieldEmailValue() !== '' && checkoutData.getCheckedEmailValue() !== '') { return true; } if (checkoutData.getInputFieldEmailValue() !== '') { return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue(); } return false; } }); });