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

308 lines
8.6 KiB
JavaScript
Raw Normal View History

(function ($, document) {
2013-03-26 19:48:33 -07:00
2013-04-18 19:52:22 -07:00
var view = "Poster";
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);
$.when(parentItemPromise, itemsPromise).done(function(r1, r2) {
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 = '';
2013-03-26 19:48:33 -07:00
2014-07-19 21:46:29 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
showLimit: false
});
$('.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';
}
2014-10-20 13:23:40 -07:00
var defaultAction = currentItem.Type == 'PhotoAlbum' ? 'photoslideshow' : null;
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,
2014-03-07 21:20:31 -07:00
shape: "smallBackdrop",
showTitle: true,
centerText: true,
2014-08-14 06:24:30 -07:00
preferBackdrop: true,
2014-10-20 13:23:40 -07:00
context: context,
defaultAction: defaultAction
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,
2014-10-20 13:23:40 -07:00
context: context,
defaultAction: defaultAction
2013-04-18 19:52:22 -07:00
});
}
2013-03-30 07:57:30 -07:00
2014-07-19 21:46:29 -07:00
html += pagingHtml;
2013-03-26 19:48:33 -07:00
$('#items', page).html(html).trigger('create').createCardMenus();
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
}
2014-10-20 13:23:40 -07:00
function startSlideshow(page, index) {
index += (query.StartIndex || 0);
var userId = Dashboard.getCurrentUserId();
var localQuery = $.extend({}, query);
localQuery.StartIndex = 0;
localQuery.Limit = null;
localQuery.MediaTypes = "Photo";
localQuery.Recursive = true;
localQuery.Filters = "IsNotFolder";
ApiClient.getItems(userId, localQuery).done(function(result) {
showSlideshow(page, result.Items, index);
});
}
function showSlideshow(page, items, index) {
var slideshowItems = items.map(function (item) {
var imgUrl = ApiClient.getScaledImageUrl(item.Id, {
tag: item.ImageTags.Primary,
type: 'Primary'
});
return {
title: item.Name,
href: imgUrl
};
});
2014-11-26 12:29:49 -07:00
index = Math.max(index || 0, 0);
2014-10-20 13:23:40 -07:00
$.swipebox(slideshowItems, {
2014-11-26 12:29:49 -07:00
initialIndexOnArray: index,
2014-10-20 13:23:40 -07:00
hideBarsDelay: 30000
});
}
$(document).on('pageinit', "#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);
});
2014-10-20 13:23:40 -07:00
$('.itemsContainer', page).on('photoslideshow', function (e, index) {
startSlideshow(page, index);
});
2013-04-16 09:45:28 -07:00
}).on('pageshow', "#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);