Implement AJAX job actions for Jobs page

- Replace form submissions with AJAX calls for cancel/restart/delete
- Remove confirm alerts and page redirects
- Add success/error notifications for actions
- Initialize job actions on page load
- Update backend routes to handle AJAX requests with JSON responses
- Maintain real-time status updates via polling
parent b05ab8f9
This diff is collapsed.
......@@ -402,8 +402,14 @@ def delete_job(job_id):
from .queue import queue_manager
if queue_manager.delete_job(job_id, user['id']):
# Check if this is an AJAX request
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return {'success': True, 'message': 'Job deleted successfully!'}
flash('Job deleted successfully!', 'success')
else:
# Check if this is an AJAX request
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return {'success': False, 'message': 'Failed to delete job or access denied.'}, 400
flash('Failed to delete job or access denied.', 'error')
return redirect(url_for('history'))
......@@ -417,8 +423,14 @@ def cancel_job(job_id):
from .queue import queue_manager
if queue_manager.cancel_job(job_id, user['id']):
# Check if this is an AJAX request
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return {'success': True, 'message': 'Job cancelled successfully!'}
flash('Job cancelled successfully!', 'success')
else:
# Check if this is an AJAX request
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return {'success': False, 'message': 'Failed to cancel job or access denied.'}, 400
flash('Failed to cancel job or access denied.', 'error')
return redirect(url_for('history'))
......@@ -432,8 +444,14 @@ def restart_job(job_id):
from .queue import queue_manager
if queue_manager.restart_job(job_id, user['id']):
# Check if this is an AJAX request
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return {'success': True, 'message': 'Job restarted successfully!'}
flash('Job restarted successfully!', 'success')
else:
# Check if this is an AJAX request
if request.headers.get('Content-Type') == 'application/x-www-form-urlencoded' and request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return {'success': False, 'message': 'Failed to restart job or access denied.'}, 400
flash('Failed to restart job or access denied.', 'error')
return redirect(url_for('history'))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment