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

56 lines
1.7 KiB
JavaScript
Raw Normal View History

import loading from 'loading';
import dom from 'dom';
import 'emby-input';
import 'emby-button';
/* eslint-disable indent */
2018-10-23 01:05:09 +03:00
function load(page, device, deviceOptions) {
2020-05-04 12:44:12 +02:00
page.querySelector('#txtCustomName', page).value = deviceOptions.CustomName || '';
page.querySelector('.reportedName', page).innerHTML = device.Name || '';
2018-10-23 01:05:09 +03:00
}
function loadData() {
2020-07-11 11:26:24 +01:00
const page = this;
2018-10-23 01:05:09 +03:00
loading.show();
2020-07-11 11:26:24 +01:00
const id = getParameterByName('id');
const promise1 = ApiClient.getJSON(ApiClient.getUrl('Devices/Info', {
Id: id
}));
2020-07-11 11:26:24 +01:00
const promise2 = ApiClient.getJSON(ApiClient.getUrl('Devices/Options', {
Id: id
}));
Promise.all([promise1, promise2]).then(function (responses) {
load(page, responses[0], responses[1]);
loading.hide();
});
2018-10-23 01:05:09 +03:00
}
function save(page) {
2020-07-11 11:26:24 +01:00
const id = getParameterByName('id');
2018-10-23 01:05:09 +03:00
ApiClient.ajax({
2020-05-04 12:44:12 +02:00
url: ApiClient.getUrl('Devices/Options', {
2018-10-23 01:05:09 +03:00
Id: id
}),
2020-05-04 12:44:12 +02:00
type: 'POST',
2018-10-23 01:05:09 +03:00
data: JSON.stringify({
2020-05-04 12:44:12 +02:00
CustomName: page.querySelector('#txtCustomName').value
2018-10-23 01:05:09 +03:00
}),
2020-05-04 12:44:12 +02:00
contentType: 'application/json'
}).then(Dashboard.processServerConfigurationUpdateResult);
2018-10-23 01:05:09 +03:00
}
function onSubmit(e) {
2020-07-11 11:26:24 +01:00
const form = this;
2020-05-04 12:44:12 +02:00
save(dom.parentWithClass(form, 'page'));
e.preventDefault();
return false;
2018-10-23 01:05:09 +03:00
}
export default function (view, params) {
2020-05-04 12:44:12 +02:00
view.querySelector('form').addEventListener('submit', onSubmit);
view.addEventListener('viewshow', loadData);
2020-07-11 11:26:24 +01:00
}
/* eslint-enable indent */