diff --git a/resources/js/Components/Pages/RecordsPage.jsx b/resources/js/Components/Pages/RecordsPage.jsx index 03e862a08..66050d2fe 100644 --- a/resources/js/Components/Pages/RecordsPage.jsx +++ b/resources/js/Components/Pages/RecordsPage.jsx @@ -108,6 +108,20 @@ export default class RecordsPage extends Page { } } + async onupdate(vnode) { + const rows = $('.mdc-data-table__row[data-model-id]'); + if (rows.length > 0) { + rows.on( + 'click', + (event: PointerEvent) => { + this.updateRecord($(event.target) + .parent('tr') + .data('model-id')); + } + ); + } + } + tableColumns(): Children { return collect(this.columns) .map( @@ -143,17 +157,52 @@ export default class RecordsPage extends Page { } return ( - + {cells.map((cell: string, index_) => {cell})} ); }); } + async updateRecord(id: number) { + // noinspection JSUnresolvedFunction + const instance: Model = (await this.model.find(id)).getData(); + const dialog = $('mwc-dialog#add-record-dialog'); + + // eslint-disable-next-line sonarjs/no-duplicate-string + dialog.find('text-field, text-area') + .each((index, field: TextField | TextArea) => { + field.value = instance[field.id]; + }); + + dialog.find('mwc-button#delete-button') + .show() + .on('click', () => { + const confirmDialog = $('mwc-dialog#confirm-delete-record-dialog'); + confirmDialog.find('mwc-button#confirm-button') + .on('click', async () => { + await instance.delete(); + this.rows = this.rows.filter(row => row.id !== instance.id); + m.redraw(); + confirmDialog.get(0) + .close(); + dialog.get(0) + .close(); + await showSnackbar(this.__('Record eliminato!'), 4000); + }); + confirmDialog.get(0) + .show(); + }); + + dialog.get(0) + .show(); + } + recordDialog() { return (
+