jellyfin-web/src/scripts/wizarduserpage.js

58 lines
2.0 KiB
JavaScript
Raw Normal View History

2018-12-11 16:54:50 -07:00
define(["loading", "globalize", "dashboardcss", "emby-input", "emby-button", "emby-linkbutton"], function(loading, globalize) {
2018-10-22 15:05:09 -07:00
"use strict";
function getApiClient() {
return ApiClient
}
function nextWizardPage() {
Dashboard.navigate("wizardlibrary.html")
}
function onUpdateUserComplete(result) {
if (loading.hide(), result.UserLinkResult) {
var msgKey = result.UserLinkResult.IsPending ? "MessagePendingEmbyAccountAdded" : "MessageEmbyAccountAdded";
Dashboard.alert({
message: globalize.translate(msgKey),
title: globalize.translate("HeaderEmbyAccountAdded"),
callback: nextWizardPage
})
} else nextWizardPage()
}
function submit(form) {
loading.show();
var apiClient = getApiClient();
apiClient.ajax({
type: "POST",
data: {
2018-12-11 16:54:50 -07:00
Name: form.querySelector("#txtUsername").value
2018-10-22 15:05:09 -07:00
},
url: apiClient.getUrl("Startup/User"),
dataType: "json"
}).then(onUpdateUserComplete, function(response) {
response && response.status;
})
}
function onSubmit(e) {
return submit(this), e.preventDefault(), !1
}
function onViewShow() {
loading.show();
var page = this,
apiClient = getApiClient();
apiClient.getJSON(apiClient.getUrl("Startup/User")).then(function(user) {
2018-12-11 16:54:50 -07:00
page.querySelector("#txtUsername").value = user.Name || "", loading.hide()
2018-10-22 15:05:09 -07:00
})
}
return function(view, params) {
view.querySelector(".wizardUserForm").addEventListener("submit", onSubmit), view.addEventListener("viewshow", function() {
document.querySelector(".skinHeader").classList.add("noHomeButtonHeader")
}), view.addEventListener("viewhide", function() {
document.querySelector(".skinHeader").classList.remove("noHomeButtonHeader")
}), view.addEventListener("viewshow", onViewShow)
}
2018-12-11 16:54:50 -07:00
});