2013-04-17 10:04:57 -07:00
|
|
|
|
(function ($, document) {
|
|
|
|
|
|
2014-11-02 20:38:43 -07:00
|
|
|
|
var view = LibraryBrowser.getDefaultItemsView('Poster', 'Poster');
|
2014-10-20 13:23:40 -07:00
|
|
|
|
|
2013-04-17 10:04:57 -07:00
|
|
|
|
// The base query options
|
|
|
|
|
var query = {
|
|
|
|
|
|
|
|
|
|
SortBy: "SortName",
|
|
|
|
|
SortOrder: "Ascending",
|
|
|
|
|
Recursive: true,
|
2014-12-10 23:20:28 -07:00
|
|
|
|
Fields: "PrimaryImageAspectRatio,SortName,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-04-17 10:04:57 -07:00
|
|
|
|
};
|
|
|
|
|
|
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 20:41:11 -07:00
|
|
|
|
showLimit: false
|
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-11-09 21:20:11 -07:00
|
|
|
|
html = LibraryBrowser.getPosterViewHtml({
|
|
|
|
|
items: result.Items,
|
|
|
|
|
shape: "portrait",
|
|
|
|
|
context: 'movies-trailers',
|
|
|
|
|
showTitle: false,
|
|
|
|
|
centerText: true,
|
|
|
|
|
lazy: true,
|
|
|
|
|
overlayText: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.itemsContainer', page).removeClass('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) {
|
|
|
|
|
|
2014-12-19 23:06:27 -07:00
|
|
|
|
if (user.Policy.EnableMediaPlayback && result.Items.length) {
|
2014-10-20 13:23:40 -07:00
|
|
|
|
$('.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);
|
|
|
|
|
});
|
|
|
|
|
|
2013-05-16 12:00:42 -07:00
|
|
|
|
$('.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;
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
|
|
|
|
reloadItems(page);
|
|
|
|
|
|
|
|
|
|
}).on('alphaclear', function (e) {
|
|
|
|
|
|
2013-05-16 20:24:41 -07:00
|
|
|
|
query.NameStartsWithOrGreater = '';
|
2013-05-16 12:00:42 -07:00
|
|
|
|
|
|
|
|
|
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) {
|
2013-10-17 13:59:46 -07:00
|
|
|
|
|
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);
|