Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

64 wiersze
1.7 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'uiElement',
  8. 'mage/url',
  9. 'subscriptionStatusResolver',
  10. 'mage/validation'
  11. ], function ($, Component, urlBuilder, subscriptionStatusResolver) {
  12. 'use strict';
  13. return Component.extend({
  14. defaults: {
  15. signUpElement: '',
  16. submitButton: '',
  17. element: null
  18. },
  19. /** @inheritdoc */
  20. initialize: function (config, element) {
  21. this._super();
  22. this.element = element;
  23. $(element).on('change', $.proxy(this.updateSignUpStatus, this));
  24. this.updateSignUpStatus();
  25. },
  26. /**
  27. * Send status request and update subscription element according to result.
  28. */
  29. updateSignUpStatus: function () {
  30. var element = $(this.element),
  31. email = element.val(),
  32. self = this,
  33. newsletterSubscription;
  34. if ($(self.signUpElement).is(':checked')) {
  35. return;
  36. }
  37. if (!email || !$.validator.methods['validate-email'].call(this, email, element)) {
  38. return;
  39. }
  40. newsletterSubscription = $.Deferred();
  41. $(self.submitButton).prop('disabled', true);
  42. subscriptionStatusResolver(email, newsletterSubscription);
  43. $.when(newsletterSubscription).done(function (isSubscribed) {
  44. if (isSubscribed) {
  45. $(self.signUpElement).prop('checked', true);
  46. }
  47. }).always(function () {
  48. $(self.submitButton).prop('disabled', false);
  49. });
  50. }
  51. });
  52. });