From cba096835845d298bc66987d0e95b25bb2412df8 Mon Sep 17 00:00:00 2001 From: hawken Date: Thu, 10 Jan 2019 22:51:06 +0000 Subject: [PATCH 1/5] fix pagination to negative pages bug --- src/scripts/episodes.js | 32 +++++++++++++++++-------- src/scripts/livetvchannels.js | 11 ++++++--- src/scripts/moviecollections.js | 14 ++++++++--- src/scripts/movies.js | 41 ++++++++++++++++++++++----------- src/scripts/movietrailers.js | 14 ++++++++--- src/scripts/musicalbums.js | 14 ++++++++--- src/scripts/musicartists.js | 14 ++++++++--- src/scripts/songs.js | 14 ++++++++--- src/scripts/tvshows.js | 20 ++++++++++++---- 9 files changed, 129 insertions(+), 45 deletions(-) diff --git a/src/scripts/episodes.js b/src/scripts/episodes.js index 5885d96c33..1f783631fb 100644 --- a/src/scripts/episodes.js +++ b/src/scripts/episodes.js @@ -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() {} } -}); \ No newline at end of file +}); diff --git a/src/scripts/livetvchannels.js b/src/scripts/livetvchannels.js index beba62ecfb..cc2eda5053 100644 --- a/src/scripts/livetvchannels.js +++ b/src/scripts/livetvchannels.js @@ -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) } } -}); \ No newline at end of file +}); diff --git a/src/scripts/moviecollections.js b/src/scripts/moviecollections.js index bf908fc887..01fdc5d5af 100644 --- a/src/scripts/moviecollections.js +++ b/src/scripts/moviecollections.js @@ -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 = '

' + Globalize.translate("MessageNoCollectionsAvailable") + "

"); 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() {} } -}); \ No newline at end of file +}); diff --git a/src/scripts/movies.js b/src/scripts/movies.js index 36c04a7c6a..689832b299 100644 --- a/src/scripts/movies.js +++ b/src/scripts/movies.js @@ -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 } } -}); \ No newline at end of file +}); diff --git a/src/scripts/movietrailers.js b/src/scripts/movietrailers.js index 9761733db4..268ddba938 100644 --- a/src/scripts/movietrailers.js +++ b/src/scripts/movietrailers.js @@ -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 = '

' + Globalize.translate("MessageNoTrailersFound") + "

"); 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() {} } -}); \ No newline at end of file +}); diff --git a/src/scripts/musicalbums.js b/src/scripts/musicalbums.js index b1b09be4a8..8a562c532d 100644 --- a/src/scripts/musicalbums.js +++ b/src/scripts/musicalbums.js @@ -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() {} } -}); \ No newline at end of file +}); diff --git a/src/scripts/musicartists.js b/src/scripts/musicartists.js index ba4ae9f6b1..b28385169d 100644 --- a/src/scripts/musicartists.js +++ b/src/scripts/musicartists.js @@ -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() {} } -}); \ No newline at end of file +}); diff --git a/src/scripts/songs.js b/src/scripts/songs.js index eeaef6e970..f03abe75ff 100644 --- a/src/scripts/songs.js +++ b/src/scripts/songs.js @@ -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() {} } -}); \ No newline at end of file +}); diff --git a/src/scripts/tvshows.js b/src/scripts/tvshows.js index 76e4a305eb..dc731eeb7d 100644 --- a/src/scripts/tvshows.js +++ b/src/scripts/tvshows.js @@ -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() {} } -}); \ No newline at end of file +}); From 5ef8a2e1cc6131f135c0875653840dc855144601 Mon Sep 17 00:00:00 2001 From: hawken Date: Mon, 14 Jan 2019 22:54:41 +0000 Subject: [PATCH 2/5] missing space in userpasswordpage.js --- src/scripts/userpasswordpage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/userpasswordpage.js b/src/scripts/userpasswordpage.js index b8582e3cf7..478ba95724 100644 --- a/src/scripts/userpasswordpage.js +++ b/src/scripts/userpasswordpage.js @@ -37,7 +37,7 @@ define(["loading", "libraryMenu", "emby-linkbutton"], function(loading, libraryM var userId = params.userId, currentPassword = view.querySelector("#txtCurrentPassword").value, newPassword = view.querySelector("#txtNewPassword").value; - if(view.querySelector("#fldCurrentPassword").classList.contains("hide")) { + if (view.querySelector("#fldCurrentPassword").classList.contains("hide")) { // Firefox does not respect autocomplete=off, so clear it if the field is supposed to be hidden (and blank) // This should only happen when user.HasConfiguredPassword is false, but this information is not passed on currentPassword = ""; From 92aa36de0b13ca20d1d363fc4f1e2bc7fea2bfc4 Mon Sep 17 00:00:00 2001 From: hawken Date: Sat, 12 Jan 2019 19:35:58 +0000 Subject: [PATCH 3/5] fix formatting in moviecollections/movies.js --- src/scripts/moviecollections.js | 33 ++++++++++-------- src/scripts/movies.js | 60 ++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/src/scripts/moviecollections.js b/src/scripts/moviecollections.js index 01fdc5d5af..ee59475e22 100644 --- a/src/scripts/moviecollections.js +++ b/src/scripts/moviecollections.js @@ -4,20 +4,25 @@ define(["loading", "events", "libraryBrowser", "imageLoader", "listView", "cardB function getPageData(context) { var key = getSavedQueryKey(context), pageData = data[key]; - return pageData || (pageData = data[key] = { - query: { - SortBy: "SortName", - SortOrder: "Ascending", - IncludeItemTypes: "BoxSet", - Recursive: !0, - Fields: "PrimaryImageAspectRatio,SortName", - ImageTypeLimit: 1, - EnableImageTypes: "Primary,Backdrop,Banner,Thumb", - StartIndex: 0, - Limit: pageSize - }, - view: libraryBrowser.getSavedView(key) || "Poster" - }, pageData.query.ParentId = params.topParentId, libraryBrowser.loadSavedQueryValues(key, pageData.query)), pageData + if (!pageData) { + pageData = data[key] = { + query: { + SortBy: "SortName", + SortOrder: "Ascending", + IncludeItemTypes: "BoxSet", + Recursive: true, + Fields: "PrimaryImageAspectRatio,SortName", + ImageTypeLimit: 1, + EnableImageTypes: "Primary,Backdrop,Banner,Thumb", + StartIndex: 0, + Limit: pageSize + }, + view: libraryBrowser.getSavedView(key) || "Poster" + }; + pageData.query.ParentId = params.topParentId; + libraryBrowser.loadSavedQueryValues(key, pageData.query); + } + return pageData; } function getQuery(context) { diff --git a/src/scripts/movies.js b/src/scripts/movies.js index 689832b299..a25e54b492 100644 --- a/src/scripts/movies.js +++ b/src/scripts/movies.js @@ -3,7 +3,14 @@ define(["loading", "layoutManager", "userSettings", "events", "libraryBrowser", "use strict"; return function(view, params, tabContent, options) { function onViewStyleChange() { - "List" == self.getCurrentViewStyle() ? (itemsContainer.classList.add("vertical-list"), itemsContainer.classList.remove("vertical-wrap")) : (itemsContainer.classList.remove("vertical-list"), itemsContainer.classList.add("vertical-wrap")), itemsContainer.innerHTML = "" + if (self.getCurrentViewStyle() == "List") { + itemsContainer.classList.add("vertical-list"); + itemsContainer.classList.remove("vertical-wrap"); + } else { + itemsContainer.classList.remove("vertical-list"); + itemsContainer.classList.add("vertical-wrap"); + } + itemsContainer.innerHTML = ""; } function updateFilterControls() { @@ -101,15 +108,27 @@ define(["loading", "layoutManager", "userSettings", "events", "libraryBrowser", } function initPage(tabContent) { - itemsContainer.fetchData = fetchData, itemsContainer.getItemsHtml = getItemsHtml, itemsContainer.afterRefresh = afterRefresh; + itemsContainer.fetchData = fetchData; + itemsContainer.getItemsHtml = getItemsHtml; + itemsContainer.afterRefresh = afterRefresh; var alphaPickerElement = tabContent.querySelector(".alphaPicker"); - alphaPickerElement && (alphaPickerElement.addEventListener("alphavaluechanged", function(e) { - var newValue = e.detail.value; - query.NameStartsWithOrGreater = newValue, query.StartIndex = 0, itemsContainer.refreshItems() - }), self.alphaPicker = new alphaPicker({ - element: alphaPickerElement, - valueChangeEvent: "click" - }), (layoutManager.desktop || layoutManager.mobile) && (alphaPickerElement.classList.add("alphabetPicker-right"), itemsContainer.classList.remove("padded-left-withalphapicker"), itemsContainer.classList.add("padded-right-withalphapicker"))); + if (alphaPickerElement) { + alphaPickerElement.addEventListener("alphavaluechanged", function(e) { + var newValue = e.detail.value; + query.NameStartsWithOrGreater = newValue; + query.StartIndex = 0; + itemsContainer.refreshItems(); + }); + self.alphaPicker = new alphaPicker({ + element: alphaPickerElement, + valueChangeEvent: "click" + }); + if (layoutManager.desktop || layoutManager.mobile) { + alphaPickerElement.classList.add("alphabetPicker-right"); + itemsContainer.classList.remove("padded-left-withalphapicker"); + itemsContainer.classList.add("padded-right-withalphapicker"); + } + } var btnFilter = tabContent.querySelector(".btnFilter"); btnFilter && btnFilter.addEventListener("click", function() { self.showFilterMenu() @@ -157,7 +176,10 @@ define(["loading", "layoutManager", "userSettings", "events", "libraryBrowser", libraryBrowser.showLayoutMenu(e.target, self.getCurrentViewStyle(), "Banner,List,Poster,PosterCard,Thumb,ThumbCard".split(",")) }), btnSelectView.addEventListener("layoutchange", function(e) { var viewStyle = e.detail.viewStyle; - userSettings.set(savedViewKey, viewStyle), query.StartIndex = 0, onViewStyleChange(), itemsContainer.refreshItems() + userSettings.set(savedViewKey, viewStyle); + query.StartIndex = 0; + onViewStyleChange(); + itemsContainer.refreshItems(); }) } var self = this, @@ -190,13 +212,19 @@ define(["loading", "layoutManager", "userSettings", "events", "libraryBrowser", query.StartIndex = 0, itemsContainer.refreshItems() }), filterDialog.show() }) - }, self.getCurrentViewStyle = function() { + }; + self.getCurrentViewStyle = function() { return userSettings.get(savedViewKey) || "Poster" - }, self.initTab = function() { - initPage(tabContent), onViewStyleChange() - }, self.renderTab = function() { - itemsContainer.refreshItems(), updateFilterControls() - }, self.destroy = function() { + }; + self.initTab = function() { + initPage(tabContent); + onViewStyleChange(); + }; + self.renderTab = function() { + itemsContainer.refreshItems(); + updateFilterControls(); + }; + self.destroy = function() { itemsContainer = null } } From dfcad4992b02c4e14de6afd6c320c9e052c268d7 Mon Sep 17 00:00:00 2001 From: hawken Date: Sat, 12 Jan 2019 20:59:37 +0000 Subject: [PATCH 4/5] Add loading and disable submit event while adding library folder --- .../medialibrarycreator.js | 65 ++++++++++++------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/src/components/medialibrarycreator/medialibrarycreator.js b/src/components/medialibrarycreator/medialibrarycreator.js index e7f7abfdb2..d0d1fdf2fa 100644 --- a/src/components/medialibrarycreator/medialibrarycreator.js +++ b/src/components/medialibrarycreator/medialibrarycreator.js @@ -2,25 +2,43 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed "use strict"; function onSubmit(e) { - if (e.preventDefault(), e.stopPropagation(), 0 == pathInfos.length) return require(["alert"], function(alert) { - alert({ - text: Globalize.translate("PleaseAddAtLeastOneFolder"), - type: "error" - }) - }), !1; - var form = this, - dlg = $(form).parents(".dialog")[0], - name = $("#txtValue", form).val(), - type = $("#selectCollectionType", form).val(); - "mixed" == type && (type = null); - var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions")); - return libraryOptions.PathInfos = pathInfos, ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() { - hasChanges = !0, dialogHelper.close(dlg) - }, function() { - require(["toast"], function(toast) { - toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")) - }) - }), !1 + e.preventDefault(); + e.stopPropagation(); + + if (isCreating) return false; + + if (pathInfos.length == 0) { + require(["alert"], function(alert) { + alert({ + text: Globalize.translate("PleaseAddAtLeastOneFolder"), + type: "error" + }) + }); + } else { + isCreating = true; + loading.show(); + + var form = this, + dlg = $(form).parents(".dialog")[0], + name = $("#txtValue", form).val(), + type = $("#selectCollectionType", form).val(); + if (type == "mixed") type = null; + var libraryOptions = libraryoptionseditor.getLibraryOptions(dlg.querySelector(".libraryOptions")); + libraryOptions.PathInfos = pathInfos; + ApiClient.addVirtualFolder(name, type, currentOptions.refresh, libraryOptions).then(function() { + hasChanges = true; + isCreating = false; + loading.hide(); + dialogHelper.close(dlg); + }, function() { + require(["toast"], function(toast) { + toast(Globalize.translate("ErrorAddingMediaPathToVirtualFolder")) + }) + isCreating = false; + loading.hide(); + }); + } + return false; } function getCollectionTypeOptionsHtml(collectionTypeOptions) { @@ -101,7 +119,8 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed } function onDialogClosed() { - loading.hide(), currentResolve(hasChanges) + loading.hide(); + currentResolve(hasChanges); } function initLibraryOptions(dlg) { @@ -119,7 +138,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed var template = this.response, dlg = dialogHelper.createDialog({ size: "medium-tall", - modal: !1, + modal: false, removeOnClose: !0, scrollY: !1 }); @@ -130,6 +149,6 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed }) } } - var currentResolve, hasChanges, currentOptions, pathInfos = []; + var currentResolve, hasChanges, currentOptions, pathInfos = [], isCreating = false; return editor -}); \ No newline at end of file +}); From e9fdcd280791637b07531f063a9ae13509edb24e Mon Sep 17 00:00:00 2001 From: hawken Date: Sat, 12 Jan 2019 22:01:46 +0000 Subject: [PATCH 5/5] prettify a bit and add comment in medialibrarycreator.js --- .../medialibrarycreator.js | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/components/medialibrarycreator/medialibrarycreator.js b/src/components/medialibrarycreator/medialibrarycreator.js index d0d1fdf2fa..5fd94022f9 100644 --- a/src/components/medialibrarycreator/medialibrarycreator.js +++ b/src/components/medialibrarycreator/medialibrarycreator.js @@ -43,7 +43,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed function getCollectionTypeOptionsHtml(collectionTypeOptions) { return collectionTypeOptions.filter(function(i) { - return !1 !== i.isSelectable + return i.isSelectable }).map(function(i) { return '" }).join("") @@ -53,9 +53,15 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed $("#selectCollectionType", page).html(getCollectionTypeOptionsHtml(collectionTypeOptions)).val("").on("change", function() { var value = this.value, dlg = $(this).parents(".dialog")[0]; - if (libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"), "mixed" == value ? "" : value), value ? dlg.querySelector(".libraryOptions").classList.remove("hide") : dlg.querySelector(".libraryOptions").classList.add("hide"), "mixed" != value) { + libraryoptionseditor.setContentType(dlg.querySelector(".libraryOptions"), value == "mixed" ? "" : value); + if (value) + dlg.querySelector(".libraryOptions").classList.remove("hide"); + else + dlg.querySelector(".libraryOptions").classList.add("hide"); + + if (value != "mixed") { var index = this.selectedIndex; - if (-1 != index) { + if (index != -1) { var name = this.options[index].innerHTML.replace("*", "").replace("&", "&"); $("#txtValue", dlg).val(name); var folderOption = collectionTypeOptions.filter(function(i) { @@ -77,7 +83,7 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed require(["directorybrowser"], function(directoryBrowser) { var picker = new directoryBrowser; picker.show({ - enableNetworkSharePath: !0, + enableNetworkSharePath: true, callback: function(path, networkSharePath) { path && addMediaLocation(page, path, networkSharePath), picker.close() } @@ -119,6 +125,8 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed } function onDialogClosed() { + // I can't see any corresponding call to loading.show, + // so I think this is not supposed to be here. loading.hide(); currentResolve(hasChanges); } @@ -132,20 +140,33 @@ define(["loading", "dialogHelper", "dom", "jQuery", "components/libraryoptionsed function editor() { this.show = function(options) { return new Promise(function(resolve, reject) { - currentOptions = options, currentResolve = resolve, hasChanges = !1; + currentOptions = options, currentResolve = resolve, hasChanges = false; var xhr = new XMLHttpRequest; - xhr.open("GET", "components/medialibrarycreator/medialibrarycreator.template.html", !0), xhr.onload = function(e) { + xhr.open("GET", "components/medialibrarycreator/medialibrarycreator.template.html", true); + xhr.onload = function(e) { var template = this.response, dlg = dialogHelper.createDialog({ size: "medium-tall", modal: false, - removeOnClose: !0, - scrollY: !1 + removeOnClose: true, + scrollY: false }); - dlg.classList.add("ui-body-a"), dlg.classList.add("background-theme-a"), dlg.classList.add("dlg-librarycreator"), dlg.classList.add("formDialog"), dlg.innerHTML = Globalize.translateDocument(template), initEditor(dlg, options.collectionTypeOptions), dlg.addEventListener("close", onDialogClosed), dialogHelper.open(dlg), dlg.querySelector(".btnCancel").addEventListener("click", function() { + dlg.classList.add("ui-body-a"); + dlg.classList.add("background-theme-a"); + dlg.classList.add("dlg-librarycreator"); + dlg.classList.add("formDialog"); + dlg.innerHTML = Globalize.translateDocument(template); + initEditor(dlg, options.collectionTypeOptions); + dlg.addEventListener("close", onDialogClosed); + dialogHelper.open(dlg); + dlg.querySelector(".btnCancel").addEventListener("click", function() { dialogHelper.close(dlg) - }), pathInfos = [], renderPaths(dlg), initLibraryOptions(dlg) - }, xhr.send() + }); + pathInfos = []; + renderPaths(dlg); + initLibraryOptions(dlg); + }; + xhr.send(); }) } }