Implement component deletion
This commit is contained in:
		@@ -22,6 +22,7 @@
 | 
			
		||||
            <a class="btn btn-secondary mb-2" href="{{component.datasheet_link}}"><i class="bi bi-file-pdf-fill"></i> Datasheet</a>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
            <button class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#comp-edit-modal"><i class="bi bi-pencil-square"></i> Edit Component</button>
 | 
			
		||||
            <button class="btn btn-danger mb-2" data-bs-toggle="modal" data-bs-target="#component-delete-modal"><i class="bi bi-file-x"></i> Delete {{component.name}}</button>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <div class="col m-1">
 | 
			
		||||
@@ -144,15 +145,54 @@
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
{% endif %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
<!-- Delete modal -->
 | 
			
		||||
<div class="modal fade" id="component-delete-modal" tabindex="-1">
 | 
			
		||||
    <div class="modal-dialog modal-lg modal-fullscreen-lg-down">
 | 
			
		||||
        <div class="modal-content">
 | 
			
		||||
            <div class="modal-header">
 | 
			
		||||
                <h5>{{component.name}}</h5>
 | 
			
		||||
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="modal-body">
 | 
			
		||||
                <h4>Delete this Component?</h4>
 | 
			
		||||
                {% if delete_error %}
 | 
			
		||||
                <div class="alert alert-danger">
 | 
			
		||||
                    {{delete_error}}
 | 
			
		||||
                </div>
 | 
			
		||||
                {% if protected_stuff %}
 | 
			
		||||
                <h4>Following prevent the deletion:</h4>
 | 
			
		||||
                <ul>
 | 
			
		||||
                    {% for elem in protected_stuff %}
 | 
			
		||||
                    <li>{{elem}}</li>
 | 
			
		||||
                    {% endfor %}
 | 
			
		||||
                </ul>
 | 
			
		||||
                {% endif %}
 | 
			
		||||
                {% endif %}
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="modal-footer">
 | 
			
		||||
                <form action="" method="post">
 | 
			
		||||
                    {% csrf_token %}
 | 
			
		||||
                    <button type="submit" class="btn btn-danger" name="submit-component-delete"><i class="bi bi-file-x"></i> Delete {{component.name}}</button>
 | 
			
		||||
                </form>
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
{% include 'parts/modals/edit-component-modal.html' with heading="Edit "|add:component.name form=comp_form %}
 | 
			
		||||
{% endblock content %}
 | 
			
		||||
 | 
			
		||||
{% block custom_scripts %}
 | 
			
		||||
 | 
			
		||||
<script type="text/javascript">
 | 
			
		||||
{% if edit_form.errors %}
 | 
			
		||||
{% if comp_form.errors %}
 | 
			
		||||
bootstrap.Modal.getOrCreateInstance(document.getElementById('comp-edit-modal')).show()
 | 
			
		||||
{% endif %}
 | 
			
		||||
{% if delete_error %}
 | 
			
		||||
bootstrap.Modal.getOrCreateInstance(document.getElementById('component-delete-modal')).show();
 | 
			
		||||
{% endif %}
 | 
			
		||||
</script>
 | 
			
		||||
{% endblock custom_scripts %}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user