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/session/addServer/index.js

75 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-08-14 08:46:34 +02:00
import appSettings from '../../../scripts/settings/appSettings';
import loading from '../../../components/loading/loading';
import globalize from '../../../scripts/globalize';
import '../../../elements/emby-button/emby-button';
2022-04-10 02:22:13 -04:00
import Dashboard from '../../../utils/dashboard';
import ServerConnections from '../../../components/ServerConnections';
import { ConnectionState } from '../../../utils/jellyfin-apiclient/ConnectionState.ts';
/* eslint-disable indent */
2019-01-11 20:36:17 +09:00
function handleConnectionResult(page, result) {
2019-01-11 20:52:44 +09:00
loading.hide();
switch (result.State) {
case ConnectionState.SignedIn: {
2020-07-15 09:29:15 +01:00
const apiClient = result.ApiClient;
2019-08-25 00:29:12 -07:00
Dashboard.onServerChanged(apiClient.getCurrentUserId(), apiClient.accessToken(), apiClient);
2020-05-04 12:44:12 +02:00
Dashboard.navigate('home.html');
2019-01-11 20:36:17 +09:00
break;
2020-07-15 09:29:15 +01:00
}
case ConnectionState.ServerSignIn:
2020-05-04 12:44:12 +02:00
Dashboard.navigate('login.html?serverid=' + result.Servers[0].Id, false, 'none');
2019-01-11 20:36:17 +09:00
break;
case ConnectionState.ServerSelection:
2020-05-04 12:44:12 +02:00
Dashboard.navigate('selectserver.html', false, 'none');
2019-01-11 20:36:17 +09:00
break;
case ConnectionState.ServerUpdateNeeded:
2019-01-11 20:36:17 +09:00
Dashboard.alert({
2020-05-04 12:44:12 +02:00
message: globalize.translate('ServerUpdateNeeded', '<a href="https://github.com/jellyfin/jellyfin">https://github.com/jellyfin/jellyfin</a>')
2019-01-11 20:36:17 +09:00
});
break;
case ConnectionState.Unavailable:
2019-01-11 20:36:17 +09:00
Dashboard.alert({
2020-05-04 12:44:12 +02:00
message: globalize.translate('MessageUnableToConnectToServer'),
title: globalize.translate('HeaderConnectionFailure')
2019-01-11 20:52:44 +09:00
});
2019-01-11 20:36:17 +09:00
}
}
2019-08-25 00:29:12 -07:00
function submitServer(page) {
2019-01-11 20:52:44 +09:00
loading.show();
2020-07-15 09:29:15 +01:00
const host = page.querySelector('#txtServerHost').value;
ServerConnections.connectToAddress(host, {
2019-01-11 20:36:17 +09:00
enableAutoLogin: appSettings.enableAutoLogin()
}).then(function(result) {
2019-01-11 20:52:44 +09:00
handleConnectionResult(page, result);
2019-01-11 20:36:17 +09:00
}, function() {
handleConnectionResult(page, {
State: ConnectionState.Unavailable
2019-01-11 20:52:44 +09:00
});
});
2019-01-11 20:36:17 +09:00
}
2021-01-26 22:20:12 -05:00
export default function(view) {
2020-05-04 12:44:12 +02:00
view.querySelector('.addServerForm').addEventListener('submit', onServerSubmit);
view.querySelector('.btnCancel').addEventListener('click', goBack);
2019-01-11 20:52:44 +09:00
2020-08-14 08:46:34 +02:00
import('../../../components/autoFocuser').then(({default: autoFocuser}) => {
2019-11-02 20:38:58 +03:00
autoFocuser.autoFocus(view);
});
2019-08-25 00:29:12 -07:00
function onServerSubmit(e) {
submitServer(view);
2019-01-11 20:52:44 +09:00
e.preventDefault();
return false;
2019-01-11 20:36:17 +09:00
}
function goBack() {
2021-04-10 13:16:07 +03:00
import('../../../components/appRouter').then(({appRouter}) => {
2019-01-11 20:52:44 +09:00
appRouter.back();
});
2019-01-11 20:36:17 +09:00
}
2020-07-15 09:29:15 +01:00
}
/* eslint-enable indent */