mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
add connect helper
This commit is contained in:
parent
d09e598f8c
commit
088e52bc65
6 changed files with 203 additions and 287 deletions
|
@ -1,101 +1,6 @@
|
|||
define(['dialogHelper', 'jQuery', 'emby-input', 'emby-button', 'emby-collapse', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, $) {
|
||||
define(['dialogHelper', 'connectHelper', 'emby-input', 'emby-button', 'emby-collapse', 'paper-icon-button-light', 'formDialogStyle'], function (dialogHelper, connectHelper) {
|
||||
'use strict';
|
||||
|
||||
function updateUserInfo(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
|
||||
|
||||
}).then(function () {
|
||||
|
||||
Dashboard.alert({
|
||||
|
||||
message: Globalize.translate('MessageEmbyAccontRemoved'),
|
||||
title: Globalize.translate('HeaderEmbyAccountRemoved'),
|
||||
|
||||
callback: actionCallback
|
||||
|
||||
});
|
||||
}, function () {
|
||||
|
||||
Dashboard.alert({
|
||||
|
||||
message: Globalize.translate('ErrorRemovingEmbyConnectAccount')
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
else if (currentConnectUsername != enteredConnectUsername) {
|
||||
|
||||
// Add/Update connect info
|
||||
ApiClient.ajax({
|
||||
type: "POST",
|
||||
url: linkUrl,
|
||||
data: {
|
||||
ConnectUsername: enteredConnectUsername
|
||||
},
|
||||
dataType: 'json'
|
||||
|
||||
}).then(function (result) {
|
||||
|
||||
var msgKey = result.IsPending ? 'MessagePendingEmbyAccountAdded' : 'MessageEmbyAccountAdded';
|
||||
|
||||
Dashboard.alert({
|
||||
message: Globalize.translate(msgKey),
|
||||
title: Globalize.translate('HeaderEmbyAccountAdded'),
|
||||
|
||||
callback: actionCallback
|
||||
|
||||
});
|
||||
|
||||
}, function () {
|
||||
|
||||
showEmbyConnectErrorMessage('.');
|
||||
});
|
||||
|
||||
} else {
|
||||
if (noActionCallback) {
|
||||
noActionCallback();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showEmbyConnectErrorMessage(username) {
|
||||
|
||||
var html;
|
||||
var text;
|
||||
|
||||
if (username) {
|
||||
|
||||
html = Globalize.translate('ErrorAddingEmbyConnectAccount1', '<a href="https://emby.media/connect" target="_blank">https://emby.media/connect</a>');
|
||||
html += '<br/><br/>' + Globalize.translate('ErrorAddingEmbyConnectAccount2', 'apps@emby.media');
|
||||
|
||||
text = Globalize.translate('ErrorAddingEmbyConnectAccount1', 'https://emby.media/connect');
|
||||
text += '\n\n' + Globalize.translate('ErrorAddingEmbyConnectAccount2', 'apps@emby.media');
|
||||
|
||||
} else {
|
||||
html = text = Globalize.translate('DefaultErrorMessage');
|
||||
}
|
||||
|
||||
require(['alert'], function (alert) {
|
||||
alert({
|
||||
text: text,
|
||||
html: html
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
show: function () {
|
||||
return new Promise(function (resolve, reject) {
|
||||
|
@ -141,7 +46,8 @@
|
|||
dlg.querySelector('form').addEventListener('submit', function (e) {
|
||||
|
||||
ApiClient.getCurrentUser().then(function (user) {
|
||||
updateUserInfo(user, dlg.querySelector('#txtConnectUsername').value, function() {
|
||||
|
||||
connectHelper.updateUserLink(ApiClient, user, dlg.querySelector('#txtConnectUsername').value).then(function () {
|
||||
dialogHelper.close(dlg);
|
||||
}, function () {
|
||||
dialogHelper.close(dlg);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue