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

78 lines
1.6 KiB
JavaScript
Raw Normal View History

(function ($, document, window) {
2013-02-20 18:33:05 -07:00
2014-09-08 18:15:31 -07:00
function onSaveComplete(user) {
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 () {
Dashboard.navigate('wizardlibrary.html');
});
});
}
2013-02-20 18:33:05 -07:00
function wizardUserPage() {
2013-02-20 18:33:05 -07:00
var self = this;
2013-02-20 18:33:05 -07:00
self.onSubmit = function () {
Dashboard.showLoadingMsg();
2013-02-20 18:33:05 -07:00
2013-12-27 09:18:42 -07:00
var form = this;
2013-02-20 18:33:05 -07:00
ApiClient.getUsers().done(function (users) {
2013-02-20 18:33:05 -07:00
var user;
2013-02-20 18:33:05 -07:00
if (users.length) {
2013-02-20 18:33:05 -07:00
user = users[0];
2013-02-20 18:33:05 -07:00
2013-12-27 09:18:42 -07:00
user.Name = $('#txtUsername', form).val();
2013-02-20 18:33:05 -07:00
2014-09-08 18:15:31 -07:00
ApiClient.updateUser(user).done(function () {
onSaveComplete(user);
});
2013-02-20 18:33:05 -07:00
} else {
2013-02-20 18:33:05 -07:00
2013-12-27 09:18:42 -07:00
user = { Name: $('#txtUsername', form).val() };
2013-02-20 18:33:05 -07:00
ApiClient.createUser(user).done(onSaveComplete);
}
2013-02-20 18:33:05 -07:00
});
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;
ApiClient.getUsers().done(function (users) {
var user = users[0] || { Name: "User" };
$('#txtUsername', page).val(user.Name);
Dashboard.hideLoadingMsg();
});
});
window.WizardUserPage = new wizardUserPage();
2013-02-20 18:33:05 -07:00
})(jQuery, document, window);