123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- define([
- 'uiClass',
- 'Magento_Ui/js/modal/alert'
- ], function (Class, alert) {
- 'use strict';
- /**
- * Check is solution enabled
- *
- * @param {*} solution
- * @param {String} enabler
- * @returns {Boolean}
- */
- var isSolutionEnabled = function (solution, enabler) {
- return solution.find(enabler).val() === '1';
- },
- /**
- * Check is solution has related solutions enabled
- *
- * @param {Object} data
- * @returns {Boolean}
- */
- hasRelationsEnabled = function (data) {
- var name;
- for (name in data.argument) {
- if (
- data.solutionsElements[name] &&
- isSolutionEnabled(data.solutionsElements[name], data.enableButton)
- ) {
- return true;
- }
- }
- return false;
- },
- /**
- * Set solution select-enabler to certain option
- *
- * @param {*} solution
- * @param {String} enabler
- * @param {Boolean} enabled
- */
- setSolutionSelectEnabled = function (solution, enabler, enabled) {
- enabled = !(enabled || typeof enabled === 'undefined') ? '0' : '1';
- solution.find(enabler + ' option[value=' + enabled + ']')
- .prop('selected', true);
- },
- /**
- * Set solution property 'disabled' value
- *
- * @param {*} solution
- * @param {String} enabler
- * @param {Boolean} enabled
- */
- setSolutionPropEnabled = function (solution, enabler, enabled) {
- enabled = !(enabled || typeof enabled === 'undefined');
- solution.find(enabler).prop('disabled', enabled);
- },
- /**
- * Set/unset solution select-enabler label
- *
- * @param {*} solution
- * @param {String} enabler
- * @param {Boolean} enabled
- */
- setSolutionMarkEnabled = function (solution, enabler, enabled) {
- var solutionEnabler = solution.find('label[for="' + solution.find(enabler).attr('id') + '"]');
- enabled || typeof enabled === 'undefined' ?
- solutionEnabler.addClass('enabled') :
- solutionEnabler.removeClass('enabled');
- },
- /**
- * Set/unset solution section label
- *
- * @param {*} solution
- * @param {Boolean} enabled
- */
- setSolutionSectionMarkEnabled = function (solution, enabled) {
- var solutionSection = solution.find('.section-config');
- enabled || typeof enabled === 'undefined' ?
- solutionSection.addClass('enabled') :
- solutionSection.removeClass('enabled');
- },
- /**
- * Set/unset solution section inner labels
- *
- * @param {*} solution
- * @param {Boolean} enabled
- */
- setSolutionLabelsMarkEnabled = function (solution, enabled) {
- var solutionLabels = solution.find('label.enabled');
- enabled || typeof enabled === 'undefined' ?
- solutionLabels.addClass('enabled') :
- solutionLabels.removeClass('enabled');
- },
- /**
- * Set/unset solution usedefault checkbox
- *
- * @param {*} solution
- * @param {String} enabler
- * @param {Boolean} checked
- */
- setSolutionUsedefaultEnabled = function (solution, enabler, checked) {
- checked = !(checked || typeof checked === 'undefined');
- solution.find('input[id="' + solution.find(enabler).attr('id') + '_inherit"]')
- .prop('checked', checked);
- },
- /**
- * Set solution as disabled
- *
- * @param {*} solution
- * @param {String} enabler
- */
- disableSolution = function (solution, enabler) {
- setSolutionUsedefaultEnabled(solution, enabler);
- setSolutionMarkEnabled(solution, enabler, false);
- setSolutionSelectEnabled(solution, enabler, false);
- setSolutionPropEnabled(solution, enabler, false);
- },
- /**
- * Set solution as enabled
- *
- * @param {*} solution
- * @param {String} enabler
- */
- enableSolution = function (solution, enabler) {
- setSolutionUsedefaultEnabled(solution, enabler);
- setSolutionPropEnabled(solution, enabler);
- setSolutionSelectEnabled(solution, enabler);
- setSolutionMarkEnabled(solution, enabler);
- },
- /**
- * Lock/unlock solution configuration button
- *
- * @param {*} solution
- * @param {String} buttonConfiguration
- * @param {Boolean} unlock
- */
- setSolutionConfigurationUnlock = function (solution, buttonConfiguration, unlock) {
- var solutionConfiguration = solution.find(buttonConfiguration);
- unlock || typeof unlock === 'undefined' ?
- solutionConfiguration.removeClass('disabled').removeAttr('disabled') :
- solutionConfiguration.addClass('disabled').attr('disabled', 'disabled');
- },
- /**
- * Forward solution select-enabler changes
- *
- * @param {*} solution
- * @param {String} enabler
- */
- forwardSolutionChange = function (solution, enabler) {
- solution.find(enabler).change();
- },
- /**
- * Show/hide dependent fields
- *
- * @param {*} solution
- * @param {String} identifier
- * @param {Boolean} show
- */
- showDependsField = function (solution, identifier, show) {
- show = show || typeof show === 'undefined';
- solution.find(identifier).toggle(show);
- solution.find(identifier).closest('tr').toggle(show);
- solution.find(identifier).attr('disabled', !show);
- };
- return Class.extend({
- defaults: {
- /**
- * Payment conflicts checker
- */
- executed: false
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- simpleDisable: function ($target, $owner, data) {
- setSolutionSelectEnabled($target, data.enableButton, false);
- setSolutionLabelsMarkEnabled($target, false);
- setSolutionSectionMarkEnabled($target, false);
- },
- /**
- * @param {*} $target
- */
- simpleMarkEnable: function ($target) {
- setSolutionSectionMarkEnabled($target);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- disable: function ($target, $owner, data) {
- this.simpleDisable($target, $owner, data);
- forwardSolutionChange($target, data.enableButton);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalExpressDisable: function ($target, $owner, data) {
- setSolutionSelectEnabled($target, data.enableButton, false);
- setSolutionLabelsMarkEnabled($target, false);
- forwardSolutionChange($target, data.enableButton);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalExpressLockConfiguration: function ($target, $owner, data) {
- setSolutionConfigurationUnlock($target, data.buttonConfiguration, false);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalExpressLockConfigurationConditional: function ($target, $owner, data) {
- if (
- !isSolutionEnabled($target, data.enableInContextPayPal) &&
- hasRelationsEnabled(data)
- ) {
- this.paypalExpressLockConfiguration($target, $owner, data);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalExpressMarkDisable: function ($target, $owner, data) {
- if (!hasRelationsEnabled(data)) {
- this.simpleDisable($target, $owner, data);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalExpressUnlockConfiguration: function ($target, $owner, data) {
- if (!hasRelationsEnabled(data)) {
- setSolutionConfigurationUnlock($target, data.buttonConfiguration);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalBmlDisable: function ($target, $owner, data) {
- disableSolution($target, data.enableBmlPayPal);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalBmlDisableConditional: function ($target, $owner, data) {
- if (!isSolutionEnabled($target, data.enableButton)) {
- this.paypalBmlDisable($target, $owner, data);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalBmlEnable: function ($target, $owner, data) {
- enableSolution($target, data.enableBmlPayPal);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressDisable: function ($target, $owner, data) {
- disableSolution($target, data.enableExpress);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressDisableConditional: function ($target, $owner, data) {
- if (
- !isSolutionEnabled($target, data.enableButton) ||
- hasRelationsEnabled(data)
- ) {
- this.payflowExpressDisable($target, $owner, data);
- forwardSolutionChange($target, data.enableExpress);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressEnable: function ($target, $owner, data) {
- enableSolution($target, data.enableExpress);
- forwardSolutionChange($target, data.enableExpress);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressEnableConditional: function ($target, $owner, data) {
- if (hasRelationsEnabled(data)) {
- setSolutionPropEnabled($target, data.enableExpress, false);
- setSolutionSelectEnabled($target, data.enableExpress);
- setSolutionMarkEnabled($target, data.enableExpress);
- } else {
- disableSolution($target, data.enableExpress);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressLockConditional: function ($target, $owner, data) {
- if (!isSolutionEnabled($target, data.enableButton)) {
- setSolutionPropEnabled($target, data.enableExpress, false);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressUsedefaultDisable: function ($target, $owner, data) {
- setSolutionUsedefaultEnabled($target, data.enableExpress, false);
- this.payflowExpressEnable($target, $owner, data);
- forwardSolutionChange($target, data.enableExpress);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowExpressUsedefaultEnable: function ($target, $owner, data) {
- setSolutionUsedefaultEnabled($target, data.enableExpress);
- this.payflowExpressDisable($target, $owner, data);
- forwardSolutionChange($target, data.enableExpress);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowBmlDisable: function ($target, $owner, data) {
- disableSolution($target, data.enableBml);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowBmlDisableConditional: function ($target, $owner, data) {
- if (
- !isSolutionEnabled($target, data.enableButton) ||
- hasRelationsEnabled(data)
- ) {
- this.payflowBmlDisable($target, $owner, data);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowBmlDisableConditionalExpress: function ($target, $owner, data) {
- if (!isSolutionEnabled($target, data.enableExpress)) {
- this.payflowBmlDisable($target, $owner, data);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowBmlEnable: function ($target, $owner, data) {
- enableSolution($target, data.enableBml);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowBmlEnableConditional: function ($target, $owner, data) {
- if (hasRelationsEnabled(data)) {
- setSolutionPropEnabled($target, data.enableBml, false);
- setSolutionSelectEnabled($target, data.enableBml);
- setSolutionMarkEnabled($target, data.enableBml);
- } else {
- disableSolution($target, data.enableBml);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowBmlLockConditional: function ($target, $owner, data) {
- if (!isSolutionEnabled($target, data.enableButton)) {
- setSolutionPropEnabled($target, data.enableBml, false);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextEnable: function ($target, $owner, data) {
- enableSolution($target, data.enableInContextPayPal);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextDisable: function ($target, $owner, data) {
- disableSolution($target, data.enableInContextPayPal);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextShowMerchantId: function ($target, $owner, data) {
- showDependsField($target, data.dependsMerchantId);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextHideMerchantId: function ($target, $owner, data) {
- showDependsField($target, data.dependsMerchantId, false);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowShowSortOrder: function ($target, $owner, data) {
- showDependsField($target, data.dependsBmlSortOrder);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- payflowHideSortOrder: function ($target, $owner, data) {
- showDependsField($target, data.dependsBmlSortOrder, false);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalShowSortOrder: function ($target, $owner, data) {
- showDependsField($target, data.dependsBmlApiSortOrder);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- paypalHideSortOrder: function ($target, $owner, data) {
- showDependsField($target, data.dependsBmlApiSortOrder, false);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextActivate: function ($target, $owner, data) {
- setSolutionMarkEnabled($target, data.enableInContextPayPal);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextDeactivate: function ($target, $owner, data) {
- setSolutionMarkEnabled($target, data.enableInContextPayPal, false);
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- inContextDisableConditional: function ($target, $owner, data) {
- if (!isSolutionEnabled($target, data.enableButton)) {
- this.inContextDisable($target, $owner, data);
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- conflict: function ($target, $owner, data) {
- var newLine = String.fromCharCode(10, 13);
- if (
- isSolutionEnabled($owner, data.enableButton) &&
- hasRelationsEnabled(data) &&
- !this.executed
- ) {
- this.executed = true;
- alert({
- content: 'The following error(s) occurred:' +
- newLine +
- 'Some PayPal solutions conflict.' +
- newLine +
- 'Please re-enable the previously enabled payment solutions.'
- });
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- removeCreditOption: function ($target, $owner, data) {
- if ($target.find(data.dependsButtonLabel + ' option[value="credit"]').length > 0) {
- $target.find(data.dependsButtonLabel + ' option[value="credit"]').remove();
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- addCreditOption: function ($target, $owner, data) {
- if ($target.find(data.dependsButtonLabel + ' option[value="credit"]').length === 0) {
- $target.find(data.dependsButtonLabel).append('<option value="credit">Credit</option>');
- }
- },
- /**
- * @param {*} $target
- * @param {*} $owner
- * @param {Object} data
- */
- removeCreditOptionConditional: function ($target, $owner, data) {
- if ($target.find(data.dependsDisableFundingOptions + ' option[value="CREDIT"]').length === 0 ||
- $target.find(data.dependsDisableFundingOptions + ' option[value="CREDIT"]:selected').length > 0
- ) {
- this.removeCreditOption($target, $owner, data);
- }
- }
- });
- });
|