2013-04-15 18:46:17 -07:00
|
|
|
|
(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";
|
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
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-04-15 18:46:17 -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-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
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
return false;
|
|
|
|
|
};
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
$(document).on('pageshow', "#wizardUserPage", function () {
|
|
|
|
|
|
|
|
|
|
Dashboard.showLoadingMsg();
|
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2014-10-19 20:04:45 -07:00
|
|
|
|
getUsers().done(function (users) {
|
2013-04-15 18:46:17 -07:00
|
|
|
|
|
2014-10-19 20:04:45 -07:00
|
|
|
|
var user = users[0];
|
2013-04-15 18:46:17 -07:00
|
|
|
|
|
|
|
|
|
$('#txtUsername', page).val(user.Name);
|
2014-10-19 20:04:45 -07:00
|
|
|
|
$('#txtConnectUserName', page).val(user.ConnectUserName);
|
2013-04-15 18:46:17 -07:00
|
|
|
|
|
|
|
|
|
Dashboard.hideLoadingMsg();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.WizardUserPage = new wizardUserPage();
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
2013-04-15 18:46:17 -07:00
|
|
|
|
})(jQuery, document, window);
|