Skip to content

Commit

Permalink
Merge pull request #559 from BlackbitDevs/feature/table-clone-row
Browse files Browse the repository at this point in the history
Field type "Table": add button to clone row
  • Loading branch information
mcop1 authored Aug 9, 2024
2 parents 7554a0f + 4814375 commit 7bf02ca
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
10 changes: 10 additions & 0 deletions public/css/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@
background: url(/bundles/pimcoreadmin/img/flat-color-icons/overlay-google.svg) center center no-repeat !important;
}

.pimcore_icon_overlay_clone:before {
position: absolute;
width: 14px;
height: 14px;
bottom: 0px;
right: 0px;
content: "";
background: url(/bundles/pimcoreadmin/img/flat-color-icons/copy.svg) center center no-repeat !important;
}

.pimcore_main_nav_icon_file {
background: url(/bundles/pimcoreadmin/img/material-icons/outline-file-24px.svg) center center no-repeat !important;
}
Expand Down
30 changes: 27 additions & 3 deletions public/js/pimcore/object/tags/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,19 @@ pimcore.object.tags.table = Class.create(pimcore.object.tags.abstract, {
}

if (!this.fieldConfig.rowsFixed || data.length != this.fieldConfig.rows) {
tbar.push({
iconCls: "pimcore_icon_table_row pimcore_icon_overlay_add",
handler: this.addRow.bind(this)
});

tbar.push({
iconCls: "pimcore_icon_table_row pimcore_icon_overlay_delete",
handler: this.deleteRow.bind(this)
});

tbar.push({
iconCls: "pimcore_icon_table_row pimcore_icon_overlay_add",
handler: this.addRow.bind(this)
iconCls: "pimcore_icon_table_row pimcore_icon_overlay_clone",
handler: this.cloneSelectedRow.bind(this)
});
}

Expand All @@ -203,7 +208,6 @@ pimcore.object.tags.table = Class.create(pimcore.object.tags.abstract, {
handler: this.pasteFromClipboard.bind(this)
});


tbar.push({
iconCls: "pimcore_icon_empty",
handler: this.emptyStore.bind(this)
Expand Down Expand Up @@ -293,6 +297,26 @@ pimcore.object.tags.table = Class.create(pimcore.object.tags.abstract, {
this.dirty = true;
},

cloneSelectedRow: function () {
var selected = this.grid.getSelectionModel();
if (selected.selection) {
var selectedIndex = selected.selection.rowIdx;
var selectedRecord = this.store.getAt(selectedIndex);

var initData = {};
var columnnManager = this.grid.getColumnManager();
var columns = columnnManager.getColumns();

for (var o = 0; o < columns.length; o++) {
initData[columns[o].dataIndex] = selectedRecord.get(columns[o].dataIndex);
}

this.store.insert(selectedIndex + 1, initData);
this.dirty = true;

}
},

deleteRow: function () {
var selected = this.grid.getSelectionModel();
if (selected.selection) {
Expand Down

0 comments on commit 7bf02ca

Please sign in to comment.