jellyfin-web/dashboard-ui/scripts/wizarduserpage.js

103 lines
2.5 KiB
JavaScript
Raw Normal View History

define(['jQuery'], function ($) {
2013-02-20 18:33:05 -07:00
2014-11-14 19:31:03 -07:00
function getApiClient() {
return ApiClient;
2014-10-19 20:04:45 -07:00
}
2014-11-14 19:31:03 -07:00
function onUpdateUserComplete(result) {
2014-09-08 18:15:31 -07:00
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-11-14 19:31:03 -07:00
if (result.UserLinkResult) {
2014-09-08 18:15:31 -07:00
2015-03-21 11:12:12 -07:00
var msgKey = result.UserLinkResult.IsPending ? 'MessagePendingEmbyAccountAdded' : 'MessageEmbyAccountAdded';
2014-09-08 18:15:31 -07:00
2014-11-14 19:31:03 -07:00
Dashboard.alert({
message: Globalize.translate(msgKey),
2015-03-21 11:12:12 -07:00
title: Globalize.translate('HeaderEmbyAccountAdded'),
2014-09-08 18:15:31 -07:00
2014-11-14 19:31:03 -07:00
callback: function () {
Dashboard.navigate('wizardlibrary.html');
}
2014-10-19 20:04:45 -07:00
2014-11-14 19:31:03 -07:00
});
2014-10-19 20:04:45 -07:00
2014-11-14 19:31:03 -07:00
} else {
2014-10-19 20:04:45 -07:00
Dashboard.navigate('wizardlibrary.html');
2014-11-14 19:31:03 -07:00
}
}
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
function submit(form) {
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-11-14 19:31:03 -07:00
var apiClient = getApiClient();
2013-02-20 18:33:05 -07:00
2014-11-14 19:31:03 -07:00
apiClient.ajax({
2013-02-20 18:33:05 -07:00
2014-11-14 19:31:03 -07:00
type: 'POST',
data: {
2013-02-20 18:33:05 -07:00
2015-07-30 07:34:46 -07:00
Name: form.querySelector('#txtUsername').value,
2015-08-20 14:13:50 -07:00
ConnectUserName: form.querySelector('#txtConnectUserName').value
2013-02-20 18:33:05 -07:00
2014-11-14 19:31:03 -07:00
},
url: apiClient.getUrl('Startup/User'),
dataType: 'json'
2013-02-20 18:33:05 -07:00
2015-12-14 08:43:03 -07:00
}).then(onUpdateUserComplete, function () {
2015-10-26 09:21:00 -07:00
2015-12-30 15:07:48 -07:00
showEmbyConnectErrorMessage(form.querySelector('#txtConnectUserName').value);
});
}
2015-10-26 09:21:00 -07:00
2015-12-30 15:07:48 -07:00
function showEmbyConnectErrorMessage(username) {
2015-10-26 09:21:00 -07:00
2015-12-30 15:07:48 -07:00
var msg;
if (username) {
msg = Globalize.translate('ErrorAddingEmbyConnectAccount1', '<a href="https://emby.media/connect" target="_blank">https://emby.media/connect</a>');
msg += '<br/><br/>' + Globalize.translate('ErrorAddingEmbyConnectAccount2', 'apps@emby.media');
} else {
msg = Globalize.translate('DefaultErrorMessage');
}
Dashboard.alert({
message: msg
2015-10-26 09:21:00 -07:00
});
2014-10-19 20:04:45 -07:00
}
2013-02-20 18:33:05 -07:00
2015-05-18 18:46:31 -07:00
function onSubmit() {
var form = this;
2013-02-20 18:33:05 -07:00
2015-05-18 18:46:31 -07:00
submit(form);
2014-10-19 20:04:45 -07:00
2015-05-18 18:46:31 -07:00
return false;
}
2014-10-19 20:04:45 -07:00
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#wizardUserPage", function () {
2013-02-20 18:33:05 -07:00
2015-05-18 18:46:31 -07:00
$('.wizardUserForm').off('submit', onSubmit).on('submit', onSubmit);
2013-02-20 18:33:05 -07:00
2015-09-24 10:08:10 -07:00
}).on('pageshow', "#wizardUserPage", function () {
Dashboard.showLoadingMsg();
var page = this;
2014-11-14 19:31:03 -07:00
var apiClient = getApiClient();
2015-12-14 08:43:03 -07:00
apiClient.getJSON(apiClient.getUrl('Startup/User')).then(function (user) {
2015-07-30 07:34:46 -07:00
page.querySelector('#txtUsername').value = user.Name;
page.querySelector('#txtConnectUserName').value = user.ConnectUserName;
Dashboard.hideLoadingMsg();
});
});
});