Vue.component('tt-table-crud', { //language=Vue template: `
`, props: { crudConfig: {type: Object, required: false, default: () => (window['TT_CONFIG']['CRUD_CONFIG'])} }, data() { return { crudModal: false, crudModalData: {}, window: window } }, methods: { openCrudModal(row = null) { this.crudModalData = row ? JSON.parse(JSON.stringify(row)) : {}; this.crudModal = true; }, resetCrudModalData() { this.crudModalData = {}; this.crudModal = false; }, async submitCrudModal() { delete this.crudModalData.isTrusted; const response = await axios.post(this.crudModalData.id ? window['TT_CONFIG']['UPDATE_URL'] : window['TT_CONFIG']['CREATE_URL'], this.crudModalData); if (response.data.success) { this.$refs.table.refreshTable(); this.resetCrudModalData(); this.window.notify('success', response.data.message || 'Erfolgreich gespeichert'); } else { this.window.notify('error', response.data.errors ? Object.values(response.data.errors).join('
') : response.data.message || 'Ein Fehler ist aufgetreten'); } }, async deleteCrudModal() { const response = await axios.post(window['TT_CONFIG']['DELETE_URL'], {id: this.crudModalData.id}); if (response.data.success) { this.$refs.table.refreshTable(); this.resetCrudModalData(); } this.window.notify(response.data.success ? 'success' : 'error', response.data.message); } }, computed: { tableConfig() { return { key: this.crudConfig.key, tableHeader: this.crudConfig.tableHeader, headers: this.crudConfig.columns.filter(column => column.table !== false).map(column => { return {text: column.text, key: column.key, ...column.table, filterOptions: column?.modal?.items} }) } }, modalConfig() { return { key: this.crudConfig.key, headers: this.crudConfig.columns.filter(column => column.modal !== false).map(column => { const type = column.modal?.type || "text" return {text: column.text, key: column.key, type, ...column.modal} }), } } } })