diff --git a/index.html b/index.html
index 3252ff5..c39a093 100644
--- a/index.html
+++ b/index.html
@@ -412,6 +412,8 @@ SELECT * FROM users LIMIT 10;">
+
+
@@ -626,7 +628,14 @@ SELECT * FROM users LIMIT 10;">
// Generate rows
body.innerHTML = records.map(record => {
const pkValue = this.primaryKey ? record[this.primaryKey] : null;
- const cells = columns.map(col => `
${record[col] || ''} | `).join('');
+ const cells = columns.map(col => {
+ const colDef = this.tableStructure.find(c => c.name === col);
+ let displayValue = record[col] || '';
+ if (colDef && colDef.type.toLowerCase() === 'boolean') {
+ displayValue = record[col] === true || record[col] === 'true' ? '✓' : '✗';
+ }
+ return `
${displayValue} | `;
+ }).join('');
const actions = pkValue ? `
@@ -674,11 +683,35 @@ SELECT * FROM users LIMIT 10;">
// Generate form fields based on table structure
form.innerHTML = this.tableStructure.map(col => {
- const value = isEdit && this.editingRecord ? '' : ''; // We'll need to load the record data
+ const value = isEdit && this.editingRecord ? '' : '';
+ let inputHtml = '';
+
+ if (col.type.toLowerCase() === 'boolean') {
+ inputHtml = ``;
+ } else if (col.type.toLowerCase().includes('json')) {
+ inputHtml = ``;
+ } else {
+ let inputType = 'text';
+ let step = '';
+
+ if (col.type.toLowerCase().includes('int')) {
+ inputType = 'number';
+ } else if (col.type.toLowerCase().includes('decimal') || col.type.toLowerCase().includes('numeric')) {
+ inputType = 'number';
+ step = 'step="0.01"';
+ } else if (col.type.toLowerCase() === 'date') {
+ inputType = 'date';
+ } else if (col.type.toLowerCase().includes('timestamp')) {
+ inputType = 'datetime-local';
+ }
+
+ inputHtml = ``;
+ }
+
return `
-
-
+
+ ${inputHtml}
`;
}).join('');
@@ -701,9 +734,13 @@ SELECT * FROM users LIMIT 10;">
const record = data.data.find(r => r[this.primaryKey] == pkValue);
if (record) {
this.tableStructure.forEach(col => {
- const input = document.querySelector(`input[name="${col.name}"]`);
+ const input = document.querySelector(`[name="${col.name}"]`);
if (input) {
- input.value = record[col.name] || '';
+ if (col.type.toLowerCase() === 'boolean') {
+ input.checked = record[col.name] === true || record[col.name] === 'true';
+ } else {
+ input.value = record[col.name] || '';
+ }
}
});
}
@@ -713,12 +750,18 @@ SELECT * FROM users LIMIT 10;">
}
async saveRecord() {
- const formData = new FormData(document.getElementById('recordForm'));
const data = {};
- for (let [key, value] of formData.entries()) {
- data[key] = value;
- }
+ this.tableStructure.forEach(col => {
+ const input = document.querySelector(`[name="${col.name}"]`);
+ if (input) {
+ if (col.type.toLowerCase() === 'boolean') {
+ data[col.name] = input.checked;
+ } else {
+ data[col.name] = input.value;
+ }
+ }
+ });
try {
let response;
@@ -743,7 +786,7 @@ SELECT * FROM users LIMIT 10;">
this.loadTableData();
this.editingRecord = null;
} else {
- this.showToast('Ошибка сохранения', 'error');
+ this.showToast(result.error || 'Ошибка сохранения', 'error');
}
} catch (err) {
this.showToast('Ошибка сохранения', 'error');
@@ -884,6 +927,9 @@ SELECT * FROM users LIMIT 10;">
+
+
+
|