2020-05-04 12:44:12 +02:00
|
|
|
define(['backdrop', 'userSettings', 'libraryMenu'], function (backdrop, userSettings, libraryMenu) {
|
|
|
|
'use strict';
|
2018-10-23 01:05:09 +03:00
|
|
|
|
2020-04-06 23:45:50 +02:00
|
|
|
var cache = {};
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
function enabled() {
|
2019-10-08 00:56:51 +03:00
|
|
|
return userSettings.enableBackdrops();
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function getBackdropItemIds(apiClient, userId, types, parentId) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var key = `backdrops2_${userId + (types || '') + (parentId || '')}`;
|
2019-10-08 00:56:51 +03:00
|
|
|
var data = cache[key];
|
|
|
|
|
|
|
|
if (data) {
|
2020-04-06 23:45:50 +02:00
|
|
|
console.debug(`Found backdrop id list in cache. Key: ${key}`);
|
2019-10-08 00:56:51 +03:00
|
|
|
data = JSON.parse(data);
|
|
|
|
return Promise.resolve(data);
|
|
|
|
}
|
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var options = {
|
2020-05-04 12:44:12 +02:00
|
|
|
SortBy: 'IsFavoriteOrLiked,Random',
|
2018-10-23 01:05:09 +03:00
|
|
|
Limit: 20,
|
2019-10-08 00:56:51 +03:00
|
|
|
Recursive: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
IncludeItemTypes: types,
|
2020-05-04 12:44:12 +02:00
|
|
|
ImageTypes: 'Backdrop',
|
2018-10-23 01:05:09 +03:00
|
|
|
ParentId: parentId,
|
2019-10-08 00:56:51 +03:00
|
|
|
EnableTotalRecordCount: false
|
2018-10-23 01:05:09 +03:00
|
|
|
};
|
2019-10-08 00:56:51 +03:00
|
|
|
return apiClient.getItems(apiClient.getCurrentUserId(), options).then(function (result) {
|
|
|
|
var images = result.Items.map(function (i) {
|
2018-10-23 01:05:09 +03:00
|
|
|
return {
|
|
|
|
Id: i.Id,
|
|
|
|
tag: i.BackdropImageTags[0],
|
|
|
|
ServerId: i.ServerId
|
2019-10-08 00:56:51 +03:00
|
|
|
};
|
2018-10-23 01:05:09 +03:00
|
|
|
});
|
2019-10-08 00:56:51 +03:00
|
|
|
cache[key] = JSON.stringify(images);
|
|
|
|
return images;
|
|
|
|
});
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function showBackdrop(type, parentId) {
|
|
|
|
var apiClient = window.ApiClient;
|
2019-10-08 00:56:51 +03:00
|
|
|
|
|
|
|
if (apiClient) {
|
|
|
|
getBackdropItemIds(apiClient, apiClient.getCurrentUserId(), type, parentId).then(function (images) {
|
|
|
|
if (images.length) {
|
|
|
|
backdrop.setBackdrops(images.map(function (i) {
|
|
|
|
i.BackdropImageTags = [i.tag];
|
|
|
|
return i;
|
|
|
|
}));
|
|
|
|
} else {
|
2020-06-16 23:45:03 +03:00
|
|
|
backdrop.clearBackdrop();
|
2019-10-08 00:56:51 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-08 00:56:51 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
pageClassOn('pageshow', 'page', function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2019-10-08 00:56:51 +03:00
|
|
|
|
2020-05-04 12:44:12 +02:00
|
|
|
if (!page.classList.contains('selfBackdropPage')) {
|
|
|
|
if (page.classList.contains('backdropPage')) {
|
2018-10-23 01:05:09 +03:00
|
|
|
if (enabled()) {
|
2020-05-04 12:44:12 +02:00
|
|
|
var type = page.getAttribute('data-backdroptype');
|
|
|
|
var parentId = page.classList.contains('globalBackdropPage') ? '' : libraryMenu.getTopParentId();
|
2019-10-08 00:56:51 +03:00
|
|
|
showBackdrop(type, parentId);
|
|
|
|
} else {
|
2020-05-04 12:44:12 +02:00
|
|
|
page.classList.remove('backdropPage');
|
2020-06-16 23:45:03 +03:00
|
|
|
backdrop.clearBackdrop();
|
2019-10-08 00:56:51 +03:00
|
|
|
}
|
|
|
|
} else {
|
2020-06-16 23:45:03 +03:00
|
|
|
backdrop.clearBackdrop();
|
2019-10-08 00:56:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|