fix pagination to negative pages bug

This commit is contained in:
hawken 2019-01-10 22:51:06 +00:00
parent 58ea56f9d1
commit cba0968358
9 changed files with 129 additions and 45 deletions

View File

@ -37,15 +37,21 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
query.StartIndex += query.Limit, reloadItems(tabContent)
if (isLoading) return;
query.StartIndex += query.Limit;
reloadItems(tabContent)
}
function onPreviousPageClick() {
query.StartIndex -= query.Limit, reloadItems(tabContent)
if (isLoading) return;
query.StartIndex -= query.Limit;
reloadItems(tabContent)
}
window.scrollTo(0, 0);
var html, pagingHtml = libraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
@ -80,16 +86,24 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
scalable: !0,
overlayPlayButton: !0
});
var i, length, elems = tabContent.querySelectorAll(".paging");
for (i = 0, length = elems.length; i < length; i++) elems[i].innerHTML = pagingHtml;
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
var i, length, elems;
for (elems = tabContent.querySelectorAll(".paging"), i = 0, length = elems.length; i < length; i++)
elems[i].innerHTML = pagingHtml;
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++)
elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++)
elems[i].addEventListener("click", onPreviousPageClick);
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
var self = this,
pageSize = 100,
data = {};
data = {},
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
@ -152,4 +166,4 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
reloadItems(tabContent)
}, self.destroy = function() {}
}
});
});

View File

@ -30,10 +30,12 @@ define(["cardBuilder", "imageLoader", "libraryBrowser", "loading", "events", "em
function renderChannels(context, result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(context)
}
function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(context)
}
var query = getQuery();
@ -68,17 +70,20 @@ define(["cardBuilder", "imageLoader", "libraryBrowser", "loading", "events", "em
function reloadItems(context, save) {
loading.show();
isLoading = true;
var query = getQuery(),
apiClient = ApiClient;
query.UserId = apiClient.getCurrentUserId(), apiClient.getLiveTvChannels(query).then(function(result) {
renderChannels(context, result), loading.hide()
renderChannels(context, result);
loading.hide();
isLoading = false;
})
}
var pageData, self = this;
var pageData, self = this, isLoading = false;
tabContent.querySelector(".btnFilter").addEventListener("click", function() {
showFilterMenu(tabContent)
}), self.renderTab = function() {
reloadItems(tabContent)
}
}
});
});

View File

@ -36,13 +36,16 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
ApiClient.getItems(ApiClient.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(tabContent)
}
function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(tabContent)
}
window.scrollTo(0, 0);
@ -106,12 +109,17 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
result.Items.length || (html = '<p style="text-align:center;">' + Globalize.translate("MessageNoCollectionsAvailable") + "</p>");
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
var self = this,
pageSize = 100,
data = {};
data = {},
isLoading = false;
self.getCurrentViewStyle = function() {
return getPageData(tabContent).view
},
@ -160,4 +168,4 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB
reloadItems(tabContent)
}, self.destroy = function() {}
}
});
});

View File

@ -1,4 +1,5 @@
define(["layoutManager", "userSettings", "events", "libraryBrowser", "alphaPicker", "listView", "cardBuilder", "emby-itemscontainer"], function(layoutManager, userSettings, events, libraryBrowser, alphaPicker, listView, cardBuilder) {
define(["loading", "layoutManager", "userSettings", "events", "libraryBrowser", "alphaPicker", "listView", "cardBuilder", "emby-itemscontainer"],
function(loading, layoutManager, userSettings, events, libraryBrowser, alphaPicker, listView, cardBuilder) {
"use strict";
return function(view, params, tabContent, options) {
function onViewStyleChange() {
@ -10,19 +11,26 @@ define(["layoutManager", "userSettings", "events", "libraryBrowser", "alphaPicke
}
function fetchData() {
isLoading = true;
loading.show();
return ApiClient.getItems(ApiClient.getCurrentUserId(), query)
}
function afterRefresh(result) {
function onNextPageClick() {
query.StartIndex += query.Limit, itemsContainer.refreshItems()
if (isLoading) return;
query.StartIndex += query.Limit;
itemsContainer.refreshItems();
}
function onPreviousPageClick() {
query.StartIndex -= query.Limit, itemsContainer.refreshItems()
if (isLoading) return;
query.StartIndex -= query.Limit;
itemsContainer.refreshItems();
}
window.scrollTo(0, 0), updateFilterControls();
var i, length, pagingHtml = libraryBrowser.getQueryPagingHtml({
window.scrollTo(0, 0);
updateFilterControls();
var i, length, elems, pagingHtml = libraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
@ -31,11 +39,15 @@ define(["layoutManager", "userSettings", "events", "libraryBrowser", "alphaPicke
addLayoutButton: !1,
sortButton: !1,
filterButton: !1
}),
elems = tabContent.querySelectorAll(".paging");
for (i = 0, length = elems.length; i < length; i++) elems[i].innerHTML = pagingHtml;
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick)
});
for (elems = tabContent.querySelectorAll(".paging"), i = 0, length = elems.length; i < length; i++)
elems[i].innerHTML = pagingHtml;
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++)
elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++)
elems[i].addEventListener("click", onPreviousPageClick)
isLoading = false;
loading.hide();
}
function getItemsHtml(items) {
@ -163,8 +175,11 @@ define(["layoutManager", "userSettings", "events", "libraryBrowser", "alphaPicke
StartIndex: 0,
Limit: 100,
ParentId: params.topParentId
};
"favorites" === options.mode && (query.IsFavorite = !0), query = userSettings.loadQuerySettings(savedQueryKey, query), self.showFilterMenu = function() {
},
isLoading = false;
if (options.mode === "favorites") query.IsFavorite = true;
query = userSettings.loadQuerySettings(savedQueryKey, query);
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
query: query,
@ -185,4 +200,4 @@ define(["layoutManager", "userSettings", "events", "libraryBrowser", "alphaPicke
itemsContainer = null
}
}
});
});

View File

@ -30,13 +30,16 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
function reloadItems() {
loading.show();
isLoading = true;
var query = getQuery(tabContent);
ApiClient.getItems(ApiClient.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems()
}
function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems()
}
window.scrollTo(0, 0), updateFilterControls(tabContent);
@ -98,7 +101,11 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
result.Items.length || (html = '<p style="text-align:center;">' + Globalize.translate("MessageNoTrailersFound") + "</p>");
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(tabContent), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(tabContent), query);
loading.hide();
isLoading = false;
})
}
@ -108,7 +115,8 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
}
var self = this,
pageSize = 100,
data = {};
data = {},
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
@ -174,4 +182,4 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
reloadItems(), updateFilterControls(tabContent)
}, self.destroy = function() {}
}
});
});

View File

@ -50,13 +50,16 @@ define(["layoutManager", "playbackManager", "loading", "events", "libraryBrowser
function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery();
ApiClient.getItems(ApiClient.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(tabContent)
}
function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(tabContent)
}
window.scrollTo(0, 0), updateFilterControls(page);
@ -100,7 +103,11 @@ define(["layoutManager", "playbackManager", "loading", "events", "libraryBrowser
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(), query);
loading.hide();
isLoading = false;
})
}
@ -109,7 +116,8 @@ define(["layoutManager", "playbackManager", "loading", "events", "libraryBrowser
self.alphaPicker.value(query.NameStartsWithOrGreater)
}
var savedQueryKey, pageData, self = this,
pageSize = 100;
pageSize = 100,
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
@ -179,4 +187,4 @@ define(["layoutManager", "playbackManager", "loading", "events", "libraryBrowser
reloadItems(tabContent), updateFilterControls(tabContent)
}, self.destroy = function() {}
}
});
});

View File

@ -35,13 +35,16 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
("albumartists" == self.mode ? ApiClient.getAlbumArtists(ApiClient.getCurrentUserId(), query) : ApiClient.getArtists(ApiClient.getCurrentUserId(), query)).then(function(result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(tabContent)
}
function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(tabContent)
}
window.scrollTo(0, 0), updateFilterControls(page);
@ -81,7 +84,11 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
@ -90,7 +97,8 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
self.alphaPicker.value(query.NameStartsWithOrGreater)
}
var self = this,
data = {};
data = {},
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
@ -133,4 +141,4 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
reloadItems(tabContent), updateFilterControls(tabContent)
}, self.destroy = function() {}
}
});
});

View File

@ -29,13 +29,16 @@ define(["events", "libraryBrowser", "imageLoader", "listView", "loading", "emby-
function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
ApiClient.getItems(Dashboard.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
if (isLoading) return;
query.StartIndex += query.Limit, reloadItems(tabContent)
}
function onPreviousPageClick() {
if (isLoading) return;
query.StartIndex -= query.Limit, reloadItems(tabContent)
}
window.scrollTo(0, 0);
@ -61,11 +64,16 @@ define(["events", "libraryBrowser", "imageLoader", "listView", "loading", "emby-
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
var self = this,
data = {};
data = {},
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
@ -124,4 +132,4 @@ define(["events", "libraryBrowser", "imageLoader", "listView", "loading", "emby-
reloadItems(tabContent)
}, self.destroy = function() {}
}
});
});

View File

@ -36,14 +36,19 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
function reloadItems(page) {
loading.show();
isLoading = true;
var query = getQuery(page);
ApiClient.getItems(ApiClient.getCurrentUserId(), query).then(function(result) {
function onNextPageClick() {
query.StartIndex += query.Limit, reloadItems(tabContent)
if (isLoading) return;
query.StartIndex += query.Limit;
reloadItems(tabContent);
}
function onPreviousPageClick() {
query.StartIndex -= query.Limit, reloadItems(tabContent)
if (isLoading) return;
query.StartIndex -= query.Limit;
reloadItems(tabContent);
}
window.scrollTo(0, 0), updateFilterControls(page);
var html, pagingHtml = libraryBrowser.getQueryPagingHtml({
@ -103,7 +108,11 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
for (elems = tabContent.querySelectorAll(".btnNextPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onNextPageClick);
for (elems = tabContent.querySelectorAll(".btnPreviousPage"), i = 0, length = elems.length; i < length; i++) elems[i].addEventListener("click", onPreviousPageClick);
var itemsContainer = tabContent.querySelector(".itemsContainer");
itemsContainer.innerHTML = html, imageLoader.lazyChildren(itemsContainer), libraryBrowser.saveQueryValues(getSavedQueryKey(page), query), loading.hide()
itemsContainer.innerHTML = html;
imageLoader.lazyChildren(itemsContainer);
libraryBrowser.saveQueryValues(getSavedQueryKey(page), query);
loading.hide();
isLoading = false;
})
}
@ -113,7 +122,8 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
}
var self = this,
pageSize = 100,
data = {};
data = {},
isLoading = false;
self.showFilterMenu = function() {
require(["components/filterdialog/filterdialog"], function(filterDialogFactory) {
var filterDialog = new filterDialogFactory({
@ -183,4 +193,4 @@ define(["layoutManager", "loading", "events", "libraryBrowser", "imageLoader", "
reloadItems(tabContent), updateFilterControls(tabContent)
}, self.destroy = function() {}
}
});
});