170 lines
4.9 KiB
HTML
170 lines
4.9 KiB
HTML
{% extends "main.html" %}
|
|
|
|
{% block header %}
|
|
<div class="row mb-2">
|
|
<div class="col-sm-6">
|
|
<h1>{{ page_title | safe }}</h1>
|
|
</div>
|
|
<div class="col-sm-6">
|
|
<button class="btn btn-outline-primary float-sm-right mr-4" data-bs-toggle="modal" data-bs-target="#addModal" title="Add Group" aria-hidden="true">
|
|
<i class="fas fa-plus fa-sm fa-fw"></i> Group
|
|
</button>
|
|
</div>
|
|
</div>
|
|
{% endblock header %}
|
|
|
|
{% block content %}
|
|
<div class="col-12">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">Groups</h3>
|
|
<div class="card-tools">
|
|
<button type="button" class="btn btn-tool" onclick="reloadPageContent()" title="Refresh">
|
|
<i class="fas fa-sync"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<table class="table table-hover" id="myDataTable" width="100%" cellspacing="0">
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endblock content %}
|
|
|
|
{% block modal %}
|
|
{% include 'modals/groups.html' %}
|
|
{% endblock modal %}
|
|
|
|
{% block script %}
|
|
<script>
|
|
var reloadTime = 10000;
|
|
|
|
function reloadPageContent() {
|
|
//Clear the automatic page reload
|
|
clearTimeout(pageReloadTimeout);
|
|
|
|
//Reload the datatables content
|
|
$('#myDataTable').DataTable().ajax.reload(null, false);
|
|
|
|
//Set the automatic page reload
|
|
pageReloadTimeout = setTimeout(() => { reloadPageContent(); }, reloadTime);
|
|
}
|
|
|
|
function loadPageContent(){
|
|
|
|
// Configure Datatable
|
|
$('#myDataTable').DataTable({
|
|
ajax: {
|
|
url: "../api/groups/list_groups",
|
|
dataType: "json",
|
|
dataSrc: "data",
|
|
contentType: "application/json",
|
|
error: function (xhr, error, code) {
|
|
console.log(xhr, code);
|
|
}
|
|
},
|
|
columns: [
|
|
{ title: "Name", data: function (row, type, set) {
|
|
if (row.hasOwnProperty('name')) {
|
|
if (row.name)
|
|
return row.name
|
|
}
|
|
return '-'
|
|
},
|
|
},
|
|
{ title: "Description", data: function (row, type, set) {
|
|
if (row.hasOwnProperty('description')) {
|
|
if (row.description)
|
|
return row.description
|
|
}
|
|
return '-'
|
|
},
|
|
},
|
|
{ title: "Actions", data: function (row, type, set) {
|
|
links = ''
|
|
if (row.hasOwnProperty('id') && row.hasOwnProperty('name')) {
|
|
links = '<a href="#" onclick=editGroup(\''+row.id+'\',\''+row.name+'\')> <i class="fas fa-edit fa-lg" style="color:#ddd" title="Edit" aria-hidden="true"></i> </a>' +
|
|
' ' +
|
|
'<a href="#" onclick=deleteGroup(\''+row.id+'\',\''+row.name+'\')> <i class="fas fa-trash-alt fa-lg" style="color:#ddd" title="Delete" aria-hidden="true"></i> </a>'
|
|
}
|
|
return links
|
|
},
|
|
},
|
|
],
|
|
order: [],
|
|
});
|
|
|
|
//Set reload page content
|
|
pageReloadTimeout = setTimeout(() => { reloadPageContent(); }, reloadTime);
|
|
|
|
}
|
|
|
|
function loadInstructionsModal(){
|
|
$("#instructionsModal").modal('show');
|
|
}
|
|
|
|
// Add group
|
|
function addGroup(){
|
|
console.log("Info: adding new group");
|
|
data = $('#addForm').serialize();
|
|
$.post("../api/groups/add_group", data, function (data) {
|
|
console.log(data);
|
|
if (data.error_code >= 400){
|
|
alert(data.error);
|
|
}
|
|
//Aync type
|
|
setTimeout(() => { reloadPageContent(); }, 2000);
|
|
});
|
|
}
|
|
|
|
// Edit group
|
|
function editGroup(id, name){
|
|
console.log("Info: loading edit group " + name);
|
|
$.get("../api/groups/get_group", {
|
|
id: id,
|
|
}, function (data) {
|
|
data = data.metadata
|
|
console.log(data)
|
|
$('input[id=idEditInput]').val(data.id);
|
|
$('input[id=nameEditInput]').val(data.name);
|
|
$('input[id=descriptionEditInput]').val(data.description);
|
|
$("#editModal").modal('show');
|
|
});
|
|
}
|
|
|
|
// Update group
|
|
function updateGroup(){
|
|
console.log("Info: adding new group");
|
|
data = $('#editForm').serialize();
|
|
$.post("../api/groups/update_group", data, function (data) {
|
|
console.log(data);
|
|
if (data.error_code >= 400){
|
|
alert(data.error);
|
|
}
|
|
//Aync type
|
|
setTimeout(() => { reloadPageContent(); }, 2000);
|
|
});
|
|
}
|
|
// Delete group
|
|
function deleteGroup(id, name){
|
|
console.log("Info: confirming removal of group " + name);
|
|
if (confirm("Are you sure you want to remove group " + name + "?") == true) {
|
|
console.log("Info: deleting group " + name);
|
|
$.post("../api/groups/delete_group", {id: id}, function (data) {
|
|
setTimeout(() => { reloadPageContent(); }, 1000);
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
loadPageContent()
|
|
|
|
});
|
|
|
|
</script>
|
|
{% endblock script %}
|
|
|