Skip to content

Commit bde8a63

Browse files
author
Ivan Tagil
committed
CMP-42 - CR Fixes
1 parent 9c15047 commit bde8a63

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

Block/Adminhtml/System/Config/Fieldset/ApiDetails.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,16 @@
1414
class ApiDetails extends Fieldset
1515
{
1616
/**
17-
* Return extra Js
17+
* Return header html for fieldset
1818
*
1919
* @param AbstractElement $element
2020
* @return string
2121
*/
22-
protected function _getExtraJs($element)
22+
protected function _getHeaderHtml($element)
2323
{
24-
$initialScript = parent::_getExtraJs($element);
25-
$extendedScript = "require(['jquery'], function ($) {
26-
$('#cm_payments_general_api_details_mode').change(function () {
27-
let modeContainerId = $(this).closest('tr').attr('id'),
28-
parentTable = $(this).parents().find('table'),
29-
mode = $(this).val();
30-
parentTable.find('tr').each(function () {
31-
let containerId = $(this).attr('id');
32-
if (containerId !== modeContainerId) {
33-
if (containerId.indexOf('_' + mode + '_') == -1) {
34-
$(this).hide();
35-
} else {
36-
$(this).show();
37-
}
38-
}
39-
});
40-
});
41-
42-
$('#cm_payments_general_api_details_mode').trigger('change');
43-
});";
44-
45-
return $initialScript . $this->_jsHelper->getScript($extendedScript);
24+
return parent::_getHeaderHtml($element) .
25+
'<div class="api-details-extra" ' .
26+
'data-mage-init=\'{"CM_Payments/js/system/action/api-details-config":' .
27+
'{"modeContainerSelector": "#cm_payments_general_api_details_mode"}}\'></div>';
4628
}
4729
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright © CM.com. All rights reserved.
3+
* See LICENSE.txt for license details.
4+
*/
5+
define([
6+
'uiComponent',
7+
'jquery'
8+
], function (
9+
Component,
10+
$
11+
) {
12+
'use strict';
13+
14+
return Component.extend({
15+
modeContainerSelector: null,
16+
17+
/**
18+
* Initialization of component
19+
*
20+
* @returns {Object}
21+
*/
22+
initialize: function () {
23+
this._super();
24+
$(this.modeContainerSelector).change(this.changeApiDetailsMode);
25+
$(this.modeContainerSelector).trigger('change');
26+
27+
return this;
28+
},
29+
30+
/**
31+
* Changing of API Details Mode
32+
*/
33+
changeApiDetailsMode: function () {
34+
let modeContainerId = $(this).closest('tr').attr('id'),
35+
parentTable = $(this).parents().find('table'),
36+
mode = $(this).val();
37+
parentTable.find('tr').each(function () {
38+
let containerId = $(this).attr('id');
39+
if (containerId !== modeContainerId) {
40+
if (containerId.indexOf('_' + mode + '_') == -1) {
41+
$(this).hide();
42+
} else {
43+
$(this).show();
44+
}
45+
}
46+
});
47+
}
48+
});
49+
})

view/adminhtml/web/js/system/action/check-api-connection.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@ define([
1212
$,
1313
alert
1414
) {
15+
'use strict';
16+
1517
return Component.extend({
1618
wrapperContainerSelector: null,
1719
modeContainerSelector: null,
1820
checkApiConnectionUrl: null,
1921
resultContainerSelector: null,
2022

23+
/**
24+
* Check API Connection function
25+
*/
2126
checkApiConnection: function () {
2227
let mode = $(this.modeContainerSelector).val(),
2328
merchant_name = $('#cm_payments_general_api_details_' + mode + '_merchant_name').val(),
24-
merchant_password = $('#cm_payments_general_api_details_' + mode + '_merchant_password').val(),
29+
merchant_password = $('#cm_payments_general_api_details_' + mode + '_merchant_password').val(),
2530
merchant_key = $('#cm_payments_general_api_details_' + mode + '_merchant_key').val(),
2631
container = $(this.wrapperContainerSelector),
2732
result = $(this.resultContainerSelector),

0 commit comments

Comments
 (0)