From 1967d248a7fbafe322b7fcefe093eec5d21e889a Mon Sep 17 00:00:00 2001 From: dkanada Date: Fri, 11 Jan 2019 20:36:17 +0900 Subject: [PATCH 1/4] reimplement page to add server --- src/addserver.html | 22 ++++++++++++++++ src/scripts/addserver.js | 55 ++++++++++++++++++++++++++++++++++++++++ src/scripts/site.js | 4 +-- src/selectserver.html | 2 +- 4 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 src/addserver.html create mode 100644 src/scripts/addserver.js diff --git a/src/addserver.html b/src/addserver.html new file mode 100644 index 0000000000..30b5ce7dab --- /dev/null +++ b/src/addserver.html @@ -0,0 +1,22 @@ +
+
+
+

${HeaderConnectToServer}

+
+ +
${LabelServerHostHelp}
+
+
+
+ +
+
+ + +
+
+
\ No newline at end of file diff --git a/src/scripts/addserver.js b/src/scripts/addserver.js new file mode 100644 index 0000000000..ea0999b683 --- /dev/null +++ b/src/scripts/addserver.js @@ -0,0 +1,55 @@ +define(["appSettings", "loading", "browser", "emby-linkbutton"], function(appSettings, loading, browser) { + "use strict"; + + function handleConnectionResult(page, result) { + switch (loading.hide(), result.State) { + case "SignedIn": + var apiClient = result.ApiClient; + Dashboard.onServerChanged(apiClient.getCurrentUserId(), apiClient.accessToken(), apiClient), Dashboard.navigate("home.html"); + break; + case "ServerSignIn": + Dashboard.navigate("login.html?serverid=" + result.Servers[0].Id, !1, "none"); + break; + case "ServerSelection": + Dashboard.navigate("selectserver.html", !1, "none"); + break; + case "ServerUpdateNeeded": + Dashboard.alert({ + message: Globalize.translate("ServerUpdateNeeded", 'https://github.com/jellyfin/jellyfin') + }); + break; + case "Unavailable": + Dashboard.alert({ + message: Globalize.translate("MessageUnableToConnectToServer"), + title: Globalize.translate("HeaderConnectionFailure") + }) + } + } + + function submitManualServer(page) { + var host = page.querySelector("#txtServerHost").value, + port = page.querySelector("#txtServerPort").value; + port && (host += ":" + port), loading.show(), ConnectionManager.connectToAddress(host, { + enableAutoLogin: appSettings.enableAutoLogin() + }).then(function(result) { + handleConnectionResult(page, result) + }, function() { + handleConnectionResult(page, { + State: "Unavailable" + }) + }) + } + + return function(view, params) { + view.querySelector(".manualServerForm").addEventListener("submit", onManualServerSubmit) + function onManualServerSubmit(e) { + return submitManualServer(view), e.preventDefault(), !1 + } + + function goBack() { + require(["appRouter"], function(appRouter) { + appRouter.back() + }) + } + } +}); diff --git a/src/scripts/site.js b/src/scripts/site.js index 070bcb43c5..8c1e6a01a4 100644 --- a/src/scripts/site.js +++ b/src/scripts/site.js @@ -375,12 +375,12 @@ var Dashboard = { autoFocus: !1, roles: "admin" }), defineRoute({ - path: "/connectlogin.html", + path: "/addserver.html", dependencies: ["emby-button", "emby-input"], autoFocus: !1, anonymous: !0, startup: !0, - controller: "scripts/connectlogin" + controller: "scripts/addserver" }), defineRoute({ path: "/dashboard.html", dependencies: [], diff --git a/src/selectserver.html b/src/selectserver.html index 0b41eb5a14..b7832cc147 100644 --- a/src/selectserver.html +++ b/src/selectserver.html @@ -13,7 +13,7 @@
- + ${ButtonAddServer} - diff --git a/src/scripts/addserver.js b/src/scripts/addserver.js index ea0999b683..3afb9c68a8 100644 --- a/src/scripts/addserver.js +++ b/src/scripts/addserver.js @@ -2,16 +2,17 @@ define(["appSettings", "loading", "browser", "emby-linkbutton"], function(appSet "use strict"; function handleConnectionResult(page, result) { - switch (loading.hide(), result.State) { + loading.hide(); + switch (result.State) { case "SignedIn": var apiClient = result.ApiClient; Dashboard.onServerChanged(apiClient.getCurrentUserId(), apiClient.accessToken(), apiClient), Dashboard.navigate("home.html"); break; case "ServerSignIn": - Dashboard.navigate("login.html?serverid=" + result.Servers[0].Id, !1, "none"); + Dashboard.navigate("login.html?serverid=" + result.Servers[0].Id, false, "none"); break; case "ServerSelection": - Dashboard.navigate("selectserver.html", !1, "none"); + Dashboard.navigate("selectserver.html", false, "none"); break; case "ServerUpdateNeeded": Dashboard.alert({ @@ -22,34 +23,43 @@ define(["appSettings", "loading", "browser", "emby-linkbutton"], function(appSet Dashboard.alert({ message: Globalize.translate("MessageUnableToConnectToServer"), title: Globalize.translate("HeaderConnectionFailure") - }) + }); } } function submitManualServer(page) { - var host = page.querySelector("#txtServerHost").value, - port = page.querySelector("#txtServerPort").value; - port && (host += ":" + port), loading.show(), ConnectionManager.connectToAddress(host, { + var host = page.querySelector("#txtServerHost").value; + var port = page.querySelector("#txtServerPort").value; + if (port) { + host += ":" + port; + } + + loading.show(); + ConnectionManager.connectToAddress(host, { enableAutoLogin: appSettings.enableAutoLogin() }).then(function(result) { - handleConnectionResult(page, result) + handleConnectionResult(page, result); }, function() { handleConnectionResult(page, { State: "Unavailable" - }) - }) + }); + }); } return function(view, params) { - view.querySelector(".manualServerForm").addEventListener("submit", onManualServerSubmit) + view.querySelector(".manualServerForm").addEventListener("submit", onManualServerSubmit); + view.querySelector(".btnCancelManualServer").addEventListener("click", goBack); + function onManualServerSubmit(e) { - return submitManualServer(view), e.preventDefault(), !1 + submitManualServer(view); + e.preventDefault(); + return false; } function goBack() { require(["appRouter"], function(appRouter) { - appRouter.back() - }) + appRouter.back(); + }); } } }); From d0f276f00cbc430ca6ce032ef92a73eddd55be6c Mon Sep 17 00:00:00 2001 From: dkanada Date: Fri, 11 Jan 2019 22:25:09 +0900 Subject: [PATCH 4/4] add to CONTRIBUTORS.md --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ac53258356..6e085c5853 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -9,6 +9,7 @@ - [bfayers](https://github.com/bfayers) - [Bond_009](https://github.com/Bond-009) - [AnthonyLavado](https://github.com/anthonylavado) + - [dkanada](https://github.com/dkanada) - [sparky8251](https://github.com/sparky8251) - [LeoVerto](https://github.com/LeoVerto) - [cvium](https://github.com/cvium)