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

96 lines
2.0 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
function getUsers() {
return ApiClient.getUsers({IsGuest: false});
}
2014-09-08 18:15:31 -07:00
function onSaveComplete(user) {
2014-10-19 20:04:45 -07:00
var page = $.mobile.activePage;
2014-09-08 18:15:31 -07:00
var userId = user.Id;
var metadataKey = "xbmcmetadata";
Dashboard.hideLoadingMsg();
2013-02-20 18:33:05 -07:00
2014-09-08 18:15:31 -07:00
ApiClient.getNamedConfiguration(metadataKey).done(function (config) {
config.UserId = userId;
ApiClient.updateNamedConfiguration(metadataKey, config).done(function () {
});
});
2014-10-19 20:04:45 -07:00
var callback = function() {
Dashboard.navigate('wizardlibrary.html');
};
ConnectHelper.updateUserInfo(user, $('#txtConnectUserName', page).val(), callback, callback);
}
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-10-19 20:04:45 -07:00
getUsers().done(function (users) {
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
var user;
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
if (users.length) {
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
user = users[0];
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
user.Name = $('#txtUsername', form).val();
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
ApiClient.updateUser(user).done(function () {
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
onSaveComplete(user);
});
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
} else {
2014-09-08 18:15:31 -07:00
2014-10-19 20:04:45 -07:00
user = { Name: $('#txtUsername', form).val() };
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
ApiClient.createUser(user).done(onSaveComplete);
}
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
});
}
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
function wizardUserPage() {
2013-02-20 18:33:05 -07:00
2014-10-19 20:04:45 -07:00
var self = this;
self.onSubmit = function () {
var form = this;
submit(form);
2013-02-20 18:33:05 -07:00
return false;
};
2013-02-20 18:33:05 -07:00
}
$(document).on('pageshow', "#wizardUserPage", function () {
Dashboard.showLoadingMsg();
var page = this;
2014-10-19 20:04:45 -07:00
getUsers().done(function (users) {
2014-10-19 20:04:45 -07:00
var user = users[0];
$('#txtUsername', page).val(user.Name);
2014-10-19 20:04:45 -07:00
$('#txtConnectUserName', page).val(user.ConnectUserName);
Dashboard.hideLoadingMsg();
});
});
window.WizardUserPage = new wizardUserPage();
2013-02-20 18:33:05 -07:00
})(jQuery, document, window);