1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/controllers/user/home/index.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

import HomescreenSettings from 'homescreenSettings';
import * as userSettings from 'userSettings';
import autoFocuser from 'autoFocuser';
import 'listViewStyle';
/* eslint-disable indent */
// Shortcuts
const UserSettings = userSettings.UserSettings;
export default function (view, params) {
2018-10-23 01:05:09 +03:00
function onBeforeUnload(e) {
if (hasChanges) {
2020-05-04 12:44:12 +02:00
e.returnValue = 'You currently have unsaved changes. Are you sure you wish to leave?';
}
2018-10-23 01:05:09 +03:00
}
let homescreenSettingsInstance;
let hasChanges;
const userId = params.userId || ApiClient.getCurrentUserId();
const currentSettings = userId === ApiClient.getCurrentUserId() ? userSettings : new UserSettings();
2020-05-04 12:44:12 +02:00
view.addEventListener('viewshow', function () {
window.addEventListener('beforeunload', onBeforeUnload);
if (homescreenSettingsInstance) {
homescreenSettingsInstance.loadData();
} else {
homescreenSettingsInstance = new HomescreenSettings({
serverId: ApiClient.serverId(),
userId: userId,
2020-05-04 12:44:12 +02:00
element: view.querySelector('.homeScreenSettingsContainer'),
2020-04-03 03:16:06 +09:00
userSettings: currentSettings,
enableSaveButton: true,
enableSaveConfirmation: true,
autoFocus: autoFocuser.isEnabled()
});
}
});
2020-05-04 12:44:12 +02:00
view.addEventListener('change', function () {
hasChanges = true;
});
2020-05-04 12:44:12 +02:00
view.addEventListener('viewdestroy', function () {
if (homescreenSettingsInstance) {
homescreenSettingsInstance.destroy();
homescreenSettingsInstance = null;
}
});
}
/* eslint-enable indent */