2020-07-09 16:20:32 +01:00
|
|
|
import appSettings from 'appSettings';
|
|
|
|
import loading from 'loading';
|
|
|
|
import browser from 'browser';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import 'emby-button';
|
|
|
|
|
|
|
|
/* 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) {
|
2020-05-04 12:44:12 +02:00
|
|
|
case 'SignedIn':
|
2019-01-11 20:36:17 +09:00
|
|
|
var 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-05-04 12:44:12 +02:00
|
|
|
case 'ServerSignIn':
|
|
|
|
Dashboard.navigate('login.html?serverid=' + result.Servers[0].Id, false, 'none');
|
2019-01-11 20:36:17 +09:00
|
|
|
break;
|
2020-05-04 12:44:12 +02:00
|
|
|
case 'ServerSelection':
|
|
|
|
Dashboard.navigate('selectserver.html', false, 'none');
|
2019-01-11 20:36:17 +09:00
|
|
|
break;
|
2020-05-04 12:44:12 +02:00
|
|
|
case '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;
|
2020-05-04 12:44:12 +02:00
|
|
|
case '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-05-04 12:44:12 +02:00
|
|
|
var host = page.querySelector('#txtServerHost').value;
|
2019-01-11 20:52:44 +09:00
|
|
|
ConnectionManager.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, {
|
2020-05-04 12:44:12 +02:00
|
|
|
State: 'Unavailable'
|
2019-01-11 20:52:44 +09:00
|
|
|
});
|
|
|
|
});
|
2019-01-11 20:36:17 +09:00
|
|
|
}
|
|
|
|
|
2020-07-09 16:20:32 +01:00
|
|
|
export default function(view, params) {
|
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-07-09 16:20:32 +01:00
|
|
|
import('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() {
|
2020-07-09 16:20:32 +01:00
|
|
|
import('appRouter').then(({default: appRouter}) => {
|
2019-01-11 20:52:44 +09:00
|
|
|
appRouter.back();
|
|
|
|
});
|
2019-01-11 20:36:17 +09:00
|
|
|
}
|
2019-11-06 13:43:39 +03:00
|
|
|
};
|
2020-07-09 16:20:32 +01:00
|
|
|
|
|
|
|
/* eslint-enable indent */
|