jellyfin-web/dashboard-ui/scripts/serversecurity.js

143 lines
3.4 KiB
JavaScript
Raw Normal View History

2014-10-15 20:26:39 -07:00
(function ($, document) {
2014-07-11 19:31:08 -07:00
function revoke(page, key) {
Dashboard.confirm(Globalize.translate('MessageConfirmRevokeApiKey'), Globalize.translate('HeaderConfirmRevokeApiKey'), function (result) {
if (result) {
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "DELETE",
2014-10-15 20:26:39 -07:00
url: ApiClient.getUrl('Auth/Keys/' + key)
2015-05-15 08:46:20 -07:00
2014-07-11 19:31:08 -07:00
}).done(function () {
loadData(page);
});
}
});
}
function renderKeys(page, keys, users) {
var rows = keys.map(function (item) {
var html = '';
html += '<tr>';
html += '<td>';
html += '<button data-token="' + item.AccessToken + '" class="btnRevoke" data-mini="true" title="' + Globalize.translate('ButtonRevoke') + '" style="margin:0;">' + Globalize.translate('ButtonRevoke') + '</button>';
html += '</td>';
html += '<td style="vertical-align:middle;">';
html += (item.AccessToken);
html += '</td>';
html += '<td style="vertical-align:middle;">';
html += (item.AppName || '');
html += '</td>';
html += '<td style="vertical-align:middle;">';
html += (item.DeviceName || '');
html += '</td>';
html += '<td style="vertical-align:middle;">';
var user = users.filter(function (u) {
return u.Id == item.UserId;
})[0];
if (user) {
html += user.Name;
}
html += '</td>';
html += '<td style="vertical-align:middle;">';
var date = parseISO8601Date(item.DateCreated, { toLocal: true });
2015-05-22 12:16:14 -07:00
html += date.toLocaleDateString() + ' ' + LibraryBrowser.getDisplayTime(date);
2014-07-11 19:31:08 -07:00
html += '</td>';
html += '</tr>';
return html;
}).join('');
var elem = $('.resultBody', page).html(rows).parents('.tblApiKeys').table("refresh").trigger('create');
$('.btnRevoke', elem).on('click', function () {
revoke(page, this.getAttribute('data-token'));
});
Dashboard.hideLoadingMsg();
}
function loadData(page) {
Dashboard.showLoadingMsg();
ApiClient.getUsers().done(function (users) {
ApiClient.getJSON(ApiClient.getUrl('Auth/Keys')).done(function (result) {
renderKeys(page, result.Items, users);
});
});
}
2015-05-15 08:46:20 -07:00
function onSubmit() {
var form = this;
var page = $(form).parents('.page');
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
Dashboard.showLoadingMsg();
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('Auth/Keys/', {
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
App: $('#txtAppName', form).val()
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
})
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
}).done(function () {
$('.newKeyPanel', page).panel('close');
loadData(page);
2014-07-11 19:31:08 -07:00
});
2015-05-15 08:46:20 -07:00
return false;
}
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
$(document).on('pageinitdepends', "#serverSecurityPage", function () {
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
var page = this;
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
$('.btnNewKey', page).on('click', function () {
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
$('.newKeyPanel', page).panel('toggle');
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
$('#txtAppName', page).val('').focus();
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
});
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
$('.newKeyForm').off('submit', onSubmit).on('submit', onSubmit);
2014-07-11 19:31:08 -07:00
2015-05-19 12:15:40 -07:00
}).on('pageshowready', "#serverSecurityPage", function () {
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
var page = this;
2014-07-11 19:31:08 -07:00
2015-05-15 08:46:20 -07:00
loadData(page);
});
2014-07-11 19:31:08 -07:00
2014-10-15 20:26:39 -07:00
})(jQuery, document);