mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Migrate to ES6
This commit is contained in:
parent
e5f0d77c30
commit
ae5fa9d304
13 changed files with 220 additions and 227 deletions
78
src/controllers/user/quickConnect/index.js
Normal file
78
src/controllers/user/quickConnect/index.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
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;
|
||||
});
|
||||
}
|
||||
|
||||
renderPage();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue