diff --git a/app/code/Magento/Paypal/Model/Config/Rules/Converter.php b/app/code/Magento/Paypal/Model/Config/Rules/Converter.php index a636188baf1cf571ea572625e6de6dec367b640e..5528f79b385758a89b1c4c1fad3d2fa90e92b08e 100644 --- a/app/code/Magento/Paypal/Model/Config/Rules/Converter.php +++ b/app/code/Magento/Paypal/Model/Config/Rules/Converter.php @@ -58,8 +58,8 @@ class Converter implements ConverterInterface protected function createEvents(\DOMElement $node) { $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 +80,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 +105,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 +126,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 eb62d570481bde11725647a1ab54858c4ca96dcf..ffd2f141e0a0d7da9bc3f642e581e754d3324d6e 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 297d3c8e620a06480da9c009f1cfc59ae81d746f..4b4c6833d92c92399d29fae6e687472d24cbedfb 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 c187130b357b85e975b93c17f457b30c78bd5f0f..4b5acbe6e073e8259ff3a3b4364c7c5c7ef70fac 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 ea426368243185bc14ed8fded1b77387366dddb3..278b101c9c696aabe05c1c62a28d426ce399acaf 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 b565aa2d66d6b46c2165650567b06fe440291b4e..c1c12344cc54c15ededbd2bb0b80184b09be19fd 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 4d94f6a2a9ff63cdb9195b4bbdaf012f98ec4cf7..54b263be6421dcdd7534f811c7ef80a02be12e99 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:' + + 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 a5cc52ed96bc2b145d06a638cef1be7135ce920b..54e355580394b5437fb79b6d2ecc6e20be54e184 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 8fccdd054558b3e289fd79ec88c52fbb32dac7ce..e3d95340b8bfe534f1da36452b36dcc63bc2e4db 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 2c5ae4265342b266e9fe76d9b60994482e371a0e..20182ef0205f4135e853b77b3c937d17f59c66bc 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 873eea979583c30b3fdc10906b968b1c7a1fba00..01d241a0e36197981029a2cfa63eaf1399193967 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 f5d796397c705af56a476831d3710ff0c66f504b..9770d463f45fc676eeda339a9d7849368822f93f 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 e7710d80cf07fc84a6ee9769ee8bb4388c155921..3ddfc3b0f60446334670836e98fffcf2cdac2dd4 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 09007924b0b4bb53f90f968717766af6e5ba9d74..607c56984e7dc6f4047a20a55b8a262442bd69ba 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 f37306731b8857896fcade130783a5de86ccbe20..94b178c071642e09b80771094946ba7522541815 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 4d8b6fa3ca39918293381d36e23d1314304f1439..77649695f3c11394c98f95d7e50bd57d4857971a 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 cc76875080a4ee00e98e93c56b182982bd06e233..ea9fc5f2d0ccbe6741615fed4bb9cd5cb0c85b74 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 456b4a6ac78ddd8bc591653a45aaf247303f1d2a..6dc1a0a49cfba72168b9e0d69b067b9dab2fa380 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 476af3b58366a86ffef757addeb4230a4f0436de..c07a0b5cf713e2b7c65bda537e331e47980f6e37 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 ed327a4678fbc1db79bc1250cee0557aa06f9e5f..d4b8d4100e56d5e9e5e2ffc134ae79e6a5445859 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 124c325c445dce34969c7e02a4ad89455daedbcf..c6ef93d332fb64b102a4ec2ba30370e5cc61d384 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 1beb826bf39a003926868e7b420537a03686da50..90f7561734f14f34d21e126ba7df9d2d9926dadc 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 8421803de67a2e84fc1030fcb60ab6909547b814..25e7b611a24692ed05b544bb8bcf8e80b05862b3 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 bd2c2f62a29f5b20a08910fdf3e2504c584bfdff..55a82e3cc19322136dec33e5b6c14e41ec0525f8 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 e549bda0adf3db7d2a8e8f0f626a72097f96530c..351f799b57b28a3739d23f37cb46bc0afaedafe8 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 6bcf9a559b39a05e5d9a76ef35afb8e2b029d81a..7943c843b13cde484d9d0baf1149110ac4885754 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 413a8bf08b1d013bfc0c1b0d7f4d49beb25b2997..fda160c6d94f4babe5257180db769a37aa667537 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 4b7c4234dd3ede12113f544c9f3c76a3cd72ed41..7531d4fae1aaab06dc14f3ffd611b7bc63508e53 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 b686f1be7c949c484de9f9dc416611c4459fcb2b..1dec21bb5b4931c2109fe2c3ab4adec651c06c3d 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 787d9e066cdbe0234bb434f57d39919d00639181..4f8de68474d7a53dc3af22f5c73c12e4ce28ef98 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 b1e124aca387a556069a776721a90d0c529db62a..f92a531e91414da86c78fcc564d8accf96a32191 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; } });