04/29 Modified project page to add button to enable/disable a project

This commit is contained in:
2026-04-29 15:42:33 -04:00
parent f166557f04
commit 96a343f284
+18 -19
View File
@@ -106,22 +106,18 @@
</div> </div>
<div class="project-actions"> <div class="project-actions">
<a href="{{ url_for('projects.edit_project', project_id=project.id) }}" <a href="{{ url_for('projects.edit_project', project_id=project.id) }}" class="btn btn-secondary">
class="btn btn-secondary">
<i class="fas fa-edit"></i> <i class="fas fa-edit"></i>
Edit Edit
</a> </a>
<!-- Activate/Deactivate button (for future use)
<form method="POST" action="{{ url_for('projects.toggle_project', project_id=project.id) }}" <form method="POST" action="{{ url_for('projects.toggle_project', project_id=project.id) }}"
style="display: inline;"> style="display: inline;">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button type="submit" <button type="submit" class="btn {% if project.active_status %}btn-warning{% else %}btn-success{% endif %}">
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> <i class="fas {% if project.active_status %}fa-pause{% else %}fa-play{% endif %}"></i>
{% if project.active_status %}Deactivate{% else %}Activate{% endif %} {% if project.active_status %}Deactivate{% else %}Activate{% endif %}
</button> </button>
</form> </form>
-->
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
@@ -145,7 +141,7 @@
{% block extra_scripts %} {% block extra_scripts %}
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function () {
// Add smooth animations to project cards // Add smooth animations to project cards
const projectCards = document.querySelectorAll('.project-card'); const projectCards = document.querySelectorAll('.project-card');
@@ -160,37 +156,40 @@ document.addEventListener('DOMContentLoaded', function() {
}, index * 100); }, 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"]'); const toggleForms = document.querySelectorAll('form[action*="toggle_project"]');
toggleForms.forEach(form => { toggleForms.forEach(form => {
form.addEventListener('submit', function(e) { form.addEventListener('submit', function (e) {
const button = form.querySelector('button'); const button = form.querySelector('button');
const action = button.textContent.trim(); const action = button.textContent.trim();
const projectName = form.closest('.project-card').querySelector('h3').textContent.trim(); const projectName = form.closest('.project-card').querySelector('h3').textContent.trim();
if (!confirm(`Are you sure you want to ${action.toLowerCase()} the project "${projectName}"?`)) { if (!confirm(`Are you sure you want to ${action.toLowerCase()} the project "${projectName}"?`)) {
e.preventDefault(); 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 // Add loading state to non-toggle action buttons (e.g. Edit links).
const actionButtons = document.querySelectorAll('.project-actions .btn'); // Toggle buttons are handled above via submit handler; exclude them here.
const actionButtons = document.querySelectorAll('.project-actions a.btn');
actionButtons.forEach(button => { actionButtons.forEach(button => {
button.addEventListener('click', function() { button.addEventListener('click', function () {
if (this.tagName === 'BUTTON') {
const originalText = this.innerHTML; const originalText = this.innerHTML;
this.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Processing...'; 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(() => { setTimeout(() => {
this.innerHTML = originalText; this.innerHTML = originalText;
this.disabled = false;
}, 3000); }, 3000);
}
}); });
}); });
}); });
</script> </script>
{% endblock %} {% endblock %}