From cad3b13bb6afaa7918f3075623685f6562fb1f8f Mon Sep 17 00:00:00 2001 From: "Gurzhyi, Andrii" <agurzhyi@ebay.com> Date: Mon, 19 Oct 2015 15:43:04 +0300 Subject: [PATCH] MAGETWO-44098: Enable PayPal Credit dropdown is active when Enable Express Checkout set to No in PayPal Payflow Link - Fixed convertor configuration and initialization events --- .../Paypal/Model/Config/Rules/Converter.php | 30 +--- .../Unit/Model/Config/Rules/ConverterTest.php | 54 ++++--- .../Config/Rules/ConvertibleContent/rules.xml | 4 + .../Paypal/etc/adminhtml/rules/payment_us.xml | 3 + .../adminhtml/web/js/predicate/confirm.js | 15 +- .../Paypal/view/adminhtml/web/js/rule.js | 14 +- .../view/adminhtml/web/js/rules/conflict.js | 32 ++-- .../view/adminhtml/web/js/rules/disable.js | 3 +- .../bml/disable-conditional-express.js | 5 +- .../rules/payflow/bml/disable-conditional.js | 5 +- .../web/js/rules/payflow/bml/disable.js | 3 +- .../rules/payflow/bml/enable-conditional.js | 11 +- .../web/js/rules/payflow/bml/enable.js | 3 +- .../js/rules/payflow/bml/lock-conditional.js | 5 +- .../payflow/express/disable-conditional.js | 5 +- .../web/js/rules/payflow/express/disable.js | 3 +- .../payflow/express/enable-conditional.js | 11 +- .../web/js/rules/payflow/express/enable.js | 3 +- .../rules/payflow/express/lock-conditional.js | 5 +- .../rules/paypal/bml/disable-conditional.js | 5 +- .../web/js/rules/paypal/bml/disable.js | 3 +- .../web/js/rules/paypal/bml/enable.js | 3 +- .../web/js/rules/paypal/express/disable.js | 3 +- .../express/lock-configuration-conditional.js | 14 +- .../paypal/express/lock-configuration.js | 3 +- .../js/rules/paypal/express/mark-disable.js | 14 +- .../paypal/express/unlock-configuration.js | 11 +- .../adminhtml/web/js/rules/simple/disable.js | 3 +- .../web/js/rules/simple/mark-enable.js | 5 +- .../Paypal/view/adminhtml/web/js/solution.js | 137 +++++++++++++----- .../Paypal/view/adminhtml/web/js/solutions.js | 35 ++++- 31 files changed, 298 insertions(+), 152 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Config/Rules/Converter.php b/app/code/Magento/Paypal/Model/Config/Rules/Converter.php index a636188baf1..b2dad4af6f4 100644 --- a/app/code/Magento/Paypal/Model/Config/Rules/Converter.php +++ b/app/code/Magento/Paypal/Model/Config/Rules/Converter.php @@ -60,6 +60,7 @@ class Converter implements ConverterInterface $result = []; /** @var \DOMElement $child */ foreach ($node->childNodes as $child) { + /** @var \DOMElement $child */ if ($this->hasNodeElement($child)) { $result[$child->getAttribute('name')] = [ 'value' => $child->getAttribute('value'), @@ -80,8 +81,8 @@ class Converter implements ConverterInterface protected function createPredicate(\DOMElement $node) { $result = []; - /** @var \DOMElement $child */ foreach ($node->childNodes as $child) { + /** @var \DOMElement $child */ if ($this->hasNodeElement($child)) { $result = [ 'name' => $child->getAttribute('name'), @@ -105,33 +106,18 @@ class Converter implements ConverterInterface { $result = []; foreach ($node->childNodes as $child) { + /** @var \DOMElement $child */ if ($this->hasNodeElement($child)) { - $result = array_merge($result, $this->createRule($child)); + $result[$child->getAttribute('type')][] = [ + 'event' => $child->getAttribute('event'), + 'argument' => $this->createArgument($child), + ]; } } return [$node->getAttribute('target') => $result]; } - /** - * Creating rules - * - * @param \DOMElement $node - * @return array - */ - protected function createRule(\DOMElement $node) - { - $result = []; - $type = $node->getAttribute('type'); - /** @var \DOMElement $node */ - $result[$type] = [ - 'event' => $node->getAttribute('event'), - ]; - $result[$type]['argument'] = $this->createArgument($node); - - return $result; - } - /** * Create argument * @@ -141,8 +127,8 @@ class Converter implements ConverterInterface protected function createArgument(\DOMElement $node) { $result = []; - /** @var \DOMElement $child */ foreach ($node->childNodes as $child) { + /** @var \DOMElement $child */ if ($this->hasNodeElement($child)) { $result[$child->getAttribute('name')] = $child->textContent; } diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConverterTest.php b/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConverterTest.php index eb62d570481..ffd2f141e0a 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConverterTest.php +++ b/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConverterTest.php @@ -78,22 +78,27 @@ class ConverterTest extends \PHPUnit_Framework_TestCase 'relations' => [ 'payment_test_1' => [ 'test' => [ - 'event' => 'event0', - 'argument' => [], + [ + 'event' => 'event0', + 'argument' => [], + ] ], ], 'payment_test_2' => [ 'test' => [ - 'event' => 'event1', - 'argument' => [ - ], + [ + 'event' => 'event1', + 'argument' => [], + ] ], 'test-two' => [ - 'event' => 'event1', - 'argument' => [ - 'argument1' => 'argument1', - 'argument2' => 'argument2', - ], + [ + 'event' => 'event1', + 'argument' => [ + 'argument1' => 'argument1', + 'argument2' => 'argument2', + ], + ] ], ], ], @@ -122,21 +127,34 @@ class ConverterTest extends \PHPUnit_Framework_TestCase 'relations' => [ 'payment_test_1' => [ 'test' => [ - 'event' => 'event0', - 'argument' => [], + [ + 'event' => 'event0', + 'argument' => [], + ] ], ], 'payment_test_2' => [ 'test' => [ - 'event' => 'event1', - 'argument' => [], + [ + 'event' => 'event1', + 'argument' => [], + ] ], 'test-two' => [ - 'event' => 'event1', - 'argument' => [ - 'argument1' => 'argument1', - 'argument2' => 'argument2', + [ + 'event' => 'event1', + 'argument' => [ + 'argument1' => 'argument1', + 'argument2' => 'argument2', + ], ], + [ + 'event' => 'event2', + 'argument' => [ + 'argument1' => 'argument1', + 'argument2' => 'argument2', + ], + ] ], ], ], diff --git a/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConvertibleContent/rules.xml b/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConvertibleContent/rules.xml index 297d3c8e620..4b4c6833d92 100644 --- a/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConvertibleContent/rules.xml +++ b/app/code/Magento/Paypal/Test/Unit/Model/Config/Rules/ConvertibleContent/rules.xml @@ -52,6 +52,10 @@ <argument name="argument1">argument1</argument> <argument name="argument2">argument2</argument> </rule> + <rule type="test-two" event="event2"> + <argument name="argument1">argument1</argument> + <argument name="argument2">argument2</argument> + </rule> </relation> </payment> </rules> diff --git a/app/code/Magento/Paypal/etc/adminhtml/rules/payment_us.xml b/app/code/Magento/Paypal/etc/adminhtml/rules/payment_us.xml index c187130b357..4b5acbe6e07 100644 --- a/app/code/Magento/Paypal/etc/adminhtml/rules/payment_us.xml +++ b/app/code/Magento/Paypal/etc/adminhtml/rules/payment_us.xml @@ -329,7 +329,10 @@ <argument name="wpp_usuk">wpp_usuk</argument> <argument name="paypal_payflowpro_with_express_checkout">paypal_payflowpro_with_express_checkout</argument> </rule> + <rule type="payflow/bml/disable-conditional-express" event="deactivate-express"/> + <rule type="payflow/bml/disable-conditional-express" event=":load"/> + <rule type="payflow/bml/enable" event="activate-express"/> <rule type="payflow/express/lock-conditional" event=":load"/> <rule type="payflow/bml/lock-conditional" event=":load"/> diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/predicate/confirm.js b/app/code/Magento/Paypal/view/adminhtml/web/js/predicate/confirm.js index ea426368243..278b101c9c6 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/predicate/confirm.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/predicate/confirm.js @@ -2,25 +2,28 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -define([], function () { - "use strict"; +define(['underscore'], function (_) { + 'use strict'; + return function (solution, message, argument) { var isConfirm = false; _.every(argument, function (name) { - if (solution.solutionsElements[name] - && solution.solutionsElements[name].find(solution.enableButton).val() == 1 + if (solution.solutionsElements[name] && + solution.solutionsElements[name].find(solution.enableButton).val() == 1 ) { isConfirm = true; + return !isConfirm; } + return !isConfirm; }, this); if (isConfirm) { return confirm(message); - } else { - return true; } + + return true; }; }); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rule.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rule.js index b565aa2d66d..c1c12344cc5 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rule.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rule.js @@ -3,18 +3,24 @@ * See COPYING.txt for license details. */ define([ - "uiClass", - "underscore" -], function (Class, _) { - "use strict"; + 'uiClass' +], function (Class) { + 'use strict'; + return Class.extend({ + /** * Constructor + * + * @param {Object} config + * @returns {exports.initialize} */ initialize: function (config) { this.initConfig(config); + return this; }, + /** * To apply the rule */ diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/conflict.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/conflict.js index 4d94f6a2a9f..ab0ca8b9f60 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/conflict.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/conflict.js @@ -2,32 +2,42 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -(function() { +(function () { + 'use strict'; + var executed = false; + define([ - 'Magento_Ui/js/modal/alert' - ], function (alert) { - "use strict"; + 'Magento_Ui/js/modal/alert', + 'underscore' + ], function (alert, _) { + return function ($target, $owner, data) { - if ($owner.find(data.enableButton).val() == 1) { - var isDisabled = true; + var isDisabled = true, + newLine = String.fromCharCode(10, 13); + + if ($owner.find(data.enableButton).val() === '1') { _.every(data.argument, function (name) { - if (data.solutionsElements[name] - && data.solutionsElements[name].find(data.enableButton).val() == 1 + if (data.solutionsElements[name] && + data.solutionsElements[name].find(data.enableButton).val() === '1' ) { isDisabled = false; + return isDisabled; } + return isDisabled; }, this); if (!isDisabled && !executed) { executed = true; alert({ - content: "The following error(s) occured:\n\r" - +"Some PayPal solutions conflict.\n\r" - +"Please re-enable the previously enabled payment solutions." + content: 'The following error(s) occurred:\n\r' + + newLine + + 'Some PayPal solutions conflict.' + + newLine + + 'Please re-enable the previously enabled payment solutions.' }); } } diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/disable.js index a5cc52ed96b..54e35558039 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/disable.js @@ -5,7 +5,8 @@ define([ 'Magento_Paypal/js/rules/simple/disable' ], function (disable) { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { disable($target, $owner, data); $target.find(data.enableButton).change(); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional-express.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional-express.js index 8fccdd05455..e3d95340b8b 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional-express.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional-express.js @@ -5,9 +5,10 @@ define([ 'Magento_Paypal/js/rules/payflow/bml/disable' ], function (disable) { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { - if ($target.find(data.enableExpress).val() == "0") { + if ($target.find(data.enableExpress).val() === '0') { disable($target, $owner, data); } }; diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional.js index 2c5ae426534..20182ef0205 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable-conditional.js @@ -5,9 +5,10 @@ define([ 'Magento_Paypal/js/rules/payflow/bml/disable' ], function (disable) { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { - if ($target.find(data.enableButton).val() == "0") { + if ($target.find(data.enableButton).val() === '0') { disable($target, $owner, data); } }; diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable.js index 873eea97958..01d241a0e36 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/disable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find('label[for="' + $target.find(data.enableBml).attr('id') + '"]').removeClass('enabled'); $target.find(data.enableBml + ' option[value="0"]').prop('selected', true); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable-conditional.js index f5d796397c7..77d3e28aa72 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable-conditional.js @@ -2,18 +2,21 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -define([], function () { - "use strict"; +define(['underscore'], function (_) { + 'use strict'; + return function ($target, $owner, data) { var isDisabled = true; _.every(data.argument, function (name) { - if (data.solutionsElements[name] - && data.solutionsElements[name].find(data.enableButton).val() == 1 + if (data.solutionsElements[name] && + data.solutionsElements[name].find(data.enableButton).val() == 1 ) { isDisabled = false; + return isDisabled; } + return isDisabled; }, this); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable.js index e7710d80cf0..3ddfc3b0f60 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/enable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find(data.enableBml).prop('disabled', false); $target.find(data.enableBml + ' option[value="1"]').prop('selected', true); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/lock-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/lock-conditional.js index 09007924b0b..607c56984e7 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/lock-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/bml/lock-conditional.js @@ -3,9 +3,10 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { - if ($target.find(data.enableButton).val() == "0") { + if ($target.find(data.enableButton).val() === '0') { $target.find(data.enableBml).prop('disabled', true); } }; diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable-conditional.js index f37306731b8..94b178c0716 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable-conditional.js @@ -5,9 +5,10 @@ define([ 'Magento_Paypal/js/rules/payflow/express/disable' ], function (disableExpress) { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { - if ($target.find(data.enableButton).val() == "0") { + if ($target.find(data.enableButton).val() === '0') { disableExpress($target, $owner, data); $target.find(data.enableExpress).change(); } diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable.js index 4d8b6fa3ca3..77649695f3c 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/disable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find('label[for="' + $target.find(data.enableExpress).attr('id') + '"]').removeClass('enabled'); $target.find(data.enableExpress + ' option[value="0"]').prop('selected', true); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable-conditional.js index cc76875080a..ea9fc5f2d0c 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable-conditional.js @@ -2,18 +2,21 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -define([], function () { - "use strict"; +define(['underscore'], function (_) { + 'use strict'; + return function ($target, $owner, data) { var isDisabled = true; _.every(data.argument, function (name) { - if (data.solutionsElements[name] - && data.solutionsElements[name].find(data.enableButton).val() == 1 + if (data.solutionsElements[name] && + data.solutionsElements[name].find(data.enableButton).val() === '1' ) { isDisabled = false; + return isDisabled; } + return isDisabled; }, this); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable.js index 456b4a6ac78..6dc1a0a49cf 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/enable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find(data.enableExpress).prop('disabled', false); $target.find(data.enableExpress + ' option[value="1"]').prop('selected', true); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/lock-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/lock-conditional.js index 476af3b5836..c07a0b5cf71 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/lock-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/payflow/express/lock-conditional.js @@ -3,9 +3,10 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { - if ($target.find(data.enableButton).val() == "0") { + if ($target.find(data.enableButton).val() === '0') { $target.find(data.enableExpress).prop('disabled', true); } }; diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable-conditional.js index ed327a4678f..d4b8d4100e5 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable-conditional.js @@ -5,9 +5,10 @@ define([ 'Magento_Paypal/js/rules/paypal/bml/disable' ], function (disable) { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { - if ($target.find(data.enableButton).val() == "0") { + if ($target.find(data.enableButton).val() === '0') { disable($target, $owner, data); } }; diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable.js index 124c325c445..c6ef93d332f 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/disable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find('label[for="' + $target.find(data.enableBmlPayPal).attr('id') + '"]').removeClass('enabled'); $target.find(data.enableBmlPayPal + ' option[value="0"]').prop('selected', true); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/enable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/enable.js index 1beb826bf39..90f7561734f 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/enable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/bml/enable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find(data.enableBmlPayPal).prop('disabled', false); $target.find(data.enableBmlPayPal + ' option[value="1"]').prop('selected', true); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/disable.js index 8421803de67..25e7b611a24 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/disable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find(data.enableButton + ' option[value="0"]').prop('selected', true); $target.find('label.enabled').removeClass('enabled'); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration-conditional.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration-conditional.js index bd2c2f62a29..55a82e3cc19 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration-conditional.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration-conditional.js @@ -3,19 +3,23 @@ * See COPYING.txt for license details. */ define([ - 'Magento_Paypal/js/rules/paypal/express/lock-configuration' -], function (lockConfiguration) { - "use strict"; + 'Magento_Paypal/js/rules/paypal/express/lock-configuration', + 'underscore' +], function (lockConfiguration, _) { + 'use strict'; + return function ($target, $owner, data) { var isDisabled = true; _.every(data.argument, function (name) { - if (data.solutionsElements[name] - && data.solutionsElements[name].find(data.enableButton).val() == 1 + if (data.solutionsElements[name] && + data.solutionsElements[name].find(data.enableButton).val() === '1' ) { isDisabled = false; + return isDisabled; } + return isDisabled; }, this); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration.js index e549bda0adf..351f799b57b 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/lock-configuration.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find(data.buttonConfiguration).addClass('disabled') .attr('disabled', 'disabled'); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/mark-disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/mark-disable.js index 6bcf9a559b3..7943c843b13 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/mark-disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/mark-disable.js @@ -3,19 +3,23 @@ * See COPYING.txt for license details. */ define([ - 'Magento_Paypal/js/rules/simple/disable' -], function (disable) { - "use strict"; + 'Magento_Paypal/js/rules/simple/disable', + 'underscore' +], function (disable, _) { + 'use strict'; + return function ($target, $owner, data) { var isDisabled = true; _.every(data.argument, function (name) { - if (data.solutionsElements[name] - && data.solutionsElements[name].find(data.enableButton).val() == 1 + if (data.solutionsElements[name] && + data.solutionsElements[name].find(data.enableButton).val() === '1' ) { isDisabled = false; + return isDisabled; } + return isDisabled; }, this); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/unlock-configuration.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/unlock-configuration.js index 413a8bf08b1..a13142e359e 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/unlock-configuration.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/paypal/express/unlock-configuration.js @@ -2,18 +2,21 @@ * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ -define([], function () { - "use strict"; +define(['underscore'], function (_) { + 'use strict'; + return function ($target, $owner, data) { var isUnlock = true; _.every(data.argument, function (name) { - if (data.solutionsElements[name] - && data.solutionsElements[name].find(data.enableButton).val() == 1 + if (data.solutionsElements[name] && + data.solutionsElements[name].find(data.enableButton).val() == 1 ) { isUnlock = false; + return isUnlock; } + return isUnlock; }, this); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/disable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/disable.js index 4b7c4234dd3..7531d4fae1a 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/disable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/disable.js @@ -3,7 +3,8 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; + 'use strict'; + return function ($target, $owner, data) { $target.find(data.enableButton + ' option[value="0"]').prop('selected', true); $target.find('label.enabled').removeClass('enabled'); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/mark-enable.js b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/mark-enable.js index b686f1be7c9..1dec21bb5b4 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/mark-enable.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/rules/simple/mark-enable.js @@ -3,8 +3,9 @@ * See COPYING.txt for license details. */ define([], function () { - "use strict"; - return function ($target, $owner, data) { + 'use strict'; + + return function ($target) { $target.find('.section-config').addClass('enabled'); }; }); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/solution.js b/app/code/Magento/Paypal/view/adminhtml/web/js/solution.js index 787d9e066cd..4f8de68474d 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/solution.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/solution.js @@ -3,39 +3,47 @@ * See COPYING.txt for license details. */ define([ - "jquery", - "uiClass", - "Magento_Paypal/js/rule", - "mageUtils", - "underscore" + 'jquery', + 'uiClass', + 'Magento_Paypal/js/rule', + 'mageUtils', + 'underscore' ], function ($, Class, Rule, utils, _) { - "use strict"; + 'use strict'; + return Class.extend({ defaults: { + /** * The event corresponding to the state change */ systemEvent: 'change', + /** * The rules applied after the page is loaded */ afterLoadRules: [], + /** * An attribute of the element responsible for the activation of the payment method (data attribute) */ enableButton: '[data-enable="payment"]', + /** * An attribute of the element responsible for the activation of the Payflow Express (data attribute) */ enableExpress: '[data-enable="express"]', + /** * An attribute of the element responsible for the activation of the Payflow Bml (data attribute) */ enableBml: '[data-enable="bml"]', + /** * An attribute of the element responsible for the activation of the PayPal Bml (data attribute) */ enableBmlPayPal: '[data-enable="bml-api"]', + /** * Templates element selectors */ @@ -43,100 +51,149 @@ define([ elementSelector: 'div.section-config tr[id$="${ $.identifier }"]:first' } }, + /** * Constructor + * + * @param {Object} config + * @param {String} identifier + * @returns {exports.initialize} */ initialize: function (config, identifier) { this.initConfig(config); this.$self = this.createElement(identifier); + return this; }, + /** * Initialization events + * + * @returns {exports.initEvents} */ initEvents: function () { _.each(this.config.events, function (elementEvents, selector) { + var solution = this, selectorButton = solution.$self.find(selector), $self = solution.$self, events = elementEvents; - selectorButton.on(solution.systemEvent, function (event) { + + selectorButton.on(solution.systemEvent, function () { _.each(events, function (elementEvent, name) { + var predicate = elementEvent.predicate, - result = true; + result = true, + + /** + * @param {Function} functionPredicate + */ + predicateCallback = function (functionPredicate) { + result = functionPredicate(solution, predicate.message, predicate.argument); + + if (result) { + $self.trigger(name); + } else { + $self.trigger(predicate.event); + } + }; + if (solution.getValue($(this)) === elementEvent.value) { if (predicate.name) { require([ 'Magento_Paypal/js/predicate/' + predicate.name - ], function (functionPredicate) { - result = functionPredicate(solution, predicate.message, predicate.argument); - if (result) { - $self.trigger(name); - } else { - $self.trigger(predicate.event); - } - }); + ], predicateCallback); } else { $self.trigger(name); } - } + } }, this); - }); + }); }, this); + return this; }, + /** + * @param {Object} $element + * @returns {*} + */ getValue: function ($element) { if ($element.is(':checkbox')) { return $element.prop('checked') ? '1' : '0'; } + return $element.val(); }, + /** * Adding event listeners + * + * @returns {exports.addListeners} */ addListeners: function () { + _.each(this.config.relations, function (rules, targetName) { + var $target = this.createElement(targetName); - _.each(rules, function (rule, name) { - var handler = new Rule({ - name :name, - $target: $target, - $owner: this.$self, - data: { - buttonConfiguration: this.buttonConfiguration, - enableButton: this.enableButton, - enableExpress: this.enableExpress, - enableBml: this.enableBml, - enableBmlPayPal: this.enableBmlPayPal, - solutionsElements: this.solutionsElements, - argument: rule.argument + + _.each(rules, function (instances, instanceName) { + + _.each(instances, function (instance) { + var handler = new Rule({ + name: instanceName, + $target: $target, + $owner: this.$self, + data: { + buttonConfiguration: this.buttonConfiguration, + enableButton: this.enableButton, + enableExpress: this.enableExpress, + enableBml: this.enableBml, + enableBmlPayPal: this.enableBmlPayPal, + solutionsElements: this.solutionsElements, + argument: instance.argument + } + }); + + if (instance.event === ':load') { + this.afterLoadRules.push(handler); + + return; } - }); - if (rule.event === ':load') { - this.afterLoadRules.push(handler); - return; - } - this.$self.on(rule.event, _.bind(handler.apply, handler)); + + this.$self.on(instance.event, _.bind(handler.apply, handler)); + }, this); }, this); }, this); + return this; }, + /** * Create a jQuery element according to selector + * + * @param {String} identifier + * @returns {*} */ createElement: function (identifier) { - if (':self' === identifier) { + if (identifier === ':self') { return this.$self; } - var selector = utils.template(this.templates.elementSelector, {identifier: identifier}); - return $(selector); + + return $(utils.template(this.templates.elementSelector, { + 'identifier': identifier + })); }, + /** * Assign solutions elements + * + * @param {Object} elements + * @returns {exports.setSolutionsElements} */ setSolutionsElements: function (elements) { this.solutionsElements = elements; + return this; } }); diff --git a/app/code/Magento/Paypal/view/adminhtml/web/js/solutions.js b/app/code/Magento/Paypal/view/adminhtml/web/js/solutions.js index b1e124aca38..f92a531e914 100644 --- a/app/code/Magento/Paypal/view/adminhtml/web/js/solutions.js +++ b/app/code/Magento/Paypal/view/adminhtml/web/js/solutions.js @@ -3,47 +3,64 @@ * See COPYING.txt for license details. */ define([ - "jquery", - "uiClass", - "Magento_Paypal/js/solution", - "underscore" + 'jquery', + 'uiClass', + 'Magento_Paypal/js/solution', + 'underscore' ], function ($, Class, Solution, _) { - "use strict"; + 'use strict'; + return Class.extend({ defaults: { + /** * Initialized solutions */ solutions: {}, + /** * The elements of created solutions */ solutionsElements: {}, + /** * The selector element responsible for configuration of payment method (CSS class) */ buttonConfiguration: '.button.action-configure' }, + /** * Constructor + * + * @param {Object} config + * @returns {exports.initialize} */ initialize: function (config) { this.initConfig(config) .initSolutions(); + return this; }, + /** * Initialization and configuration solutions + * + * @returns {exports.initSolutions} */ initSolutions: function () { _.each(this.config.solutions, this.addSolution, this); this.initializeSolutions() .wipeButtonsConfiguration(); _.each(this.solutions, this.applicationRules); + return this; }, + /** * The creation and addition of the solution according to the configuration + * + * @param {Object} solution + * @param {String} identifier */ addSolution: function (solution, identifier) { this.solutions[identifier] = new Solution({ @@ -52,6 +69,7 @@ define([ }, identifier); this.solutionsElements[identifier] = this.solutions[identifier].$self; }, + /** * Wiping buttons configuration of the payment method */ @@ -59,16 +77,22 @@ define([ $(this.buttonConfiguration).removeClass('disabled') .removeAttr('disabled'); }, + /** * Application of the rules + * + * @param {Object} solution */ applicationRules: function (solution) { _.each(solution.afterLoadRules, function (rule) { rule.apply(); }); }, + /** * Initialize solutions + * + * @returns {exports.initializeSolutions} */ initializeSolutions: function () { _.each(this.solutions, function (solution) { @@ -76,6 +100,7 @@ define([ .initEvents() .addListeners(); }, this); + return this; } }); -- GitLab