From 36dd42b62d296f258eaf6838ce346a7f861d41e1 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 21 Oct 2016 17:16:04 +0100 Subject: [PATCH] Add new record (dynamic table) --- .../components/widgets/core/dynamic-table.model.ts | 11 ++++++++++- .../widgets/dynamic-table/dynamic-table.widget.ts | 11 +++++++++-- .../widgets/dynamic-table/editors/date/date.editor.ts | 8 ++++++-- .../editors/dropdown/dropdown.editor.html | 1 + 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/core/dynamic-table.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/core/dynamic-table.model.ts index 65271329c1..7b4ec221dd 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/core/dynamic-table.model.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/core/dynamic-table.model.ts @@ -105,11 +105,20 @@ export class DynamicTableModel extends FormWidgetModel { } } + addRow(row: DynamicTableRow) { + if (row) { + this.rows.push(row); + // this.selectedRow = row; + } + } + getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any { let result = row.value[column.id]; if (column.type === 'Dropdown') { - return result.name; + if (result) { + return result.name; + } } if (column.type === 'Boolean') { diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts index 6e8cc88ead..1969189bd6 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts @@ -70,7 +70,11 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit { addNewRow() { if (this.content) { - this.editRow = { selected: false, value: {} }; + this.editRow = { + isNew: true, + selected: false, + value: {} + }; this.editMode = true; } } @@ -92,7 +96,10 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit { onSaveChanges() { if (this.content) { if (this.editRow.isNew) { - // TODO: create new record + let row = this.copyRow(this.editRow); + this.content.selectedRow = null; + this.content.addRow(row); + this.editRow.isNew = false; } else { this.content.selectedRow.value = this.copyObject(this.editRow.value); } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/date/date.editor.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/date/date.editor.ts index 6fee69784a..96293332b3 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/date/date.editor.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/date/date.editor.ts @@ -37,10 +37,14 @@ export class DateEditorComponent extends CellEditorComponent implements OnInit { ngOnInit() { let settings: any = { type: 'date', - future: moment().add(21, 'years'), - init: moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT) + future: moment().add(21, 'years') }; + let value = this.table.getCellValue(this.row, this.column); + if (value) { + settings.init = moment(value, this.DATE_FORMAT); + } + this.datePicker = new mdDateTimePicker.default(settings); if (this.elementRef) { this.datePicker.trigger = this.elementRef.nativeElement.querySelector('#dateInput'); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.html b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.html index 4d4fb3b4ab..ed6589bc50 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.html +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/editors/dropdown/dropdown.editor.html @@ -5,6 +5,7 @@ [value]="table.getCellValue(row, column)" class="dropdown-editor__select" (change)="onValueChanged(row, column, $event)"> +