1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'underscore',
'mageUtils',
'uiRegistry',
'Magento_Ui/js/dynamic-rows/dynamic-rows'
], function (_, utils, registry, dynamicRows) {
'use strict';
return dynamicRows.extend({
defaults: {
label: '',
collapsibleHeader: true,
columnsHeader: false,
deleteProperty: false,
addButton: false
},
/**
* Set new data to dataSource,
* delete element
*
* @param {Array} data - record data
*/
_updateData: function (data) {
var elems = _.clone(this.elems()),
path,
dataArr,
optionBaseData;
dataArr = this.recordData.splice(this.startIndex, this.recordData().length - this.startIndex);
dataArr.splice(0, this.pageSize);
elems = _.sortBy(this.elems(), function (elem) {
return ~~elem.index;
});
data.concat(dataArr).forEach(function (rec, idx) {
if (elems[idx]) {
elems[idx].recordId = rec[this.identificationProperty];
}
if (!rec.position) {
rec.position = this.maxPosition;
this.setMaxPosition();
}
path = this.dataScope + '.' + this.index + '.' + (this.startIndex + idx);
optionBaseData = _.pick(rec, function (value) {
return !_.isObject(value);
});
this.source.set(path, optionBaseData);
this.source.set(path + '.bundle_button_proxy', []);
this.source.set(path + '.bundle_selections', []);
this.removeBundleItemsFromOption(idx);
_.each(rec['bundle_selections'], function (obj, index) {
this.source.set(path + '.bundle_button_proxy' + '.' + index, rec['bundle_button_proxy'][index]);
this.source.set(path + '.bundle_selections' + '.' + index, obj);
}, this);
}, this);
this.elems(elems);
},
/**
* Removes nested dynamic-rows-grid rendered records from option
*
* @param {Number|String} index - element index
*/
removeBundleItemsFromOption: function (index) {
var bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName),
bundleSelectionsLength = (bundleSelections.elems() || []).length,
i;
if (bundleSelectionsLength) {
for (i = 0; i < bundleSelectionsLength; i++) {
bundleSelections.elems()[0].destroy();
}
}
},
/**
* {@inheritdoc}
*/
processingAddChild: function (ctx, index, prop) {
var recordIds = _.map(this.recordData(), function (rec) {
return parseInt(rec['record_id'], 10);
}),
maxRecordId = _.max(recordIds);
prop = maxRecordId > -1 ? maxRecordId + 1 : prop;
this._super(ctx, index, prop);
}
});
});