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

299 lines
8.8 KiB
JavaScript
Raw Normal View History

2013-04-17 10:04:57 -07:00
(function ($, document) {
2014-10-20 13:23:40 -07:00
var view = LibraryBrowser.getDefaultItemsView('Poster', 'List');
2013-04-17 10:04:57 -07:00
// The base query options
var query = {
SortBy: "SortName",
SortOrder: "Ascending",
Recursive: true,
2014-10-20 13:23:40 -07:00
Fields: "PrimaryImageAspectRatio,SortName",
2013-04-17 10:04:57 -07:00
StartIndex: 0
};
2014-10-20 13:23:40 -07:00
function getSavedQueryKey() {
return 'trailers' + (query.ParentId || '');
}
2013-04-17 10:04:57 -07:00
function reloadItems(page) {
Dashboard.showLoadingMsg();
2014-10-20 13:23:40 -07:00
query.UserId = Dashboard.getCurrentUserId();
ApiClient.getJSON(ApiClient.getUrl('Trailers', query)).done(function (result) {
2013-04-17 10:04:57 -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);
2014-10-20 13:23:40 -07:00
if (result.Items.length) {
$('.noItemsMessage', page).hide();
}
else {
$('.noItemsMessage', page).show();
}
2013-04-17 10:04:57 -07:00
var html = '';
2014-07-19 21:46:29 -07:00
var pagingHtml = LibraryBrowser.getQueryPagingHtml({
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
viewButton: true,
2014-10-20 13:23:40 -07:00
showLimit: false,
addSelectionButton: true
2014-07-19 21:46:29 -07:00
});
$('.listTopPaging', page).html(pagingHtml).trigger('create');
2013-04-17 10:04:57 -07:00
2013-10-18 09:09:47 -07:00
updateFilterControls(page);
2014-10-20 13:23:40 -07:00
if (view == "Thumb") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "backdrop",
preferThumb: true,
context: 'movies',
selectionPanel: true,
lazy: true,
overlayText: true
});
$('.itemsContainer', page).removeClass('timelineItemsContainer');
}
else if (view == "Banner") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "banner",
preferBanner: true,
context: 'movies',
lazy: true
});
$('.itemsContainer', page).removeClass('timelineItemsContainer');
}
else if (view == "List") {
html = LibraryBrowser.getListViewHtml({
items: result.Items,
context: 'movies',
sortBy: query.SortBy
});
$('.itemsContainer', page).removeClass('timelineItemsContainer');
}
else if (view == "Poster") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
showTitle: false,
centerText: true,
selectionPanel: true,
lazy: true,
overlayText: true
});
$('.itemsContainer', page).removeClass('timelineItemsContainer');
}
else if (view == "Timeline") {
html = LibraryBrowser.getPosterViewHtml({
items: result.Items,
shape: "portrait",
context: 'movies',
showTitle: true,
timeline: true,
centerText: true,
selectionPanel: true,
lazy: true
});
$('.itemsContainer', page).addClass('timelineItemsContainer');
}
2013-04-17 10:04:57 -07:00
2014-07-19 21:46:29 -07:00
html += pagingHtml;
2013-10-18 09:09:47 -07:00
2014-10-20 13:23:40 -07:00
$('.itemsContainer', page).html(html).trigger('create').createCardMenus();
2013-04-17 10:04:57 -07:00
2013-04-18 22:08:18 -07:00
$('.btnNextPage', page).on('click', function () {
2013-04-17 10:04:57 -07:00
query.StartIndex += query.Limit;
reloadItems(page);
});
2013-04-18 22:08:18 -07:00
$('.btnPreviousPage', page).on('click', function () {
2013-04-17 10:04:57 -07:00
query.StartIndex -= query.Limit;
reloadItems(page);
});
2014-10-20 13:23:40 -07:00
LibraryBrowser.saveQueryValues(getSavedQueryKey(), query);
Dashboard.getCurrentUser().done(function (user) {
if (user.Configuration.EnableMediaPlayback && result.Items.length) {
$('.btnTrailerReel', page).show();
} else {
$('.btnTrailerReel', page).hide();
}
});
2013-04-27 15:52:41 -07:00
2013-04-17 10:04:57 -07:00
Dashboard.hideLoadingMsg();
});
}
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');
2014-10-20 13:23:40 -07:00
$('.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 playReel(page) {
$('.popupTrailerReel', page).popup('close');
var reelQuery = {
UserId: Dashboard.getCurrentUserId(),
SortBy: 'Random',
Limit: 50,
Fields: "MediaSources,Chapters"
};
if ($('#chkUnwatchedOnly', page).checked()) {
reelQuery.Filters = "IsPlayed";
}
ApiClient.getJSON(ApiClient.getUrl('Trailers', reelQuery)).done(function (result) {
MediaController.play({
items: result.Items
});
});
}
2013-04-17 10:04:57 -07:00
$(document).on('pageinit', "#movieTrailersPage", function () {
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);
});
$('.alphabetPicker', this).on('alphaselect', function (e, character) {
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = character;
2013-05-17 11:05:49 -07:00
query.StartIndex = 0;
reloadItems(page);
}).on('alphaclear', function (e) {
2013-05-16 20:24:41 -07:00
query.NameStartsWithOrGreater = '';
reloadItems(page);
});
2014-10-20 13:23:40 -07:00
$('.itemsContainer', page).on('needsrefresh', function () {
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
$('.btnTrailerReel', page).on('click', function () {
$('.popupTrailerReel', page).popup('open');
});
2013-04-17 10:04:57 -07:00
}).on('pagebeforeshow', "#movieTrailersPage", function () {
2014-10-20 13:23:40 -07:00
query.ParentId = LibraryMenu.getTopParentId();
var page = this;
2013-05-15 12:40:47 -07:00
var limit = LibraryBrowser.getDefaultPageSize();
// If the default page size has changed, the start index will have to be reset
if (limit != query.Limit) {
query.Limit = limit;
query.StartIndex = 0;
}
2014-10-20 13:23:40 -07:00
var viewkey = getSavedQueryKey();
LibraryBrowser.loadSavedQueryValues(viewkey, query);
LibraryBrowser.getSavedViewSetting(viewkey).done(function (val) {
2014-10-20 13:23:40 -07:00
if (val) {
$('#selectView', page).val(val).selectmenu('refresh').trigger('change');
} else {
reloadItems(page);
}
});
2013-04-17 10:04:57 -07:00
}).on('pageshow', "#movieTrailersPage", function () {
2013-10-18 09:09:47 -07:00
updateFilterControls(this);
2013-04-17 10:04:57 -07:00
});
2014-10-20 13:23:40 -07:00
window.MovieTrailerPage = {
onSubmit: function () {
var page = $(this).parents('.page');
playReel(page);
return false;
}
};
2013-04-17 10:04:57 -07:00
})(jQuery, document);