1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/dashboard/devices/device.js

55 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import loading from '../../../components/loading/loading';
import dom from '../../../scripts/dom';
import '../../../elements/emby-input/emby-input';
import '../../../elements/emby-button/emby-button';
2022-04-10 02:22:13 -04:00
import Dashboard from '../../../utils/dashboard';
2022-04-05 15:58:12 -04:00
import { getParameterByName } from '../../../utils/url.ts';
2023-04-19 01:56:05 -04:00
function load(page, device, deviceOptions) {
page.querySelector('#txtCustomName', page).value = deviceOptions?.CustomName || '';
2023-04-19 01:56:05 -04:00
page.querySelector('.reportedName', page).innerText = device.Name || '';
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function loadData() {
const page = this;
loading.show();
const id = getParameterByName('id');
const device = ApiClient.getJSON(ApiClient.getUrl('Devices/Info', {
2023-04-19 01:56:05 -04:00
Id: id
}));
const deviceOptions = ApiClient.getJSON(ApiClient.getUrl('Devices/Options', {
2023-04-19 01:56:05 -04:00
Id: id
})).catch(() => undefined);
Promise.all([device, deviceOptions]).then(function (responses) {
2023-04-19 01:56:05 -04:00
load(page, responses[0], responses[1]);
loading.hide();
});
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function save(page) {
const id = getParameterByName('id');
ApiClient.ajax({
url: ApiClient.getUrl('Devices/Options', {
Id: id
2023-04-19 01:56:05 -04:00
}),
type: 'POST',
data: JSON.stringify({
CustomName: page.querySelector('#txtCustomName').value
}),
contentType: 'application/json'
}).then(Dashboard.processServerConfigurationUpdateResult);
}
2018-10-23 01:05:09 +03:00
2023-04-19 01:56:05 -04:00
function onSubmit(e) {
const form = this;
save(dom.parentWithClass(form, 'page'));
e.preventDefault();
return false;
}
2023-04-19 01:56:05 -04:00
export default function (view) {
view.querySelector('form').addEventListener('submit', onSubmit);
view.addEventListener('viewshow', loadData);
}