mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
77 lines
2.6 KiB
JavaScript
77 lines
2.6 KiB
JavaScript
![]() |
import QuickConnectSettings from 'quickConnectSettings';
|
||
|
import globalize from 'globalize';
|
||
|
import toast from 'toast';
|
||
|
|
||
|
export default function (view) {
|
||
|
let quickConnectSettingsInstance = null;
|
||
|
|
||
|
view.addEventListener('viewshow', function () {
|
||
|
let codeElement = view.querySelector('#txtQuickConnectCode');
|
||
|
|
||
|
quickConnectSettingsInstance = new QuickConnectSettings({
|
||
|
page: view,
|
||
|
interval: 0
|
||
|
});
|
||
|
|
||
|
view.querySelector('#btnQuickConnectActivate').addEventListener('click', () => {
|
||
|
quickConnectSettingsInstance.activate(quickConnectSettingsInstance).then(() => {
|
||
|
renderPage();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
view.querySelector('#btnQuickConnectAuthorize').addEventListener('click', () => {
|
||
|
if (!codeElement.validity.valid) {
|
||
|
toast(globalize.translate('QuickConnectInvalidCode'));
|
||
|
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
let code = codeElement.value;
|
||
|
quickConnectSettingsInstance.authorize(code);
|
||
|
});
|
||
|
|
||
|
renderPage();
|
||
|
});
|
||
|
view.addEventListener('viewbeforehide', function () {
|
||
|
if (quickConnectSettingsInstance) {
|
||
|
quickConnectSettingsInstance.submit();
|
||
|
}
|
||
|
onDestroy();
|
||
|
});
|
||
|
view.addEventListener('viewdestroy', function () {
|
||
|
onDestroy();
|
||
|
});
|
||
|
|
||
|
function onDestroy() {
|
||
|
if (quickConnectSettingsInstance) {
|
||
|
quickConnectSettingsInstance.destroy();
|
||
|
quickConnectSettingsInstance = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function renderPage(forceActive = false) {
|
||
|
ApiClient.getQuickConnect('Status').then((status) => {
|
||
|
let btn = view.querySelector('#btnQuickConnectActivate');
|
||
|
let container = view.querySelector('.quickConnectSettingsContainer');
|
||
|
|
||
|
// The activation button should only be visible when quick connect is unavailable (with the text replaced with an error) or when it is available (so it can be activated)
|
||
|
// The authorization container is only usable when quick connect is active, so it should be hidden otherwise
|
||
|
container.style.display = 'none';
|
||
|
|
||
|
if (status === 'Unavailable') {
|
||
|
btn.textContent = globalize.translate('QuickConnectNotAvailable');
|
||
|
btn.disabled = true;
|
||
|
btn.classList.remove('button-submit');
|
||
|
btn.classList.add('button');
|
||
|
} else if (status === 'Active' || forceActive) {
|
||
|
container.style.display = '';
|
||
|
btn.style.display = 'none';
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}).catch((e) => {
|
||
|
throw e;
|
||
|
});
|
||
|
}
|
||
|
}
|