2020-06-21 04:38:42 +03:00
|
|
|
import layoutManager from 'layoutManager';
|
|
|
|
import focusManager from 'focusManager';
|
|
|
|
import globalize from 'globalize';
|
|
|
|
import loading from 'loading';
|
|
|
|
import homeSections from 'homeSections';
|
|
|
|
import dom from 'dom';
|
|
|
|
import events from 'events';
|
|
|
|
import 'listViewStyle';
|
|
|
|
import 'emby-select';
|
|
|
|
import 'emby-checkbox';
|
|
|
|
|
|
|
|
/* eslint-disable indent */
|
|
|
|
|
|
|
|
const numConfigurableSections = 7;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function renderViews(page, user, result) {
|
2020-06-21 04:38:42 +03:00
|
|
|
let folderHtml = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
folderHtml += '<div class="checkboxList">';
|
2020-06-21 04:38:42 +03:00
|
|
|
folderHtml += result.map(i => {
|
|
|
|
let currentHtml = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const id = `chkGroupFolder${i.Id}`;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const isChecked = user.Configuration.GroupedFolders.includes(i.Id);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const checkedHtml = isChecked ? ' checked="checked"' : '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
currentHtml += '<label>';
|
2020-06-21 04:38:42 +03:00
|
|
|
currentHtml += `<input type="checkbox" is="emby-checkbox" class="chkGroupFolder" data-folderid="${i.Id}" id="${id}"${checkedHtml}/>`;
|
|
|
|
currentHtml += `<span>${i.Name}</span>`;
|
2019-01-10 15:39:37 +03:00
|
|
|
currentHtml += '</label>';
|
|
|
|
|
|
|
|
return currentHtml;
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
folderHtml += '</div>';
|
|
|
|
|
|
|
|
page.querySelector('.folderGroupList').innerHTML = folderHtml;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getLandingScreenOptions(type) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const list = [];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (type === 'movies') {
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Movies'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'movies',
|
|
|
|
isDefault: true
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Suggestions'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'suggestions'
|
|
|
|
});
|
2020-05-26 17:56:54 -04:00
|
|
|
list.push({
|
|
|
|
name: globalize.translate('Genres'),
|
|
|
|
value: 'genres'
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Favorites'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'favorites'
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Collections'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'collections'
|
|
|
|
});
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (type === 'tvshows') {
|
2019-01-10 15:39:37 +03:00
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Shows'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'shows',
|
|
|
|
isDefault: true
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Suggestions'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'suggestions'
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Latest'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'latest'
|
|
|
|
});
|
2020-05-26 17:56:54 -04:00
|
|
|
list.push({
|
|
|
|
name: globalize.translate('Genres'),
|
|
|
|
value: 'genres'
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Favorites'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'favorites'
|
|
|
|
});
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (type === 'music') {
|
2019-01-10 15:39:37 +03:00
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Suggestions'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'suggestions',
|
|
|
|
isDefault: true
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Albums'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'albums'
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('HeaderAlbumArtists'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'albumartists'
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Artists'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'artists'
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Playlists'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'playlists'
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Genres'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'genres'
|
|
|
|
});
|
2019-11-23 00:29:38 +09:00
|
|
|
} else if (type === 'livetv') {
|
2019-01-10 15:39:37 +03:00
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Suggestions'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'suggestions',
|
|
|
|
isDefault: true
|
|
|
|
});
|
|
|
|
list.push({
|
2019-02-03 02:41:16 +09:00
|
|
|
name: globalize.translate('Guide'),
|
2019-01-10 15:39:37 +03:00
|
|
|
value: 'guide'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getLandingScreenOptionsHtml(type, userValue) {
|
2020-06-21 04:38:42 +03:00
|
|
|
return getLandingScreenOptions(type).map(o => {
|
|
|
|
const selected = userValue === o.value || (o.isDefault && !userValue);
|
|
|
|
const selectedHtml = selected ? ' selected' : '';
|
|
|
|
const optionValue = o.isDefault ? '' : o.value;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
return `<option value="${optionValue}"${selectedHtml}>${o.name}</option>`;
|
2019-01-10 15:39:37 +03:00
|
|
|
}).join('');
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderViewOrder(context, user, result) {
|
2020-06-21 04:38:42 +03:00
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-07-19 16:15:11 +02:00
|
|
|
html += result.Items.map((view) => {
|
2020-06-21 04:38:42 +03:00
|
|
|
let currentHtml = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
currentHtml += `<div class="listItem viewItem" data-viewid="${view.Id}">`;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-04-26 02:37:28 +03:00
|
|
|
currentHtml += '<span class="material-icons listItemIcon folder_open"></span>';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
currentHtml += '<div class="listItemBody">';
|
|
|
|
|
|
|
|
currentHtml += '<div>';
|
|
|
|
currentHtml += view.Name;
|
|
|
|
currentHtml += '</div>';
|
|
|
|
|
|
|
|
currentHtml += '</div>';
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
currentHtml += `<button type="button" is="paper-icon-button-light" class="btnViewItemUp btnViewItemMove autoSize" title="${globalize.translate('Up')}"><span class="material-icons keyboard_arrow_up"></span></button>`;
|
|
|
|
currentHtml += `<button type="button" is="paper-icon-button-light" class="btnViewItemDown btnViewItemMove autoSize" title="${globalize.translate('Down')}"><span class="material-icons keyboard_arrow_down"></span></button>`;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
currentHtml += '</div>';
|
|
|
|
|
|
|
|
return currentHtml;
|
|
|
|
}).join('');
|
|
|
|
|
|
|
|
context.querySelector('.viewOrderList').innerHTML = html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function updateHomeSectionValues(context, userSettings) {
|
2020-06-21 04:38:42 +03:00
|
|
|
for (let i = 1; i <= 7; i++) {
|
|
|
|
const select = context.querySelector(`#selectHomeSection${i}`);
|
|
|
|
const defaultValue = homeSections.getDefaultSection(i - 1);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const option = select.querySelector(`option[value=${defaultValue}]`) || select.querySelector('option[value=""]');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const userValue = userSettings.get(`homesection${i - 1}`);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
option.value = '';
|
|
|
|
|
|
|
|
if (userValue === defaultValue || !userValue) {
|
|
|
|
select.value = '';
|
|
|
|
} else {
|
|
|
|
select.value = userValue;
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
context.querySelector('.selectTVHomeScreen').value = userSettings.get('tvhome') || '';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getPerLibrarySettingsHtml(item, user, userSettings, apiClient) {
|
2020-06-21 04:38:42 +03:00
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
let isChecked;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (item.Type === 'Channel' || item.CollectionType === 'boxsets' || item.CollectionType === 'playlists') {
|
2020-06-21 04:38:42 +03:00
|
|
|
isChecked = !(user.Configuration.MyMediaExcludes || []).includes(item.Id);
|
2019-01-10 15:39:37 +03:00
|
|
|
html += '<div>';
|
|
|
|
html += '<label>';
|
2020-06-21 04:38:42 +03:00
|
|
|
html += `<input type="checkbox" is="emby-checkbox" class="chkIncludeInMyMedia" data-folderid="${item.Id}"${isChecked ? ' checked="checked"' : ''}/>`;
|
|
|
|
html += `<span>${globalize.translate('DisplayInMyMedia')}</span>`;
|
2019-01-10 15:39:37 +03:00
|
|
|
html += '</label>';
|
|
|
|
html += '</div>';
|
|
|
|
}
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const excludeFromLatest = ['playlists', 'livetv', 'boxsets', 'channels'];
|
|
|
|
if (!excludeFromLatest.includes(item.CollectionType || '')) {
|
|
|
|
isChecked = !user.Configuration.LatestItemsExcludes.includes(item.Id);
|
2019-01-10 15:39:37 +03:00
|
|
|
html += '<label class="fldIncludeInLatest">';
|
2020-06-21 04:38:42 +03:00
|
|
|
html += `<input type="checkbox" is="emby-checkbox" class="chkIncludeInLatest" data-folderid="${item.Id}"${isChecked ? ' checked="checked"' : ''}/>`;
|
|
|
|
html += `<span>${globalize.translate('DisplayInOtherHomeScreenSections')}</span>`;
|
2019-01-10 15:39:37 +03:00
|
|
|
html += '</label>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (html) {
|
2020-06-21 04:38:42 +03:00
|
|
|
html = `<div class="checkboxListContainer">${html}</div>`;
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (item.CollectionType === 'movies' || item.CollectionType === 'tvshows' || item.CollectionType === 'music' || item.CollectionType === 'livetv') {
|
2020-06-21 04:38:42 +03:00
|
|
|
const idForLanding = item.CollectionType === 'livetv' ? item.CollectionType : item.Id;
|
2019-01-10 15:39:37 +03:00
|
|
|
html += '<div class="selectContainer">';
|
2020-06-21 04:38:42 +03:00
|
|
|
html += `<select is="emby-select" class="selectLanding" data-folderid="${idForLanding}" label="${globalize.translate('LabelDefaultScreen')}">`;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const userValue = userSettings.get(`landing-${idForLanding}`);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
html += getLandingScreenOptionsHtml(item.CollectionType, userValue);
|
|
|
|
|
|
|
|
html += '</select>';
|
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (html) {
|
2020-06-21 04:38:42 +03:00
|
|
|
let prefix = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
prefix += '<div class="verticalSection">';
|
|
|
|
|
|
|
|
prefix += '<h2 class="sectionTitle">';
|
|
|
|
prefix += item.Name;
|
|
|
|
prefix += '</h2>';
|
|
|
|
|
|
|
|
html = prefix + html;
|
|
|
|
html += '</div>';
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function renderPerLibrarySettings(context, user, userViews, userSettings, apiClient) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const elem = context.querySelector('.perLibrarySettings');
|
|
|
|
let html = '';
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
for (let i = 0, length = userViews.length; i < length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
html += getPerLibrarySettingsHtml(userViews[i], user, userSettings, apiClient);
|
|
|
|
}
|
|
|
|
|
|
|
|
elem.innerHTML = html;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadForm(context, user, userSettings, apiClient) {
|
2019-01-10 15:39:37 +03:00
|
|
|
context.querySelector('.chkHidePlayedFromLatest').checked = user.Configuration.HidePlayedInLatest || false;
|
|
|
|
|
|
|
|
updateHomeSectionValues(context, userSettings);
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const promise1 = apiClient.getUserViews({ IncludeHidden: true }, user.Id);
|
|
|
|
const promise2 = apiClient.getJSON(apiClient.getUrl(`Users/${user.Id}/GroupingOptions`));
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
Promise.all([promise1, promise2]).then(responses => {
|
2019-01-10 15:39:37 +03:00
|
|
|
renderViewOrder(context, user, responses[0]);
|
|
|
|
|
|
|
|
renderPerLibrarySettings(context, user, responses[0].Items, userSettings, apiClient);
|
|
|
|
|
|
|
|
renderViews(context, user, responses[1]);
|
|
|
|
|
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function onSectionOrderListClick(e) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const target = dom.parentWithClass(e.target, 'btnViewItemMove');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (target) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const viewItem = dom.parentWithClass(target, 'viewItem');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
if (viewItem) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (target.classList.contains('btnViewItemDown')) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const next = viewItem.nextSibling;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (next) {
|
|
|
|
viewItem.parentNode.removeChild(viewItem);
|
|
|
|
next.parentNode.insertBefore(viewItem, next.nextSibling);
|
2019-11-02 23:35:44 +03:00
|
|
|
focusManager.focus(e.target);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
} else {
|
2020-06-21 04:38:42 +03:00
|
|
|
const prev = viewItem.previousSibling;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
if (prev) {
|
|
|
|
viewItem.parentNode.removeChild(viewItem);
|
|
|
|
prev.parentNode.insertBefore(viewItem, prev);
|
2019-11-02 23:35:44 +03:00
|
|
|
focusManager.focus(e.target);
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCheckboxItems(selector, context, isChecked) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const inputs = context.querySelectorAll(selector);
|
|
|
|
const list = [];
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
for (let i = 0, length = inputs.length; i < length; i++) {
|
2019-01-10 15:39:37 +03:00
|
|
|
if (inputs[i].checked === isChecked) {
|
|
|
|
list.push(inputs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveUser(context, user, userSettingsInstance, apiClient) {
|
2019-01-10 15:39:37 +03:00
|
|
|
user.Configuration.HidePlayedInLatest = context.querySelector('.chkHidePlayedFromLatest').checked;
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
user.Configuration.LatestItemsExcludes = getCheckboxItems('.chkIncludeInLatest', context, false).map(i => {
|
2019-01-10 15:39:37 +03:00
|
|
|
return i.getAttribute('data-folderid');
|
|
|
|
});
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
user.Configuration.MyMediaExcludes = getCheckboxItems('.chkIncludeInMyMedia', context, false).map(i => {
|
2019-01-10 15:39:37 +03:00
|
|
|
return i.getAttribute('data-folderid');
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
user.Configuration.GroupedFolders = getCheckboxItems('.chkGroupFolder', context, true).map(i => {
|
2019-01-10 15:39:37 +03:00
|
|
|
return i.getAttribute('data-folderid');
|
|
|
|
});
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const viewItems = context.querySelectorAll('.viewItem');
|
|
|
|
const orderedViews = [];
|
|
|
|
let i;
|
|
|
|
let length;
|
2019-01-10 15:39:37 +03:00
|
|
|
for (i = 0, length = viewItems.length; i < length; i++) {
|
|
|
|
orderedViews.push(viewItems[i].getAttribute('data-viewid'));
|
|
|
|
}
|
|
|
|
|
|
|
|
user.Configuration.OrderedViews = orderedViews;
|
|
|
|
|
|
|
|
userSettingsInstance.set('tvhome', context.querySelector('.selectTVHomeScreen').value);
|
|
|
|
|
|
|
|
userSettingsInstance.set('homesection0', context.querySelector('#selectHomeSection1').value);
|
|
|
|
userSettingsInstance.set('homesection1', context.querySelector('#selectHomeSection2').value);
|
|
|
|
userSettingsInstance.set('homesection2', context.querySelector('#selectHomeSection3').value);
|
|
|
|
userSettingsInstance.set('homesection3', context.querySelector('#selectHomeSection4').value);
|
|
|
|
userSettingsInstance.set('homesection4', context.querySelector('#selectHomeSection5').value);
|
|
|
|
userSettingsInstance.set('homesection5', context.querySelector('#selectHomeSection6').value);
|
|
|
|
userSettingsInstance.set('homesection6', context.querySelector('#selectHomeSection7').value);
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const selectLandings = context.querySelectorAll('.selectLanding');
|
2018-10-23 01:05:09 +03:00
|
|
|
for (i = 0, length = selectLandings.length; i < length; i++) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const selectLanding = selectLandings[i];
|
|
|
|
userSettingsInstance.set(`landing-${selectLanding.getAttribute('data-folderid')}`, selectLanding.value);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
return apiClient.updateUserConfiguration(user.Id, user.Configuration);
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function save(instance, context, userId, userSettings, apiClient, enableSaveConfirmation) {
|
2019-01-10 15:39:37 +03:00
|
|
|
loading.show();
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
apiClient.getUser(userId).then(user => {
|
|
|
|
saveUser(context, user, userSettings, apiClient).then(() => {
|
2019-01-10 15:39:37 +03:00
|
|
|
loading.hide();
|
|
|
|
if (enableSaveConfirmation) {
|
2020-06-21 04:38:42 +03:00
|
|
|
import('toast').then(({default: toast}) => {
|
2019-02-03 02:41:16 +09:00
|
|
|
toast(globalize.translate('SettingsSaved'));
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
events.trigger(instance, 'saved');
|
2020-06-21 04:38:42 +03:00
|
|
|
}, () => {
|
2019-01-10 15:39:37 +03:00
|
|
|
loading.hide();
|
|
|
|
});
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSubmit(e) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const self = this;
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(self.options.serverId);
|
2020-06-21 04:38:42 +03:00
|
|
|
const userId = self.options.userId;
|
|
|
|
const userSettings = self.options.userSettings;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
userSettings.setUserInfo(userId, apiClient).then(() => {
|
|
|
|
const enableSaveConfirmation = self.options.enableSaveConfirmation;
|
2019-01-10 15:39:37 +03:00
|
|
|
save(self, self.options.element, userId, userSettings, apiClient, enableSaveConfirmation);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Disable default form submission
|
|
|
|
if (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
return false;
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function onChange(e) {
|
2020-06-21 04:38:42 +03:00
|
|
|
const chkIncludeInMyMedia = dom.parentWithClass(e.target, 'chkIncludeInMyMedia');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (!chkIncludeInMyMedia) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const section = dom.parentWithClass(chkIncludeInMyMedia, 'verticalSection');
|
|
|
|
const fldIncludeInLatest = section.querySelector('.fldIncludeInLatest');
|
2019-01-10 15:39:37 +03:00
|
|
|
if (fldIncludeInLatest) {
|
|
|
|
if (chkIncludeInMyMedia.checked) {
|
|
|
|
fldIncludeInLatest.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
fldIncludeInLatest.classList.add('hide');
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function embed(options, self) {
|
2020-06-21 04:38:42 +03:00
|
|
|
return import('text!./homeScreenSettings.template.html').then(({default: template}) => {
|
|
|
|
for (let i = 1; i <= numConfigurableSections; i++) {
|
|
|
|
template = template.replace(`{section${i}label}`, globalize.translate('LabelHomeScreenSectionValue', i));
|
2019-01-10 15:39:37 +03:00
|
|
|
}
|
|
|
|
|
2020-07-18 09:21:15 +01:00
|
|
|
options.element.innerHTML = globalize.translateHtml(template, 'core');
|
2019-01-10 15:39:37 +03:00
|
|
|
|
|
|
|
options.element.querySelector('.viewOrderList').addEventListener('click', onSectionOrderListClick);
|
|
|
|
options.element.querySelector('form').addEventListener('submit', onSubmit.bind(self));
|
|
|
|
options.element.addEventListener('change', onChange);
|
|
|
|
|
|
|
|
if (options.enableSaveButton) {
|
|
|
|
options.element.querySelector('.btnSave').classList.remove('hide');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (layoutManager.tv) {
|
|
|
|
options.element.querySelector('.selectTVHomeScreenContainer').classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
options.element.querySelector('.selectTVHomeScreenContainer').classList.add('hide');
|
|
|
|
}
|
|
|
|
|
|
|
|
self.loadData(options.autoFocus);
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
class HomeScreenSettings {
|
|
|
|
constructor(options) {
|
|
|
|
this.options = options;
|
|
|
|
embed(options, this);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
loadData(autoFocus) {
|
|
|
|
const self = this;
|
|
|
|
const context = self.options.element;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
loading.show();
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
const userId = self.options.userId;
|
2020-08-30 06:06:47 +02:00
|
|
|
const apiClient = window.connectionManager.getApiClient(self.options.serverId);
|
2020-06-21 04:38:42 +03:00
|
|
|
const userSettings = self.options.userSettings;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
apiClient.getUser(userId).then(user => {
|
|
|
|
userSettings.setUserInfo(userId, apiClient).then(() => {
|
|
|
|
self.dataLoaded = true;
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
loadForm(context, user, userSettings, apiClient);
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
if (autoFocus) {
|
|
|
|
focusManager.autoFocus(context);
|
|
|
|
}
|
|
|
|
});
|
2019-01-10 15:39:37 +03:00
|
|
|
});
|
2020-06-21 04:38:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
submit() {
|
|
|
|
onSubmit.call(this);
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
destroy() {
|
|
|
|
this.options = null;
|
|
|
|
}
|
|
|
|
}
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
/* eslint-enable indent */
|
2019-01-10 15:39:37 +03:00
|
|
|
|
2020-06-21 04:38:42 +03:00
|
|
|
export default HomeScreenSettings;
|