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

100 lines
2.4 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 = '';
html += '<ul data-role="listview" data-inset="true" data-split-icon="minus">';
html += devices.map(function (d) {
var deviceHtml = '';
deviceHtml += '<li>';
2014-10-11 18:46:02 -07:00
deviceHtml += '<a href="device.html?id=' + d.Id + '">';
2014-10-11 13:38:13 -07:00
deviceHtml += '<h3>';
deviceHtml += d.Name;
deviceHtml += '</h3>';
2014-10-11 18:46:02 -07:00
if (d.AppName) {
deviceHtml += '<p style="color:blue;">';
deviceHtml += d.AppName;
deviceHtml += '</p>';
}
2014-10-11 13:38:13 -07:00
if (d.LastUserName) {
deviceHtml += '<p style="color:green;">';
deviceHtml += Globalize.translate('DeviceLastUsedByUserName', d.LastUserName);
deviceHtml += '</p>';
}
deviceHtml += '</a>';
deviceHtml += '<a href="#" data-icon="minus" class="btnDeleteDevice" data-id="' + d.Id + '">';
deviceHtml += Globalize.translate('Delete');
deviceHtml += '</a>';
deviceHtml += '</li>';
return deviceHtml;
}).join('');
html += '</ul>';
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-05-15 08:46:20 -07:00
$(document).on('pageshown', "#devicesPage", function () {
2014-10-11 13:38:13 -07:00
var page = this;
loadData(page);
});
})();