init vendors js file
add function to delete buttons add connection to add vendor api
This commit is contained in:
parent
f5054aea47
commit
b6dd9d4892
2 changed files with 38 additions and 14 deletions
14
app/static/vendors.js
Normal file
14
app/static/vendors.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
const delButtons = document.getElementsByClassName('del-button');
|
||||||
|
|
||||||
|
async function deleteVendor(id){
|
||||||
|
var result = await fetch(`/delete_vendor/${id}`, {method:'POST'});
|
||||||
|
var data = await result.json();
|
||||||
|
document.getElementById(`${id}-row`).remove();
|
||||||
|
}
|
||||||
|
document.addEventListener("DOMContentLoaded", (event) => {
|
||||||
|
for(let i = 0; i < delButtons.length; i++){
|
||||||
|
delButtons[i].addEventListener('click', e => {
|
||||||
|
deleteVendor(parseInt(e.target.id));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
@ -10,19 +10,28 @@
|
||||||
Vendors
|
Vendors
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
<form action="{{ url_for('add_vendor') }}" method="POST">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="vendorName" class="form-label">Add Vendor</label>
|
||||||
|
<input type="text" class="form-control" id="vendorName" name="vendor_name" placeholder="Enter vendor name" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary">Submit</button>
|
||||||
|
</form>
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">ID</th>
|
<th scope="col">ID</th>
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
|
<th scope="col">Delete</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for vendor in vendors %}
|
{% for vendor in vendors %}
|
||||||
<tr>
|
<tr id="{{vendor[0].id}}-row">
|
||||||
<th scope="row">{{vendor[0].id}}</th>
|
<th scope="row">{{vendor[0].id}}</th>
|
||||||
<th scope="row">{{vendor[0].name}}</th>
|
<th scope="row">{{vendor[0].name}}</th>
|
||||||
|
<th scope="row"><button class="btn btn-danger del-button" id="{{vendor[0].id}}">Delete</button></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
@ -33,4 +42,5 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
<script src="{{url_for('.static', filename='vendors.js')}}"></script>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue