Skip to content

Commit

Permalink
Merge pull request #535 from magento-vanilla/MAGETWO-50158
Browse files Browse the repository at this point in the history
[Vanilla] Story + Bug
  • Loading branch information
slavvka committed Apr 13, 2016
2 parents 809df2c + 9dad46d commit f4ae285
Show file tree
Hide file tree
Showing 25 changed files with 623 additions and 239 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
-->
<button class="action-delete"
data-bind="
click: function(){ $parents[1].deleteRecord($parent.index, $parent.recordId); },
click: function(){ $parent.processingDeleteRecord($record().index, $record().recordId); },
attr: {
title: $parents[1].deleteButtonLabel
title: $parent.deleteButtonLabel
}
">
<span data-bind="text: $parents[1].deleteButtonLabel"></span>
<span data-bind="text: $parent.deleteButtonLabel"></span>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,44 @@
</label>

<div class="admin__field-control" data-role="grid-wrapper">
<div class="admin__control-table-pagination" visible="!!$data.recordData().length">
<div class="admin__data-grid-pager">
<button class="action-previous" type="button" data-bind="attr: {title: $t('Previous Page')}, click: previousPage, disable: isFirst()"></button>
<input class="admin__control-text" type="number" data-bind="attr: {id: ++ko.uid}, value: currentPage">
<label class="admin__control-support-text" data-bind="attr: {for: ko.uid}, text: 'of ' + pages()"></label>
<button class="action-next" type="button" data-bind="attr: {title: $t('Next Page')}, click: nextPage, disable: isLast()"></button>
</div>
</div>
<div class="admin__control-table-wrapper">
<table class="admin__dynamic-rows data-grid" data-role="grid">
<thead if="element.columnsHeader">
<tr>
<th if="dndConfig.enabled"
class="data-grid-draggable-row-cell"/>

<!-- ko foreach: {data: labels, as: 'item'} -->
<th class="data-grid-th"
text="item.label"
visible="item.visible"
disabled="item.disabled"
css="$parent.setClasses(item)">
<th repeat="foreach: labels, item: '$label'"
class="data-grid-th"
text="$label().label"
visible="$label().visible"
disable="$label().disabled"
css="setClasses($label())">
</th>
<!-- /ko -->
</tr>
</thead>

<tbody data-bind="foreach: elems">
<tr class="data-row"
css="'_odd-row': $index() % 2">
<td if="$parent.dndConfig.enabled"
<tr repeat="foreach: elems, item: '$record'"
class="data-row"
css="'_odd-row': $index % 2">
<td if="dndConfig.enabled"
class="data-grid-draggable-row-cell"
template="name: $parent.dndConfig.template, data: $parent.dnd"/>
template="name: dndConfig.template, data: dnd"/>

<!-- ko foreach: { data: elems, as: 'elem'} -->
<!-- ko fastForEach: { data: $record().elems, as: 'elem'} -->
<td if="elem.template"
visible="elem.visible"
disabled="elem.disabled"
css="$parents[1].setClasses(elem)"
disable="elem.disabled"
css="$parent.setClasses(elem)"
template="elem.template"
attr="'data-index': index"/>
<!-- /ko -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ protected function getTextColumn($dataScope, $fit, Phrase $label, $sortOrder)
'componentType' => Field::NAME,
'formElement' => Input::NAME,
'elementTmpl' => 'ui/dynamic-rows/cells/text',
'component' => 'Magento_Ui/js/form/element/text',
'dataType' => Text::NAME,
'dataScope' => $dataScope,
'fit' => $fit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<button class="action-delete"
attr="{'data-action': 'remove_row'}"
data-bind="
click: function(){ $data.deleteRecord($parents); },
click: function(){ $data.processingDeleteRecord($parents); },
attr: {
title: $parents[1].deleteButtonLabel
title: $parent.deleteButtonLabel
}
">
<span data-bind="text: $parents[1].deleteButtonLabel"></span>
<span data-bind="text: $parent.deleteButtonLabel"></span>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ protected function getRows()
'config' => [
'componentType' => Form\Field::NAME,
'formElement' => Form\Element\Input::NAME,
'component' => 'Magento_Ui/js/form/element/text',
'elementTmpl' => 'ui/dynamic-rows/cells/text',
'dataType' => Form\Element\DataType\Text::NAME,
'label' => __('Attributes'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ define([
openModalWithGrid: function (rowIndex) {
var productSource = this.source.get(this.dataScope + '.' + this.index + '.' + rowIndex),
product = {
'id': productSource.id,
'attributes': productSource['configurable_attribute']
};
'id': productSource.id,
'attributes': productSource['configurable_attribute']
};

this.modalWithGrid().openModal();
this.gridWithProducts().showGridChangeProduct(rowIndex, product);
Expand Down Expand Up @@ -110,7 +110,8 @@ define([
* @param {Number} index - row index
*/
deleteRecord: function (index) {
var tmpArray;
var tmpArray,
lastRecord;

this.reRender = false;
tmpArray = this.getUnionInsertData();
Expand All @@ -120,8 +121,26 @@ define([
this.source.set('data.attributes', []);
}

if (parseInt(this.currentPage(), 10) === this.pages()) {
lastRecord =
_.findWhere(this.elems(), {
index: this.startIndex + this.getChildItems().length - 1
}) ||
_.findWhere(this.elems(), {
index: (this.startIndex + this.getChildItems().length - 1).toString()
});

lastRecord.destroy();
}

this.unionInsertData(tmpArray);

if (this.pages() < parseInt(this.currentPage(), 10)) {
this.currentPage(this.pages());
}

this.reRender = true;
this.showSpinner(false);
},

/**
Expand Down Expand Up @@ -175,44 +194,37 @@ define([
* @param {Array} data
*/
processingUnionInsertData: function (data) {
var dataInc = 0,
diff = 0,
dataCount,
var dataCount,
elemsCount,
lastRecord;
tmpData,
path;

this.source.remove(this.dataScope + '.' + this.index);
this.isEmpty(data.length === 0);

_.each(data, function (row) {
_.each(row, function (value, key) {
var path = this.dataScope + '.' + this.index + '.' + dataInc + '.' + key;
tmpData = data.slice(this.pageSize * (this.currentPage() - 1),
this.pageSize * (this.currentPage() - 1) + this.pageSize);

this.source.set(path, value);
}, this);
this.source.set(this.dataScope + '.' + this.index, []);

++dataInc;
_.each(tmpData, function (row, index) {
path = this.dataScope + '.' + this.index + '.' + (this.startIndex + index);
this.source.set(path, row);
}, this);

this.source.set(this.dataScope + '.' + this.index, data);
this.parsePagesData(data);

// Render
dataCount = data.length;
elemsCount = this.elems().length;

if (dataCount > elemsCount) {
for (diff = dataCount - elemsCount; diff > 0; diff--) {
this.addChild(data, false);
}
this.getChildItems().each(function (elemData, index) {
this.addChild(elemData, this.startIndex + index);
}, this);
} else {
for (diff = elemsCount - dataCount; diff > 0; diff--) {
lastRecord =
_.findWhere(this.elems(), {
index: this.recordIterator - 1
}) ||
_.findWhere(this.elems(), {
index: (this.recordIterator - 1).toString()
});
lastRecord.destroy();
--this.recordIterator;
for (elemsCount; elemsCount > dataCount; elemsCount--) {
this.elems()[elemsCount - 1].destroy();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@
-->
<div class="action-select-wrap" data-bind="
css : {
'_active' : $parents[1].actionsListOpened() === $parent.index
'_active' : $parent.actionsListOpened() === $record().index
},
outerClick: $parents[1].closeList.bind($parents[1], $parent.index)"
outerClick: $parent.closeList.bind($parent, $record().index)"
>
<button class="action-select" data-bind="click: function(){ $parents[1].toggleActionsList($parent.index); }">
<button class="action-select" data-bind="click: function(){ $parent.toggleActionsList($record().index); }">
<span data-bind="i18n: 'Select'"></span>
</button>
<ul class="action-menu _active" data-bind="css: {'_active': $parents[1].actionsListOpened() === $parent.index}">
<ul class="action-menu _active" data-bind="css: {'_active': $parent.actionsListOpened() === $record().index}">
<li>
<a class="action-menu-item" data-bind="
click: function(){
$parents[1].openModalWithGrid($parent.index);
$parents[1].closeList($parent.index);
$parent.openModalWithGrid($record().index);
$parent.closeList($record().index);
}
">Choose a different Product</a>
</li>
<li>
<a class="action-menu-item" data-bind="
text: $data.value() == 1 ? $t('Disable Product') : $t('Enable Product'),
click: function(){
$parents[1].toggleStatusProduct($parent.index);
$parents[1].closeList($parent.index);
$parent.toggleStatusProduct($record().index);
$parent.closeList($record().index);
}
"></a>
</li>
<li>
<a class="action-menu-item" data-bind="
click: function(){
$parents[1].deleteRecord($parent.index, $parent.recordId);
$parents[1].closeList($parent.index);
$parent.closeList($record().index);
$parent.processingDeleteRecord($record().index, $record().recordId);
},
text: $t('Remove Product')
"></a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,24 @@
<table class="data-grid data-grid-configurable">
<thead>
<tr>
<!-- ko foreach: { data: grid.columns, as: 'column' } -->
<th class="data-grid-th" data-bind="text: column"></th>
<!-- /ko -->
<th repeat="foreach: grid.columns, item: '$column'" class="data-grid-th" data-bind="text: $column"></th>
</tr>
</thead>

<tbody>
<!-- ko foreach: { data: grid, as: 'product' } -->
<tr>
<!-- ko foreach: { data: product, as: 'property' } -->
<!-- ko if: property && property.preview -->
<td class="data-grid-thumbnail-cell">
<tr repeat="foreach: grid, item: '$product'">
<!-- ko fastForEach: { data: $product(), as: 'property' } -->
<td if="property && property.preview" class="data-grid-thumbnail-cell">
<div class="images-uploaded">
<img data-bind="attr: {src: property.preview}"/>
<span data-bind="text: property.images.length"></span>
</div>
</td>
<!-- /ko -->
<!-- ko ifnot: property && property.preview -->
<td>
<td ifnot="property && property.preview">
<span data-bind='text: property'></span>
</td>
<!-- /ko -->
<!-- /ko -->
</tr>
<!-- /ko -->
</tbody>
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ define([
* @returns {Object} draggable record context
*/
getRecord: function (elem) {
return this.recordsCache()[getContext(elem).$index()];
return this.recordsCache()[getContext(elem).$index];
}

});
Expand Down
Loading

0 comments on commit f4ae285

Please sign in to comment.