2018-07-09 19:27:22 +02:00
|
|
|
|
var apiKeysTable = $('#apikeys-table').DataTable({
|
|
|
|
|
'order': [[4, 'desc']],
|
|
|
|
|
'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
|
|
|
|
|
|
|
|
|
var createdApiKeyId = GetUriParam('CreatedApiKeyId');
|
|
|
|
|
if (createdApiKeyId !== undefined)
|
|
|
|
|
{
|
2020-01-28 19:27:18 +01:00
|
|
|
|
animateCSS("#apiKeyRow_" + createdApiKeyId, "pulse");
|
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();
|
2019-10-15 19:59:14 +02:00
|
|
|
|
}, 200));
|
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
|
|
|
|
{
|
|
|
|
|
var objectName = $(e.currentTarget).attr('data-apikey-apikey');
|
|
|
|
|
var objectId = $(e.currentTarget).attr('data-apikey-id');
|
|
|
|
|
|
|
|
|
|
bootbox.confirm({
|
2019-05-01 20:19:18 +02:00
|
|
|
|
message: __t('Are you sure to delete API key "%s"?', objectName),
|
2019-09-24 10:24:47 +02:00
|
|
|
|
closeButton: false,
|
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
|
|
|
|
|
|
|
|
|
function QrCodeForApiKey(apiKeyType, apiKey)
|
|
|
|
|
{
|
|
|
|
|
var content = U('/api') + '|' + apiKey;
|
|
|
|
|
if (apiKeyType === 'special-purpose-calendar-ical')
|
|
|
|
|
{
|
|
|
|
|
content = U('/api/calendar/ical?secret=' + apiKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QrCodeImgHtml(content);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 10:00:49 +02:00
|
|
|
|
$('.apikey-show-qr-button').on('click', function()
|
|
|
|
|
{
|
2020-12-20 19:53:28 +01:00
|
|
|
|
var qrcodeHtml = QrCodeForApiKey($(this).data('apikey-type'), $(this).data('apikey-key'));
|
2020-09-06 10:00:49 +02:00
|
|
|
|
bootbox.alert({
|
|
|
|
|
title: __t('API key'),
|
|
|
|
|
message: "<p class='text-center'>" + qrcodeHtml + "</p>",
|
|
|
|
|
closeButton: false
|
|
|
|
|
});
|
|
|
|
|
})
|