sftpgo-mirror/templates/users.html

236 lines
8.9 KiB
HTML
Raw Normal View History

{{template "base" .}}
{{define "title"}}{{.Title}}{{end}}
{{define "extra_css"}}
<link href="/static/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">
<link href="/static/vendor/datatables/select.bootstrap4.min.css" rel="stylesheet">
<link href="/static/vendor/datatables/buttons.bootstrap4.min.css" rel="stylesheet">
{{end}}
{{define "page_body"}}
<div id="errorMsg" class="card mb-4 border-left-warning" style="display: none;">
<div id="errorTxt" class="card-body text-form-error"></div>
</div>
2019-10-13 10:07:22 +00:00
<div id="successMsg" class="card mb-4 border-left-success" style="display: none;">
<div id="successTxt" class="card-body"></div>
</div>
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">View and manage users</h6>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>ID</th>
<th>Username</th>
<th>Status</th>
<th>Expiration</th>
<th>Permissions</th>
<th>Bandwidth</th>
<th>Quota</th>
<th>Other</th>
</tr>
</thead>
<tbody>
{{range .Users}}
<tr>
<td>{{.ID}}</td>
<td>{{.Username}}</td>
<td>{{if eq .Status 1 }}Active{{else}}Inactive{{end}}</td>
<td>{{.GetExpirationDateAsString}}</td>
<td>{{.GetPermissionsAsString}}</td>
<td>{{.GetBandwidthAsString}}</td>
<td>{{.GetQuotaSummary}}</td>
<td>{{.GetInfoString}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
</div>
{{end}}
{{define "dialog"}}
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModalLabel">
Confirmation required
</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">Do you want to delete the selected user?</div>
<div class="modal-footer">
<button class="btn btn-secondary" type="button" data-dismiss="modal">
Cancel
</button>
<a class="btn btn-warning" href="#" onclick="deleteAction()">
Delete
</a>
</div>
</div>
</div>
</div>
{{end}}
{{define "extra_js"}}
<script src="/static/vendor/datatables/jquery.dataTables.min.js"></script>
<script src="/static/vendor/datatables/dataTables.bootstrap4.min.js"></script>
<script src="/static/vendor/datatables/dataTables.select.min.js"></script>
<script src="/static/vendor/datatables/select.bootstrap4.min.js"></script>
<script src="/static/vendor/datatables/dataTables.buttons.min.js"></script>
<script src="/static/vendor/datatables/buttons.bootstrap4.min.js"></script>
<script type="text/javascript">
function deleteAction() {
var table = $('#dataTable').DataTable();
table.button(2).enable(false);
var userID = table.row({ selected: true }).data()[0];
var path = '{{.APIUserURL}}'.trimEnd("/") + "/" + userID;
$('#deleteModal').modal('hide');
$.ajax({
url: path,
type: 'DELETE',
dataType: 'json',
timeout: 15000,
success: function (result) {
table.button(2).enable(true);
window.location.href = '{{.UsersURL}}';
},
error: function ($xhr, textStatus, errorThrown) {
console.log("delete error")
table.button(2).enable(true);
var txt = "Unable to delete the selected user";
if ($xhr) {
var json = $xhr.responseJSON;
if (json) {
txt += ": " + json.error;
}
}
$('#errorTxt').text(txt);
$('#errorMsg').show();
setTimeout(function () {
$('#errorMsg').hide();
}, 5000);
}
});
}
$(document).ready(function () {
$.fn.dataTable.ext.buttons.add = {
text: 'Add',
action: function (e, dt, node, config) {
window.location.href = '{{.UserURL}}';
}
};
$.fn.dataTable.ext.buttons.edit = {
text: 'Edit',
action: function (e, dt, node, config) {
var userID = dt.row({ selected: true }).data()[0];
var path = '{{.UserURL}}'.trimEnd("/") + "/" + userID;
window.location.href = path;
},
enabled: false
};
$.fn.dataTable.ext.buttons.delete = {
text: 'Delete',
action: function (e, dt, node, config) {
/*console.log("delete clicked, num row selected: " + dt.rows({ selected: true }).count());
var data = dt.rows({ selected: true }).data();
for (var i = 0; i < data.length; i++) {
console.log("selected row data: " + JSON.stringify(data[i]));
}*/
$('#deleteModal').modal('show');
},
enabled: false
};
2019-10-13 10:07:22 +00:00
$.fn.dataTable.ext.buttons.quota_scan = {
text: 'Quota scan',
action: function (e, dt, node, config) {
table.button(3).enable(false);
var username = dt.row({ selected: true }).data()[1];
var path = '{{.APIQuotaScanURL}}'
$.ajax({
url: path,
type: 'POST',
dataType: 'json',
data: JSON.stringify({ "username": username }),
timeout: 15000,
success: function (result) {
table.button(3).enable(true);
$('#successTxt').text("Quota scan started for the selected user. Please reload the user's page to check when the scan ends");
$('#successMsg').show();
setTimeout(function () {
$('#successMsg').hide();
}, 5000);
},
error: function ($xhr, textStatus, errorThrown) {
console.log("quota scan error")
table.button(3).enable(true);
var txt = "Unable to update quota for the selected user";
if ($xhr) {
var json = $xhr.responseJSON;
if (json) {
2019-10-13 11:08:19 +00:00
if (json.message) {
txt += ": " + json.message;
} else if (json.error) {
txt += ": " + json.error;
}
2019-10-13 10:07:22 +00:00
}
}
$('#errorTxt').text(txt);
$('#errorMsg').show();
setTimeout(function () {
$('#errorMsg').hide();
}, 5000);
}
});
},
enabled: false
};
var table = $('#dataTable').DataTable({
dom: "<'row'<'col-sm-12'B>>" +
"<'row'<'col-sm-12 col-md-6'l><'col-sm-12 col-md-6'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
select: true,
buttons: [
2019-10-13 10:07:22 +00:00
'add', 'edit', 'delete', 'quota_scan'
],
"columnDefs": [
{
"targets": [0],
"visible": false,
"searchable": false
},
],
"scrollX": false,
"order": [[1, 'asc']]
});
table.on('select deselect', function () {
var selectedRows = table.rows({ selected: true }).count();
table.button(1).enable(selectedRows == 1);
table.button(2).enable(selectedRows == 1);
2019-10-13 10:07:22 +00:00
table.button(3).enable(selectedRows == 1);
});
});
</script>
{{end}}