jellyfin-web/dashboard-ui/scripts/itemlistpage.js

279 lines
8.0 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2013-03-26 19:48:33 -07:00
2015-05-17 12:50:37 -07:00
var view = LibraryBrowser.getDefaultItemsView('Poster', 'PosterCard');
2013-05-15 12:40:47 -07:00
// The base query options
var query = {
2013-03-05 23:22:19 -07:00
SortBy: "SortName",
SortOrder: "Ascending",
2014-12-10 23:20:28 -07:00
Fields: "DateCreated,PrimaryImageAspectRatio,MediaSourceCount,SyncInfo",
2014-11-30 12:01:33 -07:00
StartIndex: 0,
ImageTypeLimit: 1,
2014-12-01 05:43:34 -07:00
EnableImageTypes: "Primary,Backdrop,Banner,Thumb"
};
2013-10-18 09:09:47 -07:00
2013-06-02 07:33:51 -07:00
var currentItem;
function reloadItems(page) {
2013-03-30 07:57:30 -07:00
Dashboard.showLoadingMsg();
var userId = Dashboard.getCurrentUserId();
2013-03-05 23:22:19 -07:00
2014-10-20 13:23:40 -07:00
var parentItemPromise = query.ParentId ?
ApiClient.getItem(userId, query.ParentId) :
ApiClient.getRootFolder(userId);
var itemsPromise = ApiClient.getItems(userId, query);
2015-05-09 21:29:04 -07:00
$.when(parentItemPromise, itemsPromise).done(function (r1, r2) {
2014-10-20 13:23:40 -07:00
var item = r1[0];
currentItem = item;
var result = r2[0];
2013-03-30 07:57:30 -07:00
2013-05-17 12:18:54 -07:00
// Scroll back up so they can see the results from the beginning
$(document).scrollTop(0);
var html = '';
2015-01-28 12:30:45 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
2014-07-19 21:46:29 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
showLimit: false
2015-01-28 12:30:45 -07:00
});
$('.listTopPaging', page).html(pagingHtml).trigger('create');
2013-03-05 23:22:19 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
2014-08-14 06:24:30 -07:00
var context = getParameterByName('context');
if (context == 'home') {
context = 'folders';
}
2013-04-18 19:52:22 -07:00
if (view == "Backdrop") {
2014-03-07 21:20:31 -07:00
html = LibraryBrowser.getPosterViewHtml({
2013-04-18 19:52:22 -07:00
items: result.Items,
2015-01-31 13:28:18 -07:00
shape: "backdrop",
2014-03-07 21:20:31 -07:00
showTitle: true,
centerText: true,
2014-08-14 06:24:30 -07:00
preferBackdrop: true,
2015-05-09 21:29:04 -07:00
context: context
2013-04-18 19:52:22 -07:00
});
}
else if (view == "Poster") {
2014-03-07 21:20:31 -07:00
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
2014-06-21 22:52:31 -07:00
shape: "auto",
2014-03-07 21:20:31 -07:00
showTitle: true,
2014-08-14 06:24:30 -07:00
centerText: true,
2015-05-09 21:29:04 -07:00
context: context
2013-04-18 19:52:22 -07:00
});
}
2015-05-12 21:55:19 -07:00
else if (view == "PosterCard") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "auto",
showTitle: true,
context: context,
cardLayout: true,
showYear: true
});
}
2013-03-30 07:57:30 -07:00
2015-01-28 12:30:45 -07:00
var elem = $('#items', page).html(html).lazyChildren();
$(pagingHtml).appendTo(elem).trigger('create');
2013-03-26 19:48:33 -07:00
2013-04-18 22:08:18 -07:00
$('.btnNextPage', page).on('click', function () {
2013-04-15 15:03:05 -07:00
query.StartIndex += query.Limit;
reloadItems(page);
});
2013-04-18 22:08:18 -07:00
$('.btnPreviousPage', page).on('click', function () {
2013-04-15 15:03:05 -07:00
query.StartIndex -= query.Limit;
reloadItems(page);
});
2013-10-18 09:09:47 -07:00
LibraryBrowser.saveQueryValues(getParameterByName('parentId'), query);
2013-04-27 15:52:41 -07:00
2013-04-26 06:50:21 -07:00
var name = item.Name;
2013-04-26 06:50:21 -07:00
if (item.IndexNumber != null) {
name = item.IndexNumber + " - " + name;
}
if (item.ParentIndexNumber != null) {
name = item.ParentIndexNumber + "." + name;
}
$('#itemName', page).html(name);
2013-05-15 12:40:47 -07:00
2013-04-26 06:50:21 -07:00
Dashboard.setPageTitle(name);
2013-05-15 12:40:47 -07:00
2014-04-13 10:27:13 -07:00
$(page).trigger('displayingitem', [{
item: item
}]);
2013-05-10 05:18:07 -07:00
2014-10-20 13:23:40 -07:00
Dashboard.hideLoadingMsg();
});
2013-05-15 12:40:47 -07:00
2013-05-04 21:49:49 -07:00
Dashboard.getCurrentUser().done(function (user) {
2014-12-19 23:06:27 -07:00
if (user.Policy.IsAdministrator && query.ParentId) {
2013-05-04 21:49:49 -07:00
$('#editButtonContainer', page).show();
} else {
$('#editButtonContainer', page).hide();
}
});
}
2013-03-30 07:57:30 -07:00
2013-10-18 09:09:47 -07:00
function updateFilterControls(page) {
// Reset form values using the last used query
$('.radioSortBy', page).each(function () {
this.checked = (query.SortBy || '').toLowerCase() == this.getAttribute('data-sortby').toLowerCase();
}).checkboxradio('refresh');
$('.radioSortOrder', page).each(function () {
this.checked = (query.SortOrder || '').toLowerCase() == this.getAttribute('data-sortorder').toLowerCase();
}).checkboxradio('refresh');
$('.chkStandardFilter', page).each(function () {
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
$('#selectView', page).val(view).selectmenu('refresh');
$('.alphabetPicker', page).alphaValue(query.NameStartsWithOrGreater);
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).val(query.Limit).selectmenu('refresh');
2013-10-18 09:09:47 -07:00
}
2015-05-09 21:29:04 -07:00
function onListItemClick(e) {
2014-10-20 13:23:40 -07:00
2015-05-09 21:29:04 -07:00
var page = $(this).parents('.page');
var info = LibraryBrowser.getListItemInfo(this);
2014-10-20 13:23:40 -07:00
2015-05-09 21:29:04 -07:00
if (info.mediaType == 'Photo') {
Photos.startSlideshow(page, query, info.id);
return false;
}
2014-10-20 13:23:40 -07:00
}
2015-05-15 08:46:20 -07:00
$(document).on('pageinitdepends', "#itemListPage", function () {
2013-03-30 07:57:30 -07:00
2013-04-18 19:52:22 -07:00
var page = this;
$('.radioSortBy', this).on('click', function () {
query.StartIndex = 0;
query.SortBy = this.getAttribute('data-sortby');
reloadItems(page);
});
$('.radioSortOrder', this).on('click', function () {
query.StartIndex = 0;
query.SortOrder = this.getAttribute('data-sortorder');
reloadItems(page);
});
$('.chkStandardFilter', this).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.Filters || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.Filters = filters;
reloadItems(page);
});
$('#selectView', this).on('change', function () {
view = this.value;
reloadItems(page);
2014-01-13 09:25:18 -07:00
LibraryBrowser.saveViewSetting(getParameterByName('parentId'), view);
2013-04-18 19:52:22 -07:00
});
2013-03-30 07:57:30 -07:00
2013-05-04 21:49:49 -07:00
$('#btnEdit', page).on('click', function () {
2013-06-02 07:33:51 -07:00
Dashboard.navigate("edititemmetadata.html?id=" + currentItem.Id);
2013-05-04 21:49:49 -07:00
});
2013-06-04 18:41:59 -07:00
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
query.NameStartsWithOrGreater = character;
query.StartIndex = 0;
reloadItems(page);
}).on('alphaclear', function (e) {
query.NameStartsWithOrGreater = '';
reloadItems(page);
});
2014-07-19 21:46:29 -07:00
$('#selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
reloadItems(page);
});
2015-05-09 21:29:04 -07:00
$(page).on('click', '.mediaItem', onListItemClick);
2014-10-20 13:23:40 -07:00
2015-05-19 12:15:40 -07:00
}).on('pageshowready', "#itemListPage", function () {
2013-03-30 07:57:30 -07:00
2014-01-13 09:25:18 -07:00
var page = this;
2014-04-13 10:27:13 -07:00
2013-05-15 12:40:47 -07:00
query.Limit = LibraryBrowser.getDefaultPageSize();
query.ParentId = getParameterByName('parentId');
2013-04-18 19:52:22 -07:00
query.Filters = "";
query.SortBy = "SortName";
query.SortOrder = "Ascending";
query.StartIndex = 0;
2013-06-04 18:41:59 -07:00
query.NameStartsWithOrGreater = '';
2013-05-15 12:40:47 -07:00
2014-01-13 09:25:18 -07:00
var key = getParameterByName('parentId');
LibraryBrowser.loadSavedQueryValues(key, query);
2013-04-18 19:52:22 -07:00
2014-01-13 09:25:18 -07:00
LibraryBrowser.getSavedViewSetting(key).done(function (val) {
if (val) {
$('#selectView', page).val(val).selectmenu('refresh').trigger('change');
} else {
reloadItems(page);
}
});
2013-06-02 07:33:51 -07:00
2014-01-13 09:25:18 -07:00
updateFilterControls(page);
2013-06-04 18:41:59 -07:00
2013-06-02 07:33:51 -07:00
}).on('pagehide', "#itemListPage", function () {
currentItem = null;
});
2013-03-05 23:22:19 -07:00
})(jQuery, document);