2018-07-09 19:27:22 +02:00
|
|
|
|
var apiKeysTable = $('#apikeys-table').DataTable({
|
2023-05-23 20:31:51 +02:00
|
|
|
|
'order': [[6, 'desc']],
|
2018-07-09 19:27:22 +02:00
|
|
|
|
'columnDefs': [
|
2020-01-03 14:18:56 +01:00
|
|
|
|
{ 'orderable': false, 'targets': 0 },
|
|
|
|
|
{ 'searchable': false, "targets": 0 }
|
2020-12-07 19:48:33 +01:00
|
|
|
|
].concat($.fn.dataTable.defaults.columnDefs)
|
2018-07-09 19:27:22 +02:00
|
|
|
|
});
|
2019-01-05 20:06:35 +01:00
|
|
|
|
$('#apikeys-table tbody').removeClass("d-none");
|
2019-03-04 17:43:12 +01:00
|
|
|
|
apiKeysTable.columns.adjust().draw();
|
2018-07-09 19:27:22 +02:00
|
|
|
|
|
2019-10-15 19:59:14 +02:00
|
|
|
|
$("#search").on("keyup", Delay(function()
|
2018-07-09 19:27:22 +02:00
|
|
|
|
{
|
|
|
|
|
var value = $(this).val();
|
|
|
|
|
if (value === "all")
|
|
|
|
|
{
|
|
|
|
|
value = "";
|
|
|
|
|
}
|
2019-01-19 00:37:21 -07:00
|
|
|
|
|
2018-07-09 19:27:22 +02:00
|
|
|
|
apiKeysTable.search(value).draw();
|
2025-01-11 15:41:04 +01:00
|
|
|
|
}, 500));
|
2018-07-09 19:27:22 +02:00
|
|
|
|
|
2020-11-07 14:53:45 +01:00
|
|
|
|
$("#clear-filter-button").on("click", function()
|
|
|
|
|
{
|
|
|
|
|
$("#search").val("");
|
|
|
|
|
apiKeysTable.search("").draw();
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-30 12:18:16 +02:00
|
|
|
|
$(document).on('click', '.apikey-delete-button', function(e)
|
2018-04-21 19:18:00 +02:00
|
|
|
|
{
|
2023-05-23 20:31:51 +02:00
|
|
|
|
var button = $(e.currentTarget);
|
|
|
|
|
var objectName = button.attr('data-apikey-key');
|
2024-12-29 20:18:10 +01:00
|
|
|
|
var objectDescription = button.attr('data-apikey-description');
|
2023-05-23 20:31:51 +02:00
|
|
|
|
var objectId = button.attr('data-apikey-id');
|
2018-04-21 19:18:00 +02:00
|
|
|
|
|
2024-12-29 20:18:10 +01:00
|
|
|
|
if (objectDescription)
|
|
|
|
|
{
|
|
|
|
|
objectName = objectDescription;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 19:18:00 +02:00
|
|
|
|
bootbox.confirm({
|
2024-12-26 10:46:54 +01:00
|
|
|
|
message: __t('Are you sure you want to delete API key "%s"?', objectName),
|
2019-09-24 10:24:47 +02:00
|
|
|
|
closeButton: false,
|
2024-12-29 20:18:10 +01:00
|
|
|
|
className: "text-break",
|
2018-04-21 19:18:00 +02:00
|
|
|
|
buttons: {
|
|
|
|
|
confirm: {
|
2019-05-01 20:19:18 +02:00
|
|
|
|
label: __t('Yes'),
|
2018-04-21 19:18:00 +02:00
|
|
|
|
className: 'btn-success'
|
|
|
|
|
},
|
|
|
|
|
cancel: {
|
2019-05-01 20:19:18 +02:00
|
|
|
|
label: __t('No'),
|
2018-04-21 19:18:00 +02:00
|
|
|
|
className: 'btn-danger'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
callback: function(result)
|
|
|
|
|
{
|
|
|
|
|
if (result === true)
|
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
|
Grocy.Api.Delete('objects/api_keys/' + objectId, {},
|
2018-04-21 19:18:00 +02:00
|
|
|
|
function(result)
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U('/manageapikeys');
|
|
|
|
|
},
|
|
|
|
|
function(xhr)
|
|
|
|
|
{
|
|
|
|
|
console.error(xhr);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2020-12-20 19:53:28 +01:00
|
|
|
|
|
2023-05-23 20:31:51 +02:00
|
|
|
|
$(".apikey-show-qr-button").on("click", function()
|
2020-12-20 19:53:28 +01:00
|
|
|
|
{
|
2023-05-23 20:31:51 +02:00
|
|
|
|
var button = $(this);
|
|
|
|
|
var apiKey = button.data("apikey-key");
|
|
|
|
|
var apiKeyType = button.data("apikey-type");
|
|
|
|
|
var apiKeyDescription = button.data("apikey-description");
|
|
|
|
|
|
|
|
|
|
var content = U("/api") + "|" + apiKey;
|
|
|
|
|
if (apiKeyType === "special-purpose-calendar-ical")
|
2020-12-20 19:53:28 +01:00
|
|
|
|
{
|
2023-05-23 20:31:51 +02:00
|
|
|
|
content = U("/api/calendar/ical?secret=" + apiKey);
|
2020-12-20 19:53:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 10:00:49 +02:00
|
|
|
|
bootbox.alert({
|
2023-05-23 21:22:54 +02:00
|
|
|
|
message: "<div class='text-center'><h1>" + __t("API key") + "</h1><h2 class='text-muted'>" + apiKeyDescription + "</h2><p><hr>" + QrCodeImgHtml(content) + "</p></div>",
|
2020-09-06 10:00:49 +02:00
|
|
|
|
closeButton: false
|
|
|
|
|
});
|
2023-05-23 20:31:51 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#add-api-key-button").on("click", function(e)
|
|
|
|
|
{
|
|
|
|
|
$("#add-api-key-modal").modal("show");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#add-api-key-modal").on("shown.bs.modal", function(e)
|
|
|
|
|
{
|
2025-01-12 17:57:50 +01:00
|
|
|
|
setTimeout(function()
|
|
|
|
|
{
|
|
|
|
|
$("#description").focus();
|
|
|
|
|
}, 500);
|
2023-05-23 20:31:51 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$("#new-api-key-button").on("click", function(e)
|
|
|
|
|
{
|
|
|
|
|
window.location.href = U("/manageapikeys/new?description=" + encodeURIComponent($("#description").val()));
|
|
|
|
|
});
|