123
This commit is contained in:
47
index.html
47
index.html
@@ -633,39 +633,46 @@ SELECT * FROM users LIMIT 10;"></textarea>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CRUD Operations
|
// CRUD Operations
|
||||||
showAddRecordModal() {
|
async showAddRecordModal() {
|
||||||
this.editingRecord = null;
|
this.editingRecord = null;
|
||||||
document.getElementById('recordModalTitle').textContent = 'Добавить запись';
|
document.getElementById('recordModalTitle').textContent = 'Добавить запись';
|
||||||
this.generateRecordForm();
|
|
||||||
|
await this.generateRecordForm();
|
||||||
|
|
||||||
document.getElementById('recordModal').classList.remove('hidden');
|
document.getElementById('recordModal').classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
editRecord(idx) {
|
async editRecord(idx) {
|
||||||
this.editingRecord = idx;
|
this.editingRecord = idx;
|
||||||
document.getElementById('recordModalTitle').textContent = 'Редактировать запись';
|
document.getElementById('recordModalTitle').textContent = 'Редактировать запись';
|
||||||
this.generateRecordForm();
|
|
||||||
|
await this.generateRecordForm();
|
||||||
|
|
||||||
document.getElementById('recordModal').classList.remove('hidden');
|
document.getElementById('recordModal').classList.remove('hidden');
|
||||||
}
|
}
|
||||||
|
|
||||||
generateRecordForm() {
|
async generateRecordForm() {
|
||||||
// Get columns based on current table structure
|
if (response.status === 401) {
|
||||||
const columns = this.getTableStructure(this.currentTable);
|
this.logout();
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const columns = await this.getTableStructure(this.currentTable);
|
||||||
const container = document.getElementById('recordForm');
|
const container = document.getElementById('recordForm');
|
||||||
|
|
||||||
container.innerHTML = columns.map(col => `
|
container.innerHTML = columns.map(col => `
|
||||||
<div>
|
<div>
|
||||||
<label class="block text-sm font-medium text-slate-700 mb-1">
|
<label class="block text-sm font-medium text-slate-700 mb-1">
|
||||||
${col.name}
|
${col.name}
|
||||||
${col.nullable ? '' : '<span class="text-red-500">*</span>'}
|
${col.nullable ? '' : '<span class="text-red-500">*</span>'}
|
||||||
</label>
|
</label>
|
||||||
<input type="${this.getInputType(col.type)}"
|
<input type="${this.getInputType(col.type)}"
|
||||||
name="${col.name}"
|
name="${col.name}"
|
||||||
class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none"
|
class="w-full px-4 py-2 border border-slate-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent outline-none"
|
||||||
${col.default ? `value="${col.default}"` : ''}>
|
${col.default ? `value="${col.default}"` : ''}>
|
||||||
<p class="text-xs text-slate-500 mt-1">${col.type}</p>
|
<p class="text-xs text-slate-500 mt-1">${col.type}</p>
|
||||||
</div>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTableStructure(tableName) {
|
async getTableStructure(tableName) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user