Added Pages

This commit is contained in:
2025-04-30 16:22:07 +03:00
parent 56f3f8805d
commit b2912064b5
9 changed files with 339 additions and 43 deletions

View File

@@ -158,11 +158,149 @@ document.addEventListener('DOMContentLoaded', () => {
alert('Exporting current report as PDF...');
// Add logic to export the current report as PDF
});
});
document.addEventListener('DOMContentLoaded', () => {
const templateList = document.getElementById('template-list');
const createTemplateBtn = document.getElementById('create-template-btn');
// Example: Handle the "Create New Template" button click
createTemplateBtn.addEventListener('click', () => {
window.location.href = '/create_template';
});
// Example: Handle the "Edit" and "Delete" buttons
templateList.addEventListener('click', (event) => {
if (event.target.classList.contains('edit-btn')) {
const templateId = event.target.closest('li').dataset.id;
window.location.href = `/edit_template/${templateId}`;
} else if (event.target.classList.contains('delete-btn')) {
const templateId = event.target.closest('li').dataset.id;
if (confirm('Are you sure you want to delete this template?')) {
fetch(`/delete_template/${templateId}`, { method: 'POST' })
.then(response => response.text())
.then(data => {
alert(data);
// Optionally, remove the template from the list
event.target.closest('li').remove();
});
}
}
});
});
document.addEventListener('DOMContentLoaded', () => {
const setDimensionsBtn = document.getElementById('set-dimensions-btn');
const getTablesBtn = document.getElementById('get-tables-btn');
const tablesContainer = document.getElementById('tables-container');
const columnsContainer = document.getElementById('columns-container');
const labelPreview = document.getElementById('label-preview');
const saveTemplateBtn = document.getElementById('save-template-btn');
// Handle setting dimensions
setDimensionsBtn.addEventListener('click', () => {
const width = document.getElementById('label-width').value;
const height = document.getElementById('label-height').value;
if (width && height) {
alert(`Label dimensions set to ${width}mm x ${height}mm.`);
} else {
alert('Please enter valid dimensions.');
}
});
// Handle fetching database tables
getTablesBtn.addEventListener('click', () => {
fetch('/get_tables')
.then(response => response.json())
.then(data => {
tablesContainer.innerHTML = '<h4>Select a Table:</h4>';
data.tables.forEach(table => {
const button = document.createElement('button');
button.textContent = table;
button.classList.add('btn');
button.addEventListener('click', () => fetchColumns(table));
tablesContainer.appendChild(button);
});
})
.catch(error => console.error('Error fetching tables:', error));
});
// Fetch columns for a selected table
function fetchColumns(table) {
fetch(`/get_columns?table=${table}`)
.then(response => response.json())
.then(data => {
columnsContainer.innerHTML = '<h4>Select Columns:</h4>';
data.columns.forEach(column => {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.value = column;
checkbox.id = `column-${column}`;
const label = document.createElement('label');
label.textContent = column;
label.htmlFor = `column-${column}`;
columnsContainer.appendChild(checkbox);
columnsContainer.appendChild(label);
columnsContainer.appendChild(document.createElement('br'));
// Update label preview on checkbox change
checkbox.addEventListener('change', updateLabelPreview);
});
})
.catch(error => console.error('Error fetching columns:', error));
}
// Update the label preview
function updateLabelPreview() {
const selectedColumns = Array.from(columnsContainer.querySelectorAll('input[type="checkbox"]:checked'))
.map(checkbox => checkbox.value);
labelPreview.innerHTML = '<h4>Label Preview:</h4>';
selectedColumns.forEach(column => {
const div = document.createElement('div');
div.textContent = column;
labelPreview.appendChild(div);
});
}
// Handle saving the template
saveTemplateBtn.addEventListener('click', () => {
const selectedColumns = Array.from(columnsContainer.querySelectorAll('input[type="checkbox"]:checked'))
.map(checkbox => checkbox.value);
if (selectedColumns.length === 0) {
alert('Please select at least one column for the label.');
return;
}
const width = document.getElementById('label-width').value;
const height = document.getElementById('label-height').value;
if (!width || !height) {
alert('Please set the label dimensions.');
return;
}
const templateData = {
width,
height,
columns: selectedColumns
};
fetch('/save_template', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(templateData)
})
.then(response => response.json())
.then(data => {
alert(data.message);
})
.catch(error => console.error('Error saving template:', error));
});
});