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>
|
||||||
|
|
||||||
<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 %}
|
||||||
@@ -160,7 +156,10 @@ 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) {
|
||||||
@@ -170,25 +169,25 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
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);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user