mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Refactor QuickConnect helper functions
This commit is contained in:
parent
05b0a2518e
commit
394a3d9f49
3 changed files with 39 additions and 49 deletions
36
src/controllers/user/quickConnect/helper.js
Normal file
36
src/controllers/user/quickConnect/helper.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import globalize from '../../../scripts/globalize';
|
||||
import toast from '../../../components/toast/toast';
|
||||
import Dashboard from '../../../scripts/clientUtils';
|
||||
|
||||
export const authorize = (code) => {
|
||||
const url = ApiClient.getUrl('/QuickConnect/Authorize?Code=' + code);
|
||||
ApiClient.ajax({
|
||||
type: 'POST',
|
||||
url: url
|
||||
}, true).then(() => {
|
||||
toast(globalize.translate('QuickConnectAuthorizeSuccess'));
|
||||
}).catch(() => {
|
||||
toast(globalize.translate('QuickConnectAuthorizeFail'));
|
||||
});
|
||||
|
||||
// prevent bubbling
|
||||
return false;
|
||||
};
|
||||
|
||||
export const activate = () => {
|
||||
const url = ApiClient.getUrl('/QuickConnect/Activate');
|
||||
return ApiClient.ajax({
|
||||
type: 'POST',
|
||||
url: url
|
||||
}).then(() => {
|
||||
toast(globalize.translate('QuickConnectActivationSuccessful'));
|
||||
return true;
|
||||
}).catch((e) => {
|
||||
console.error('Error activating quick connect. Error:', e);
|
||||
Dashboard.alert({
|
||||
title: globalize.translate('HeaderError'),
|
||||
message: globalize.translate('DefaultErrorMessage')
|
||||
});
|
||||
throw e;
|
||||
});
|
||||
};
|
|
@ -1,17 +1,13 @@
|
|||
import QuickConnectSettings from '../../../components/quickConnectSettings/quickConnectSettings';
|
||||
import { activate, authorize } from './helper';
|
||||
import globalize from '../../../scripts/globalize';
|
||||
import toast from '../../../components/toast/toast';
|
||||
|
||||
export default function (view) {
|
||||
let quickConnectSettingsInstance = null;
|
||||
|
||||
view.addEventListener('viewshow', function () {
|
||||
const codeElement = view.querySelector('#txtQuickConnectCode');
|
||||
|
||||
quickConnectSettingsInstance = new QuickConnectSettings();
|
||||
|
||||
view.querySelector('#btnQuickConnectActivate').addEventListener('click', () => {
|
||||
quickConnectSettingsInstance.activate(quickConnectSettingsInstance).then(() => {
|
||||
activate().then(() => {
|
||||
renderPage();
|
||||
});
|
||||
});
|
||||
|
@ -24,7 +20,7 @@ export default function (view) {
|
|||
}
|
||||
|
||||
const code = codeElement.value;
|
||||
quickConnectSettingsInstance.authorize(code);
|
||||
authorize(code);
|
||||
});
|
||||
|
||||
view.querySelector('.quickConnectSettingsContainer').addEventListener('submit', (e) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue