04/29 Modified project page to add button to enable/disable a project
This commit is contained in:
+14
-15
@@ -106,22 +106,18 @@
|
||||
</div>
|
||||
|
||||
<div class="project-actions">
|
||||
<a href="{{ url_for('projects.edit_project', project_id=project.id) }}"
|
||||
class="btn btn-secondary">
|
||||
<a href="{{ url_for('projects.edit_project', project_id=project.id) }}" class="btn btn-secondary">
|
||||
<i class="fas fa-edit"></i>
|
||||
Edit
|
||||
</a>
|
||||
<!-- Activate/Deactivate button (for future use)
|
||||
<form method="POST" action="{{ url_for('projects.toggle_project', project_id=project.id) }}"
|
||||
style="display: inline;">
|
||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
|
||||
<button type="submit"
|
||||
class="btn {% if project.active_status %}btn-warning{% else %}btn-success{% endif %}">
|
||||
<button type="submit" class="btn {% if project.active_status %}btn-warning{% else %}btn-success{% endif %}">
|
||||
<i class="fas {% if project.active_status %}fa-pause{% else %}fa-play{% endif %}"></i>
|
||||
{% if project.active_status %}Deactivate{% else %}Activate{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
-->
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
@@ -160,7 +156,10 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}, index * 100);
|
||||
});
|
||||
|
||||
// Confirm project deactivation/activation
|
||||
// Confirm + loading state for toggle (activate/deactivate) forms.
|
||||
// IMPORTANT: the loading spinner must be applied AFTER confirm() resolves
|
||||
// true. Setting button.disabled before the form submits blocks submission
|
||||
// per the HTML spec (disabled buttons are not successful submitters).
|
||||
const toggleForms = document.querySelectorAll('form[action*="toggle_project"]');
|
||||
toggleForms.forEach(form => {
|
||||
form.addEventListener('submit', function (e) {
|
||||
@@ -170,25 +169,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
if (!confirm(`Are you sure you want to ${action.toLowerCase()} the project "${projectName}"?`)) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// User confirmed — apply loading state after confirm, form will now submit.
|
||||
button.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...';
|
||||
button.disabled = true;
|
||||
});
|
||||
});
|
||||
|
||||
// Add loading state to buttons
|
||||
const actionButtons = document.querySelectorAll('.project-actions .btn');
|
||||
// Add loading state to non-toggle action buttons (e.g. Edit links).
|
||||
// Toggle buttons are handled above via submit handler; exclude them here.
|
||||
const actionButtons = document.querySelectorAll('.project-actions a.btn');
|
||||
actionButtons.forEach(button => {
|
||||
button.addEventListener('click', function () {
|
||||
if (this.tagName === 'BUTTON') {
|
||||
const originalText = this.innerHTML;
|
||||
this.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...';
|
||||
this.disabled = true;
|
||||
|
||||
// Re-enable after form submission (in case of validation errors)
|
||||
setTimeout(() => {
|
||||
this.innerHTML = originalText;
|
||||
this.disabled = false;
|
||||
}, 3000);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user