Skip to content

Commit dcfa034

Browse files
author
Andrii Lugovyi
committed
MAGETWO-43891: Expanded 'Downloadable Information' tab with active 'Is this downloadable Product?' checkbox if create virtual product
- fix js static
1 parent 880edc7 commit dcfa034

File tree

6 files changed

+175
-37
lines changed

6 files changed

+175
-37
lines changed

app/code/Magento/Bundle/view/adminhtml/web/js/bundle-type-handler.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,36 @@ define([
77
'jquery',
88
'Magento_Catalog/catalog/type-events',
99
'Magento_Catalog/js/product/weight-handler'
10-
], function($, productType, weight){
11-
"use strict";
10+
], function ($, productType, weight) {
11+
'use strict';
1212

1313
return {
14-
'Magento_Bundle/js/bundle-type-handler': function(data) {
14+
15+
/**
16+
* Constructor component
17+
*/
18+
'Magento_Bundle/js/bundle-type-handler': function () {
1519
this.bindAll();
1620
this._initType();
1721
},
22+
23+
/**
24+
* Bind all
25+
*/
1826
bindAll: function () {
1927
$(document).on('changeTypeProduct', this._initType.bind(this));
2028
},
29+
30+
/**
31+
* Init type
32+
* @private
33+
*/
2134
_initType: function () {
22-
if (productType.type.real == 'bundle'
23-
&& productType.type.current != 'bundle' && !weight.isLocked()) {
35+
if (
36+
productType.type.real === 'bundle' &&
37+
productType.type.current !== 'bundle' &&
38+
!weight.isLocked()
39+
) {
2440
weight.switchWeight();
2541
}
2642
}

app/code/Magento/Catalog/view/adminhtml/web/catalog/apply-to-type-switcher.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
* See COPYING.txt for license details.
44
*/
55
define([
6-
"jquery",
6+
'jquery',
77
'Magento_Catalog/js/product/weight-handler',
88
'Magento_Catalog/catalog/type-events'
9-
], function($, weight, productType) {
9+
], function ($, weight, productType) {
10+
'use strict';
1011

1112
return {
13+
1214
/**
1315
* Bind event
1416
*/
@@ -18,14 +20,17 @@ define([
1820
this._switchToTypeByApplyAttr.bind(this)
1921
);
2022

21-
$("#product_info_tabs").on(
22-
"beforePanelsMove tabscreate tabsactivate",
23+
$('#product_info_tabs').on(
24+
'beforePanelsMove tabscreate tabsactivate',
2325
this._switchToTypeByApplyAttr.bind(this)
2426
);
2527

2628
$(document).on('changeTypeProduct', this._switchToTypeByApplyAttr.bind(this));
2729
},
2830

31+
/**
32+
* Constructor component
33+
*/
2934
'Magento_Catalog/catalog/apply-to-type-switcher': function () {
3035
this.bindAll();
3136
this._switchToTypeByApplyAttr();
@@ -36,11 +41,12 @@ define([
3641
*
3742
* @private
3843
*/
39-
_switchToTypeByApplyAttr: function() {
40-
$('[data-apply-to]:not(.removed)').each(function(index, element) {
44+
_switchToTypeByApplyAttr: function () {
45+
$('[data-apply-to]:not(.removed)').each(function (index, element) {
4146
var attrContainer = $(element),
42-
applyTo = attrContainer.data('applyTo') || [];
43-
var $inputs = attrContainer.find('select, input, textarea');
47+
applyTo = attrContainer.data('applyTo') || [],
48+
$inputs = attrContainer.find('select, input, textarea');
49+
4450
if (applyTo.length === 0 || $.inArray(productType.type.current, applyTo) !== -1) {
4551
attrContainer.removeClass('not-applicable-attribute');
4652
$inputs.removeClass('ignore-validate');

app/code/Magento/Catalog/view/adminhtml/web/catalog/type-events.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55
define([
66
'jquery',
77
'Magento_Catalog/js/product/weight-handler'
8-
], function($, weight) {
8+
], function ($, weight) {
9+
'use strict';
910

1011
return {
1112
$type: $('#product_type_id'),
13+
14+
/**
15+
* Init
16+
*/
1217
init: function () {
13-
//todo: need refactoring
18+
1419
if (weight.productHasWeight()) {
1520
this.type = {
1621
virtual: 'virtual',
@@ -26,20 +31,35 @@ define([
2631

2732
this.bindAll();
2833
},
34+
35+
/**
36+
* Bind all
37+
*/
2938
bindAll: function () {
3039
$(document).on('setTypeProduct', function (event, type) {
3140
this.setType(type);
3241
}.bind(this));
3342

3443
//direct change type input
35-
this.$type.on('change', function() {
44+
this.$type.on('change', function () {
3645
this.type.current = this.$type.val();
3746
this._notifyType();
3847
}.bind(this));
3948
},
49+
50+
/**
51+
* Set type
52+
* @param {String} type - type product (downloadable, simple, virtual ...)
53+
* @returns {*}
54+
*/
4055
setType: function (type) {
4156
return this.$type.val(type || this.type.real).trigger('change');
4257
},
58+
59+
/**
60+
* Notify type
61+
* @private
62+
*/
4363
_notifyType: function () {
4464
$(document).trigger('changeTypeProduct', this.type);
4565
}

app/code/Magento/Catalog/view/adminhtml/web/js/product/weight-handler.js

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,74 @@ define([
1919
hideWeightSwitcher: function () {
2020
this.$weightSwitcher.hide();
2121
},
22+
23+
/**
24+
* Is locked
25+
* @returns {*}
26+
*/
2227
isLocked: function () {
2328
return this.$weight.is('[data-locked]');
2429
},
30+
31+
/**
32+
* Disabled
33+
*/
2534
disabled: function () {
2635
this.$weight.addClass('ignore-validate').prop('disabled', true);
2736
},
37+
38+
/**
39+
* Enabled
40+
*/
2841
enabled: function () {
2942
this.$weight.removeClass('ignore-validate').prop('disabled', false);
3043
},
31-
switchWeight: function() {
44+
45+
/**
46+
* Switch Weight
47+
* @returns {*}
48+
*/
49+
switchWeight: function () {
3250
return this.productHasWeight() ? this.enabled() : this.disabled();
3351
},
52+
53+
/**
54+
* Product has weight
55+
* @returns {Bool}
56+
*/
3457
productHasWeight: function () {
35-
return $('input:checked', this.$weightSwitcher).val() == 1;
58+
return $('input:checked', this.$weightSwitcher).val() === '1';
3659
},
60+
61+
/**
62+
* Notify product weight is changed
63+
* @returns {*|jQuery}
64+
*/
3765
notifyProductWeightIsChanged: function () {
3866
return $('input:checked', this.$weightSwitcher).trigger('change');
3967
},
68+
69+
/**
70+
* Change
71+
* @param {String} data
72+
*/
4073
change: function (data) {
4174
var value = data !== undefined ? +data : !this.productHasWeight();
42-
$('input[value='+ value +']', this.$weightSwitcher).prop('checked', true);
75+
76+
$('input[value=' + value + ']', this.$weightSwitcher).prop('checked', true);
4377
},
78+
79+
/**
80+
* Constructor component
81+
*/
4482
'Magento_Catalog/js/product/weight-handler': function () {
4583
this.bindAll();
4684
this.switchWeight();
4785
},
86+
87+
/**
88+
* Bind all
89+
*/
4890
bindAll: function () {
4991
this.$weightSwitcher.find('input').on('change', this.switchWeight.bind(this));
5092
}

app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/configurable-type-handler.js

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@ define([
1111
'Magento_Ui/js/modal/modal',
1212
'mage/translate',
1313
'domReady!'
14-
], function($, productType, advancedPricingHandler, priceTypeHandler){
14+
], function ($, productType, advancedPricingHandler, priceTypeHandler) {
1515
'use strict';
1616

1717
return {
1818
$block: null,
1919
hasVariations: null,
20-
configurationSectionMessageHandler: (function() {
21-
var title = $('[data-role="product-create-configuration-info"]');
22-
var buttons = $('[data-action="product-create-configuration-buttons"]');
23-
var newText = 'Configurations cannot be created for a standard product with downloadable files.' +
24-
' To create configurations, first remove all downloadable files.';
25-
var oldText = title.text();
20+
configurationSectionMessageHandler: (function () {
21+
var title = $('[data-role="product-create-configuration-info"]'),
22+
buttons = $('[data-action="product-create-configuration-buttons"]'),
23+
newText = 'Configurations cannot be created for a standard product with downloadable files.' +
24+
' To create configurations, first remove all downloadable files.',
25+
oldText = title.text();
26+
2627
return function (change) {
2728
if (change) {
2829
title.text(newText);
@@ -31,8 +32,16 @@ define([
3132
title.text(oldText);
3233
buttons.show();
3334
}
34-
}.bind(this);
35+
};
3536
}()),
37+
38+
/**
39+
* Set element disabled
40+
* @param {Object} $element - jquery instance element
41+
* @param {Bool} state
42+
* @param {Bool} triggerEvent
43+
* @private
44+
*/
3645
_setElementDisabled: function ($element, state, triggerEvent) {
3746
if (!$element.is('[data-locked]')) {
3847
$element.prop('disabled', state);
@@ -42,20 +51,38 @@ define([
4251
}
4352
}
4453
},
54+
55+
/**
56+
* Show
57+
*/
4558
show: function () {
4659
this.configurationSectionMessageHandler(false);
4760
},
61+
62+
/**
63+
* Hide
64+
*/
4865
hide: function () {
4966
this.configurationSectionMessageHandler(true);
5067
},
68+
69+
/**
70+
* Bind all
71+
*/
5172
bindAll: function () {
5273
$(document).on('changeConfigurableTypeProduct', function (event, isConfigurable) {
5374
$(document).trigger('setTypeProduct', isConfigurable ? 'configurable' : null);
54-
}.bind(this));
75+
});
5576
$(document).on('changeTypeProduct', this._initType.bind(this));
5677
},
78+
79+
/**
80+
* Init type
81+
* @private
82+
*/
5783
_initType: function () {
5884
var suggestContainer = $('#product-template-suggest-container .action-dropdown > .action-toggle');
85+
5986
if (productType.type.current === 'configurable') {
6087
suggestContainer.addClass('disabled').prop('disabled', true);
6188
$('#inventory_qty').prop('disabled', true);
@@ -76,9 +103,14 @@ define([
76103
this.show();
77104
}
78105
},
79-
'Magento_ConfigurableProduct/js/configurable-type-handler': function (inData) {
80-
this.$block = $(inData.blockId + ' input[name="attributes[]"]');
81-
this.hasVariations = inData.hasVariations;
106+
107+
/**
108+
* Constructor component
109+
* @param {Object} data - this backend data
110+
*/
111+
'Magento_ConfigurableProduct/js/configurable-type-handler': function (data) {
112+
this.$block = $(data.blockId + ' input[name="attributes[]"]');
113+
this.hasVariations = data.hasVariations;
82114

83115
advancedPricingHandler.init();
84116
priceTypeHandler.init();

app/code/Magento/Downloadable/view/adminhtml/web/downloadable-type-handler.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,59 @@ define([
77
'jquery',
88
'Magento_Catalog/js/product/weight-handler',
99
'Magento_Catalog/catalog/type-events'
10-
], function($, weight, productType) {
11-
"use strict";
10+
], function ($, weight, productType) {
11+
'use strict';
1212

1313
return {
1414
$checkbox: $('[data-action=change-type-product-downloadable]'),
1515
$items: $('#product_info_tabs_downloadable_items'),
1616
$tab: null,
1717
isDownloadable: false,
18+
19+
/**
20+
* Show
21+
*/
1822
show: function () {
1923
this.$checkbox.prop('checked', true);
2024
this.$items.show();
2125
},
26+
27+
/**
28+
* Hide
29+
*/
2230
hide: function () {
2331
this.$checkbox.prop('checked', false);
2432
this.$items.hide();
2533
},
26-
'Magento_Downloadable/downloadable-type-handler': function(data) {
27-
this.$tab = $('[data-tab='+data.tabId+']');
34+
35+
/**
36+
* Constructor component
37+
* @param {Object} data - this backend data
38+
*/
39+
'Magento_Downloadable/downloadable-type-handler': function (data) {
40+
this.$tab = $('[data-tab=' + data.tabId + ']');
2841
this.isDownloadable = data.isDownloadable;
2942
this.bindAll();
3043
this._initType();
3144
},
45+
46+
/**
47+
* Bind all
48+
*/
3249
bindAll: function () {
3350
this.$checkbox.on('change', function (event) {
3451
$(document).trigger('setTypeProduct', $(event.target).prop('checked') ? 'downloadable' : null);
35-
}.bind(this));
52+
});
3653

3754
$(document).on('changeTypeProduct', this._initType.bind(this));
3855
},
56+
57+
/**
58+
* Init type
59+
* @private
60+
*/
3961
_initType: function () {
40-
if (productType.type.current == 'downloadable') {
62+
if (productType.type.current === 'downloadable') {
4163
weight.change(false);
4264
weight.$weightSwitcher.one('change', function () {
4365
$(document).trigger('setTypeProduct', null);

0 commit comments

Comments
 (0)