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

105 lines
2.7 KiB
JavaScript
Raw Normal View History

2014-10-11 13:38:13 -07:00
(function () {
function deleteDevice(page, id) {
var msg = Globalize.translate('DeleteDeviceConfirmation');
Dashboard.confirm(msg, Globalize.translate('HeaderDeleteDevice'), function (result) {
if (result) {
Dashboard.showLoadingMsg();
ApiClient.ajax({
type: "DELETE",
url: ApiClient.getUrl('Devices', {
Id: id
})
}).done(function () {
loadData(page);
});
}
});
}
function load(page, devices) {
var html = '';
2015-10-16 15:21:03 -07:00
if (devices.length) {
html += '<div class="paperList">';
}
2014-10-11 13:38:13 -07:00
html += devices.map(function (d) {
var deviceHtml = '';
2015-08-20 20:21:27 -07:00
deviceHtml += '<paper-icon-item>';
2014-10-11 13:38:13 -07:00
2015-08-20 20:21:27 -07:00
deviceHtml += '<paper-fab class="listAvatar" style="background:#999;" icon="tablet-android" item-icon></paper-fab>';
2014-10-11 13:38:13 -07:00
2015-08-20 20:21:27 -07:00
deviceHtml += '<paper-item-body three-line>';
deviceHtml += '<a class="clearLink" href="device.html?id=' + d.Id + '">';
deviceHtml += '<div>';
2014-10-11 13:38:13 -07:00
deviceHtml += d.Name;
2015-08-20 20:21:27 -07:00
deviceHtml += '</div>';
2014-10-11 13:38:13 -07:00
2014-10-11 18:46:02 -07:00
if (d.AppName) {
2015-08-20 20:21:27 -07:00
deviceHtml += '<div secondary>';
2014-10-11 18:46:02 -07:00
deviceHtml += d.AppName;
2015-08-20 20:21:27 -07:00
deviceHtml += '</div>';
2014-10-11 18:46:02 -07:00
}
2014-10-11 13:38:13 -07:00
if (d.LastUserName) {
2015-08-20 20:21:27 -07:00
deviceHtml += '<div secondary>';
2014-10-11 13:38:13 -07:00
deviceHtml += Globalize.translate('DeviceLastUsedByUserName', d.LastUserName);
2015-08-20 20:21:27 -07:00
deviceHtml += '</div>';
2014-10-11 13:38:13 -07:00
}
deviceHtml += '</a>';
2015-08-20 20:21:27 -07:00
deviceHtml += '</paper-item-body>';
2014-10-11 13:38:13 -07:00
2015-08-20 20:21:27 -07:00
deviceHtml += '<paper-icon-button icon="delete" data-id="' + d.Id + '" title="' + Globalize.translate('ButtonDelete') + '" class="btnDeleteDevice"></paper-icon-button>';
deviceHtml += '</paper-icon-item>';
2014-10-11 13:38:13 -07:00
return deviceHtml;
}).join('');
2015-10-16 15:21:03 -07:00
if (devices.length) {
html += '</div>';
}
2014-10-11 13:38:13 -07:00
var elem = $('.devicesList', page).html(html).trigger('create');
$('.btnDeleteDevice', elem).on('click', function () {
deleteDevice(page, this.getAttribute('data-id'));
});
}
function loadData(page) {
Dashboard.showLoadingMsg();
2014-12-10 23:20:28 -07:00
ApiClient.getJSON(ApiClient.getUrl('Devices', {
2015-01-19 22:19:13 -07:00
SupportsPersistentIdentifier: true
2014-12-10 23:20:28 -07:00
2014-12-12 20:56:30 -07:00
})).done(function (result) {
2014-10-11 13:38:13 -07:00
2014-12-12 20:56:30 -07:00
load(page, result.Items);
2014-10-11 13:38:13 -07:00
Dashboard.hideLoadingMsg();
});
}
2015-09-24 10:08:10 -07:00
$(document).on('pageshow', "#devicesPage", function () {
2014-10-11 13:38:13 -07:00
var page = this;
loadData(page);
});
})();