2019-10-08 00:56:51 +03:00
|
|
|
define(["backdrop", "userSettings", "libraryMenu"], function (backdrop, userSettings, libraryMenu) {
|
2018-10-23 01:05:09 +03:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
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) {
|
2019-10-08 00:56:51 +03:00
|
|
|
var key = "backdrops2_" + userId + (types || "") + (parentId || "");
|
|
|
|
var data = cache[key];
|
|
|
|
|
|
|
|
if (data) {
|
2020-02-16 03:44:43 +01: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 = {
|
|
|
|
SortBy: "IsFavoriteOrLiked,Random",
|
|
|
|
Limit: 20,
|
2019-10-08 00:56:51 +03:00
|
|
|
Recursive: true,
|
2018-10-23 01:05:09 +03:00
|
|
|
IncludeItemTypes: types,
|
|
|
|
ImageTypes: "Backdrop",
|
|
|
|
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 {
|
|
|
|
backdrop.clear();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-10-23 01:05:09 +03:00
|
|
|
}
|
2019-10-08 00:56:51 +03:00
|
|
|
|
2018-10-23 01:05:09 +03:00
|
|
|
var cache = {};
|
2019-10-08 00:56:51 +03:00
|
|
|
pageClassOn("pageshow", "page", function () {
|
2018-10-23 01:05:09 +03:00
|
|
|
var page = this;
|
2019-10-08 00:56:51 +03:00
|
|
|
|
|
|
|
if (!page.classList.contains("selfBackdropPage")) {
|
|
|
|
if (page.classList.contains("backdropPage")) {
|
2018-10-23 01:05:09 +03:00
|
|
|
if (enabled()) {
|
2019-10-08 00:56:51 +03:00
|
|
|
var type = page.getAttribute("data-backdroptype");
|
|
|
|
var parentId = page.classList.contains("globalBackdropPage") ? "" : libraryMenu.getTopParentId();
|
|
|
|
showBackdrop(type, parentId);
|
|
|
|
} else {
|
|
|
|
page.classList.remove("backdropPage");
|
|
|
|
backdrop.clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
backdrop.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|