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

158 lines
3.9 KiB
JavaScript
Raw Normal View History

2016-05-05 19:55:15 -07:00
define(['datetime', 'jQuery'], function (datetime, $) {
2016-10-22 22:11:46 -07:00
'use strict';
2016-01-19 20:02:14 -07:00
function revoke(page, key) {
2016-02-22 11:47:56 -07:00
require(['confirm'], function (confirm) {
2016-01-19 20:02:14 -07:00
2016-02-22 11:47:56 -07:00
confirm(Globalize.translate('MessageConfirmRevokeApiKey'), Globalize.translate('HeaderConfirmRevokeApiKey')).then(function () {
2016-01-19 20:02:14 -07:00
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('Auth/Keys/' + key)
}).then(function () {
loadData(page);
});
2016-02-22 11:47:56 -07:00
});
2016-01-19 20:02:14 -07:00
});
}
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;">';
2016-05-05 21:50:06 -07:00
var date = datetime.parseISO8601Date(item.DateCreated, true);
2016-01-19 20:02:14 -07:00
2016-05-05 19:55:15 -07:00
html += datetime.toLocaleDateString(date) + ' ' + datetime.getDisplayTime(date);
2016-01-19 20:02:14 -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().then(function (users) {
ApiClient.getJSON(ApiClient.getUrl('Auth/Keys')).then(function (result) {
renderKeys(page, result.Items, users);
});
});
}
2016-02-15 07:41:07 -07:00
function showNewKeyPrompt(page) {
require(['prompt'], function (prompt) {
// HeaderNewApiKeyHelp not used
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
prompt({
title: Globalize.translate('HeaderNewApiKey'),
label: Globalize.translate('LabelAppName'),
description: Globalize.translate('LabelAppNameExample')
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
}).then(function (value) {
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
ApiClient.ajax({
type: "POST",
url: ApiClient.getUrl('Auth/Keys', {
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
App: value
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
})
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
}).then(function () {
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
loadData(page);
});
});
2016-01-19 20:02:14 -07:00
2016-02-15 07:41:07 -07:00
});
2016-01-19 20:02:14 -07:00
}
2016-04-13 09:17:52 -07:00
function getTabs() {
return [
{
href: 'dashboardhosting.html',
name: Globalize.translate('TabHosting')
},
{
href: 'serversecurity.html',
name: Globalize.translate('TabSecurity')
}];
}
2016-01-19 20:02:14 -07:00
pageIdOn('pageinit', "serverSecurityPage", function () {
var page = this;
$('.btnNewKey', page).on('click', function () {
2016-02-15 07:41:07 -07:00
showNewKeyPrompt(page);
2016-01-19 20:02:14 -07:00
});
});
pageIdOn('pagebeforeshow', "serverSecurityPage", function () {
2016-04-13 09:17:52 -07:00
LibraryMenu.setTabs('adminadvanced', 1, getTabs);
2016-01-19 20:02:14 -07:00
var page = this;
loadData(page);
});
});