define(['jQuery'], function ($) { // The base query options var data = {}; function getQuery(params) { var key = getSavedQueryKey(); var pageData = data[key]; if (!pageData) { pageData = data[key] = { query: { SortBy: "SortName", SortOrder: "Ascending", IncludeItemTypes: "Movie", Recursive: true, Fields: "DateCreated,ItemCounts", StartIndex: 0, Limit: LibraryBrowser.getDefaultPageSize() } }; pageData.query.ParentId = params.topParentId; LibraryBrowser.loadSavedQueryValues(key, pageData.query); } return pageData.query; } function getSavedQueryKey() { return LibraryBrowser.getSavedQueryKey('studios'); } function reloadItems(context, params) { var query = getQuery(params); Dashboard.showLoadingMsg(); ApiClient.getStudios(Dashboard.getCurrentUserId(), query).then(function (result) { // Scroll back up so they can see the results from the beginning window.scrollTo(0, 0); var html = ''; $('.listTopPaging', context).html(LibraryBrowser.getQueryPagingHtml({ startIndex: query.StartIndex, limit: query.Limit, totalRecordCount: result.TotalRecordCount, showLimit: false })); html += LibraryBrowser.getPosterViewHtml({ items: result.Items, shape: "backdrop", showTitle: false, context: 'movies', preferThumb: true, showItemCounts: true, centerText: true, lazy: true }); var elem = context.querySelector('.itemsContainer'); elem.innerHTML = html; ImageLoader.lazyChildren(elem); $('.btnNextPage', context).on('click', function () { query.StartIndex += query.Limit; reloadItems(context, params); }); $('.btnPreviousPage', context).on('click', function () { query.StartIndex -= query.Limit; reloadItems(context, params); }); LibraryBrowser.saveQueryValues(getSavedQueryKey(), query); Dashboard.hideLoadingMsg(); }); } return function (view, params, tabContent) { var self = this; self.renderTab = function () { reloadItems(tabContent, params); }; }; });