solutions.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'uiClass',
  8. 'Magento_Paypal/js/solution',
  9. 'underscore'
  10. ], function ($, Class, Solution, _) {
  11. 'use strict';
  12. return Class.extend({
  13. defaults: {
  14. /**
  15. * Initialized solutions
  16. */
  17. solutions: {},
  18. /**
  19. * The elements of created solutions
  20. */
  21. solutionsElements: {},
  22. /**
  23. * The selector element responsible for configuration of payment method (CSS class)
  24. */
  25. buttonConfiguration: '.button.action-configure'
  26. },
  27. /**
  28. * Constructor
  29. *
  30. * @param {Object} config
  31. * @returns {exports.initialize}
  32. */
  33. initialize: function (config) {
  34. this.initConfig(config)
  35. .initSolutions();
  36. return this;
  37. },
  38. /**
  39. * Initialization and configuration solutions
  40. *
  41. * @returns {exports.initSolutions}
  42. */
  43. initSolutions: function () {
  44. _.each(this.config.solutions, this.addSolution, this);
  45. this.initializeSolutions()
  46. .wipeButtonsConfiguration();
  47. _.each(this.solutions, this.applicationRules);
  48. return this;
  49. },
  50. /**
  51. * The creation and addition of the solution according to the configuration
  52. *
  53. * @param {Object} solution
  54. * @param {String} identifier
  55. */
  56. addSolution: function (solution, identifier) {
  57. this.solutions[identifier] = new Solution({
  58. config: solution,
  59. buttonConfiguration: this.buttonConfiguration
  60. }, identifier);
  61. this.solutionsElements[identifier] = this.solutions[identifier].$self;
  62. },
  63. /**
  64. * Wiping buttons configuration of the payment method
  65. */
  66. wipeButtonsConfiguration: function () {
  67. $(this.buttonConfiguration).removeClass('disabled')
  68. .removeAttr('disabled');
  69. },
  70. /**
  71. * Application of the rules
  72. *
  73. * @param {Object} solution
  74. */
  75. applicationRules: function (solution) {
  76. _.each(solution.afterLoadRules, function (rule) {
  77. rule.apply();
  78. });
  79. },
  80. /**
  81. * Initialize solutions
  82. *
  83. * @returns {exports.initializeSolutions}
  84. */
  85. initializeSolutions: function () {
  86. _.each(this.solutions, function (solution) {
  87. solution.setSolutionsElements(this.solutionsElements)
  88. .initEvents()
  89. .addListeners();
  90. }, this);
  91. return this;
  92. }
  93. });
  94. });