Added entity edit and delete buttons, added entity delete functionality
This commit is contained in:
@@ -397,6 +397,32 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Delete entity Modal -->
|
||||||
|
<div class="modal fade" id="deleteEntityModal" tabindex="-1" aria-hidden="true">
|
||||||
|
<div class="modal-dialog modal-m modal-dialog-scrollable">
|
||||||
|
<div class="modal-content">
|
||||||
|
|
||||||
|
<div class="modal-header bg-danger text-white">
|
||||||
|
<h2 class="modal-title" id="deleteEntityTitle">@T["Delete entity"]</h2>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>@T["Are you sure you want to delete this entity? This action cannot be undone."]</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" id="EntityConfirmDelete" class="btn btn-danger" data-bs-dismiss="modal">
|
||||||
|
@T["Delete"]
|
||||||
|
</button>
|
||||||
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||||
|
@T["Close"]
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var domains = JSON.parse('@Html.Raw(System.Text.Json.JsonSerializer.Serialize(domains))');
|
var domains = JSON.parse('@Html.Raw(System.Text.Json.JsonSerializer.Serialize(domains))');
|
||||||
@@ -681,6 +707,28 @@
|
|||||||
console.error('Error clearing searchdomain cache:', error);
|
console.error('Error clearing searchdomain cache:', error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document
|
||||||
|
.getElementById('EntityConfirmDelete')
|
||||||
|
.addEventListener('click', () => {
|
||||||
|
const domainKey = getSelectedDomainKey();
|
||||||
|
const entityName = document.getElementById('EntityConfirmDelete').getAttribute('data-name');
|
||||||
|
fetch(`/Entity/Delete?searchdomain=${encodeURIComponent(domains[domainKey])}&entityName=${entityName}`, {
|
||||||
|
method: 'GET'
|
||||||
|
}).then(async response => {
|
||||||
|
let result = await response.json();
|
||||||
|
if (response.ok && result.Success) {
|
||||||
|
// TODO add toast
|
||||||
|
console.log('Entity deleted successfully');
|
||||||
|
selectDomain(getSelectedDomainKey());
|
||||||
|
} else {
|
||||||
|
// TODO add toast
|
||||||
|
console.error('Failed to delete entity:', result.Message);
|
||||||
|
}
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Error deleting entity:', error);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function deleteSearchdomain(domainKey) {
|
function deleteSearchdomain(domainKey) {
|
||||||
@@ -888,15 +936,39 @@
|
|||||||
row.appendChild(nameCell);
|
row.appendChild(nameCell);
|
||||||
|
|
||||||
var actionCell = document.createElement('td');
|
var actionCell = document.createElement('td');
|
||||||
|
actionCell.classList.add('btn-group');
|
||||||
var detailsButton = document.createElement('button');
|
var detailsButton = document.createElement('button');
|
||||||
detailsButton.className = 'btn btn-info btn-sm';
|
detailsButton.className = 'btn btn-info btn-sm';
|
||||||
detailsButton.textContent = 'Details';
|
detailsButton.textContent = '@T["Details"]';
|
||||||
detailsButton.setAttribute("data-index", entities.findIndex(en => en == entity));
|
detailsButton.setAttribute("data-index", entities.findIndex(en => en == entity));
|
||||||
detailsButton.addEventListener('click', () => {
|
detailsButton.addEventListener('click', () => {
|
||||||
showEntityDetails(entity);
|
showEntityDetails(entity);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var updateButton = document.createElement('button');
|
||||||
|
updateButton.className = 'btn btn-warning btn-sm';
|
||||||
|
updateButton.textContent = '@T["Update"]';
|
||||||
|
updateButton.setAttribute("data-index", entities.findIndex(en => en == entity));
|
||||||
|
updateButton.addEventListener('click', () => {
|
||||||
|
updateEntity(entity);
|
||||||
|
});
|
||||||
|
|
||||||
|
var deleteButton = document.createElement('button');
|
||||||
|
deleteButton.className = 'btn btn-danger btn-sm';
|
||||||
|
deleteButton.textContent = '@T["Delete"]';
|
||||||
|
deleteButton.setAttribute("data-index", entities.findIndex(en => en == entity));
|
||||||
|
deleteButton.addEventListener('click', () => {
|
||||||
|
const modal = new bootstrap.Modal(
|
||||||
|
document.getElementById('deleteEntityModal')
|
||||||
|
);
|
||||||
|
modal.show();
|
||||||
|
let entityConfirmDelete = document.getElementById('EntityConfirmDelete');
|
||||||
|
entityConfirmDelete.setAttribute('data-name', entity.Name);
|
||||||
|
});
|
||||||
|
|
||||||
actionCell.appendChild(detailsButton);
|
actionCell.appendChild(detailsButton);
|
||||||
|
actionCell.appendChild(updateButton);
|
||||||
|
actionCell.appendChild(deleteButton);
|
||||||
row.appendChild(actionCell);
|
row.appendChild(actionCell);
|
||||||
|
|
||||||
tableBody.appendChild(row);
|
tableBody.appendChild(row);
|
||||||
|
|||||||
Reference in New Issue
Block a user