Skip to content

Commit 3cd05e5

Browse files
committed
MAGETWO-89383: [UI Component] URL Input: External Link
1 parent 00806b2 commit 3cd05e5

File tree

6 files changed

+101
-10
lines changed

6 files changed

+101
-10
lines changed

app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@
421421
<item name="settingLabel" type="string" translate="true" xsi:type="xpath">settings/settingLabel</item>
422422
<item name="typeSelectorTemplate" type="string" translate="true" xsi:type="xpath">settings/typeSelectorTemplate</item>
423423
<item name="settingTemplate" type="string" translate="true" xsi:type="xpath">settings/settingTemplate</item>
424+
<item name="settingValue" type="boolean" xsi:type="xpath">settings/settingValue</item>
424425
</item>
425426
</argument>
426427
</schema>

app/code/Magento/Ui/view/base/ui_component/etc/definition/urlInput.xsd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@
6262
</xs:documentation>
6363
</xs:annotation>
6464
</xs:element>
65+
<xs:element name="settingValue" type="xs:boolean">
66+
<xs:annotation>
67+
<xs:documentation>
68+
Allows to specify default value for setting
69+
</xs:documentation>
70+
</xs:annotation>
71+
</xs:element>
6572
</xs:choice>
6673
</xs:group>
6774
</xs:schema>

app/code/Magento/Ui/view/base/web/js/form/element/url-input.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ define([
3636
}
3737
},
3838
listens: {
39-
checked: 'settingValue',
40-
disabled: 'hideLinkedElement',
4139
settingValue: 'checked',
40+
disabled: 'hideLinkedElement',
4241
linkType: 'createChildUrlInputComponent'
4342
},
4443
links: {
@@ -78,6 +77,7 @@ define([
7877
baseLinkType = this.urlTypes.base;
7978

8079
delete this.urlTypes.base;
80+
console.log(this);
8181
_.each(this.urlTypes, function (linkSettingsArray, linkName) {
8282
//add link name by link type
8383
linkSettingsArray.name = baseLinkType.namePrefix + linkName;
@@ -170,7 +170,7 @@ define([
170170
*/
171171
checkboxClick: function () {
172172
if (!this.disabled()) {
173-
this.checked(!this.checked());
173+
this.settingValue(!this.settingValue());
174174
}
175175
}
176176
});

app/code/Magento/Ui/view/base/web/templates/form/element/urlInput/setting.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<div class="admin__field admin__field-option url-input-setting" visible="visible" click="checkboxClick">
99
<input type="checkbox"
1010
class="admin__control-checkbox"
11-
ko-checked="$data.checked"
11+
ko-checked="settingValue"
1212
disable="disabled"
1313
ko-value="settingValue"
1414
hasFocus="focused"

app/design/adminhtml/Magento/backend/web/css/source/components/_url_input.less

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
min-width: 7.5em;
1515
}
1616

17+
18+
.url-input-element-linked-element {
19+
float: left;
20+
margin-left: 1.5em;
21+
width: calc(~'100% - 9em');
22+
}
23+
1724
.url-input-setting {
1825
clear: both;
1926
display: block;
@@ -22,10 +29,4 @@
2229
clear: both;
2330
}
2431
}
25-
26-
.url-input-element-linked-element {
27-
float: left;
28-
margin-left: 1.5em;
29-
width: calc(~'100% - 9em');
30-
}
3132
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
/*eslint max-nested-callbacks: 0*/
7+
8+
define([
9+
'jquery',
10+
'Magento_Ui/js/form/element/url-input',
11+
], function ($, UrlInput) {
12+
'use strict';
13+
14+
describe('Magento_Ui/js/form/element/url-input', function () {
15+
var component;
16+
17+
beforeEach(function () {
18+
var params = {
19+
dataScope: 'urlInput',
20+
urlTypes: {
21+
base: {
22+
namePrefix: '${$.name}.',
23+
dataScopePrefix: '${$.dataScope}.',
24+
provider: '${$.provider}'
25+
},
26+
url: {
27+
label: 'Test label',
28+
component: 'Magento_Ui/js/form/element/abstract',
29+
template: 'ui/form/element/input',
30+
sortOrder: 40
31+
},
32+
testUrl: {
33+
label: 'Test label 2',
34+
component: 'Magento_Ui/js/form/element/abstract',
35+
template: 'ui/form/element/input',
36+
sortOrder: 10
37+
}
38+
}
39+
};
40+
41+
component = new UrlInput(params);
42+
});
43+
44+
describe('processLinkTypes method', function () {
45+
it('check url types were set', function () {
46+
expect(component.urlTypes).toBeDefined();
47+
expect(component.urlTypes.hasOwnProperty('url'));
48+
expect(component.urlTypes.hasOwnProperty('testUrl'));
49+
expect(component.urlTypes.base).not.toBeDefined();
50+
});
51+
});
52+
53+
describe('setOptions method', function () {
54+
it('check that optons were set', function () {
55+
var expectedOptions = [
56+
{
57+
value: 'testUrl',
58+
label: 'Test label 2',
59+
sortOrder: 10
60+
},
61+
{
62+
value: 'url',
63+
label: 'Test label',
64+
sortOrder: 40
65+
}
66+
];
67+
68+
expect(component.options()).toEqual(expectedOptions);
69+
});
70+
});
71+
72+
describe('createChildUrlInputComponent method', function () {
73+
it('check linked element was set', function () {
74+
expect(component.linkedElementInstances.url).not.toBeDefined();
75+
component.createChildUrlInputComponent('url');
76+
expect(component.linkedElementInstances.url).toBeDefined();
77+
expect(component.getLinkedElementName()).toEqual(component.linkedElementInstances.url);
78+
});
79+
});
80+
81+
});
82+
});

0 commit comments

Comments
 (0)