Updated filters remained after deleting record
This commit is contained in:
@@ -8121,7 +8121,25 @@ def delete_time_attendance_record(record_id):
|
||||
logger_handler.log_database_error('time_attendance_delete', e)
|
||||
flash('Failed to delete time attendance record.', 'error')
|
||||
|
||||
return redirect(url_for('time_attendance_records'))
|
||||
# Get filter parameters from BOTH request.form (POST) and request.args (GET query params)
|
||||
# This handles both the records list page and the detail page
|
||||
filter_params = {}
|
||||
|
||||
# List of possible filter parameters
|
||||
filter_keys = ['employee_id', 'location_name', 'project_id', 'start_date', 'end_date', 'page']
|
||||
|
||||
for key in filter_keys:
|
||||
# Try to get from form data first (records list page)
|
||||
value = request.form.get(key)
|
||||
# If not in form, try query parameters (detail page)
|
||||
if not value:
|
||||
value = request.args.get(key)
|
||||
# Only include if value exists and is not empty
|
||||
if value:
|
||||
filter_params[key] = value
|
||||
|
||||
# Redirect back with filters preserved
|
||||
return redirect(url_for('time_attendance_records', **filter_params))
|
||||
|
||||
@app.route('/api/time-attendance/employee/<employee_id>')
|
||||
@login_required
|
||||
|
||||
@@ -840,23 +840,35 @@ function closeDeleteModal() {
|
||||
}
|
||||
|
||||
function submitDelete() {
|
||||
console.log('[DEBUG] Submit delete function called');
|
||||
console.log('[DEBUG] Submit delete called');
|
||||
|
||||
// Close the modal if it exists
|
||||
const modal = document.getElementById('deleteModal');
|
||||
if (modal) {
|
||||
closeDeleteModal();
|
||||
}
|
||||
// Close modal
|
||||
closeDeleteModal();
|
||||
|
||||
// Create form dynamically
|
||||
// Get current URL parameters (filters that were passed from records page)
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const params = currentUrl.searchParams;
|
||||
|
||||
console.log('[DEBUG] Current URL params:', params.toString());
|
||||
|
||||
// Create form
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = "{{ url_for('delete_time_attendance_record', record_id=record.id) }}";
|
||||
|
||||
// Add session-based CSRF token if available
|
||||
// Add all URL parameters as hidden form inputs
|
||||
for (const [key, value] of params.entries()) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = key;
|
||||
input.value = value;
|
||||
form.appendChild(input);
|
||||
console.log('[DEBUG] Added param:', key, '=', value);
|
||||
}
|
||||
|
||||
// Add CSRF token
|
||||
const sessionCsrfToken = '{{ session.get("csrf_token", "") }}';
|
||||
if (sessionCsrfToken) {
|
||||
console.log('[DEBUG] Adding CSRF token');
|
||||
const csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = 'csrf_token';
|
||||
@@ -864,9 +876,9 @@ function submitDelete() {
|
||||
form.appendChild(csrfInput);
|
||||
}
|
||||
|
||||
// Append form to body and submit
|
||||
// Submit
|
||||
document.body.appendChild(form);
|
||||
console.log('[DEBUG] Submitting form...');
|
||||
console.log('[DEBUG] Submitting form with', form.querySelectorAll('input').length, 'inputs');
|
||||
form.submit();
|
||||
}
|
||||
|
||||
|
||||
@@ -236,8 +236,8 @@
|
||||
<!-- Actions -->
|
||||
<td class="actions-cell">
|
||||
<div class="action-buttons">
|
||||
<a href="{{ url_for('time_attendance_record_detail', record_id=record.id) }}"
|
||||
class="action-btn view">
|
||||
<a href="{{ url_for('time_attendance_record_detail', record_id=record.id, **request.args) }}"
|
||||
class="action-btn view">
|
||||
<i class="fas fa-eye"></i>
|
||||
View
|
||||
</a>
|
||||
@@ -346,9 +346,34 @@ function toggleFilters() {
|
||||
|
||||
function confirmDelete(recordId, employeeName, date) {
|
||||
if (confirm(`Are you sure you want to delete the attendance record for ${employeeName} on ${date}?`)) {
|
||||
// Get current URL parameters (filters)
|
||||
const currentUrl = new URL(window.location.href);
|
||||
const params = currentUrl.searchParams;
|
||||
|
||||
// Create form
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = `/time-attendance/delete/${recordId}`;
|
||||
|
||||
// Add all current filter parameters as hidden inputs
|
||||
for (const [key, value] of params.entries()) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'hidden';
|
||||
input.name = key;
|
||||
input.value = value;
|
||||
form.appendChild(input);
|
||||
}
|
||||
|
||||
// Add CSRF token if available
|
||||
const sessionCsrfToken = '{{ session.get("csrf_token", "") }}';
|
||||
if (sessionCsrfToken) {
|
||||
const csrfInput = document.createElement('input');
|
||||
csrfInput.type = 'hidden';
|
||||
csrfInput.name = 'csrf_token';
|
||||
csrfInput.value = sessionCsrfToken;
|
||||
form.appendChild(csrfInput);
|
||||
}
|
||||
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
@@ -370,7 +395,7 @@ function exportRecords(format) {
|
||||
// Get current filter values
|
||||
const employeeId = document.querySelector('select[name="employee_id"]')?.value || '';
|
||||
const locationName = document.querySelector('select[name="location_name"]')?.value || '';
|
||||
const projectId = document.querySelector('select[name="project_id"]')?.value || ''; // ADD THIS LINE
|
||||
const projectId = document.querySelector('select[name="project_id"]')?.value || '';
|
||||
const startDate = document.querySelector('input[name="start_date"]')?.value || '';
|
||||
const endDate = document.querySelector('input[name="end_date"]')?.value || '';
|
||||
|
||||
@@ -378,7 +403,7 @@ function exportRecords(format) {
|
||||
const params = new URLSearchParams();
|
||||
if (employeeId) params.append('employee_id', employeeId);
|
||||
if (locationName) params.append('location_name', locationName);
|
||||
if (projectId) params.append('project_id', projectId); // ADD THIS LINE
|
||||
if (projectId) params.append('project_id', projectId);
|
||||
if (startDate) params.append('start_date', startDate);
|
||||
if (endDate) params.append('end_date', endDate);
|
||||
params.append('format', format);
|
||||
|
||||
Reference in New Issue
Block a user