add connect to startup wizard

This commit is contained in:
Luke Pulverenti 2014-10-19 23:04:45 -04:00
parent 9855c3e6dc
commit 80f38f2eae
4 changed files with 133 additions and 93 deletions

View File

@ -29,7 +29,7 @@
<label for="chkSaveLocal">${LabelSaveLocalMetadata}</label>
<div class="fieldDescription">${LabelSaveLocalMetadataHelp}</div>
</li>
<li>
<li style="display:none;">
<label for="selectImageSavingConvention">${LabelImageSavingConvention}</label>
<select name="selectImageSavingConvention" id="selectImageSavingConvention" data-mini="true">
<option value="Compatible">${OptionImageSavingCompatible}</option>

View File

@ -76,76 +76,17 @@
if (currentConnectUsername == enteredConnectUsername) {
Dashboard.alert(Globalize.translate('SettingsSaved'));
} else {
updateConnectInfo(page, user);
ConnectHelper.updateUserInfo(user, $('#txtConnectUserName', page).val(), function () {
loadData(page);
});
}
} else {
Dashboard.navigate("userprofiles.html");
}
}
function updateConnectInfo(page, user) {
var currentConnectUsername = currentUser.ConnectUserName || '';
var enteredConnectUsername = $('#txtConnectUserName', page).val();
var linkUrl = ApiClient.getUrl('Users/' + user.Id + '/Connect/Link');
if (currentConnectUsername && !enteredConnectUsername) {
// Remove connect info
// Add/Update connect info
ApiClient.ajax({
type: "DELETE",
url: linkUrl
}).done(function () {
Dashboard.alert({
message: Globalize.translate('MessageMediaBrowserAccontRemoved'),
title: Globalize.translate('HeaderMediaBrowserAccountRemoved'),
callback: function () {
loadData(page);
}
});
});
}
else if (currentConnectUsername != enteredConnectUsername) {
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: linkUrl,
data: {
ConnectUsername: enteredConnectUsername
},
dataType: 'json'
}).done(function (result) {
var msgKey = result.IsPending ? 'MessagePendingMediaBrowserAccountAdded' : 'MessageMediaBrowserAccountAdded';
Dashboard.alert({
message: Globalize.translate(msgKey),
title: Globalize.translate('HeaderMediaBrowserAccountAdded'),
callback: function () {
loadData(page);
}
});
});
}
}
function saveUser(user, page) {
user.Name = $('#txtUserName', page).val();
@ -263,4 +204,73 @@
});
})(jQuery, window, document);
})(jQuery, window, document);
(function () {
window.ConnectHelper = {
updateUserInfo: function (user, newConnectUsername, actionCallback, noActionCallback) {
var currentConnectUsername = user.ConnectUserName || '';
var enteredConnectUsername = newConnectUsername;
var linkUrl = ApiClient.getUrl('Users/' + user.Id + '/Connect/Link');
if (currentConnectUsername && !enteredConnectUsername) {
// Remove connect info
// Add/Update connect info
ApiClient.ajax({
type: "DELETE",
url: linkUrl
}).done(function () {
Dashboard.alert({
message: Globalize.translate('MessageMediaBrowserAccontRemoved'),
title: Globalize.translate('HeaderMediaBrowserAccountRemoved'),
callback: actionCallback
});
});
}
else if (currentConnectUsername != enteredConnectUsername) {
// Add/Update connect info
ApiClient.ajax({
type: "POST",
url: linkUrl,
data: {
ConnectUsername: enteredConnectUsername
},
dataType: 'json'
}).done(function(result) {
var msgKey = result.IsPending ? 'MessagePendingMediaBrowserAccountAdded' : 'MessageMediaBrowserAccountAdded';
Dashboard.alert({
message: Globalize.translate(msgKey),
title: Globalize.translate('HeaderMediaBrowserAccountAdded'),
callback: actionCallback
});
});
} else {
if (noActionCallback) {
noActionCallback();
}
}
}
};
})();

View File

@ -1,7 +1,12 @@
(function ($, document, window) {
function getUsers() {
return ApiClient.getUsers({IsGuest: false});
}
function onSaveComplete(user) {
var page = $.mobile.activePage;
var userId = user.Id;
var metadataKey = "xbmcmetadata";
@ -14,9 +19,44 @@
ApiClient.updateNamedConfiguration(metadataKey, config).done(function () {
Dashboard.navigate('wizardlibrary.html');
});
});
var callback = function() {
Dashboard.navigate('wizardlibrary.html');
};
ConnectHelper.updateUserInfo(user, $('#txtConnectUserName', page).val(), callback, callback);
}
function submit(form) {
Dashboard.showLoadingMsg();
getUsers().done(function (users) {
var user;
if (users.length) {
user = users[0];
user.Name = $('#txtUsername', form).val();
ApiClient.updateUser(user).done(function () {
onSaveComplete(user);
});
} else {
user = { Name: $('#txtUsername', form).val() };
ApiClient.createUser(user).done(onSaveComplete);
}
});
}
function wizardUserPage() {
@ -24,33 +64,10 @@
var self = this;
self.onSubmit = function () {
Dashboard.showLoadingMsg();
var form = this;
ApiClient.getUsers().done(function (users) {
var user;
if (users.length) {
user = users[0];
user.Name = $('#txtUsername', form).val();
ApiClient.updateUser(user).done(function () {
onSaveComplete(user);
});
} else {
user = { Name: $('#txtUsername', form).val() };
ApiClient.createUser(user).done(onSaveComplete);
}
});
submit(form);
return false;
};
@ -62,11 +79,12 @@
var page = this;
ApiClient.getUsers().done(function (users) {
getUsers().done(function (users) {
var user = users[0] || { Name: "User" };
var user = users[0];
$('#txtUsername', page).val(user.Name);
$('#txtConnectUserName', page).val(user.ConnectUserName);
Dashboard.hideLoadingMsg();
});

View File

@ -22,6 +22,18 @@
<div class="fieldDescription">${MoreUsersCanBeAddedLater}</div>
</li>
</ul>
<h2>${HeaderOptionalLinkMediaBrowserAccount}</h2>
<br/>
<ul data-role="listview" class="ulForm">
<li>
<label for="txtConnectUserName">${LabelConnectUserName}</label>
<input id="txtConnectUserName" type="text" />
<div class="fieldDescription">
<div>${LabelConnectUserNameHelp}</div>
<div style="margin-top: .75em;"><a href="http://mediabrowser.tv/connect" target="_blank">${ButtonLearnMoreAboutMediaBrowserConnect}</a></div>
</div>
</li>
</ul>
<div class="wizardNavigation">
<button type="button" data-iconpos="left" data-icon="arrow-l" data-inline="true" onclick="history.back();">${LabelPrevious}</button>