(function ($, document, window) {
var defaultSortBy = "SortName";
// The base query options
var query = {
SortBy: defaultSortBy,
SortOrder: "Ascending",
Recursive: true,
Fields: "MediaSources,DateCreated,Settings,Studios",
StartIndex: 0,
IncludeItemTypes: "Movie",
IsMissing: false,
IsVirtualUnaired: false,
Limit: 200,
CollapseBoxSetItems: false
};
function getHeaderCells(reportType) {
switch (reportType) {
case 'Season':
{
return [
{},
{ name: Globalize.translate('HeaderSeries'), sortField: 'SeriesSortName,SortName', type: 'Series' },
{ name: Globalize.translate('HeaderSeason'), sortField: 'SortName', type: 'Season' },
{ name: Globalize.translate('HeaderSeasonNumber'), type: 'Season Number', sortField: 'IndexNumber' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' }
];
}
case 'Series':
{
return [
{},
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderNetwork'), sortField: 'Studio,SortName', type: 'Network' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderYear'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Year' },
{ name: Globalize.translate('HeaderParentalRating'), sortField: 'OfficialRating,SortName', type: 'Parental Rating' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' },
{ name: Globalize.translate('HeaderRuntime'), sortField: 'Runtime,SortName', type: 'Runtime' },
{ name: Globalize.translate('HeaderTrailers'), type: 'Trailers' },
{ name: Globalize.translate('HeaderSpecials'), type: 'Specials' }
];
}
case 'Game':
{
return [
{},
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderGameSystem'), sortField: 'GameSystem,SortName', type: 'Game System' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,GameSystem,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderParentalRating'), sortField: 'OfficialRating,SortName', type: 'Parental Rating' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' },
{ name: Globalize.translate('HeaderPlayers'), type: 'Players', sortField: 'Players,GameSystem,SortName' },
{ name: Globalize.translate('HeaderTrailers'), type: 'Trailers' }
];
}
case 'Audio':
{
return [
{},
{ name: Globalize.translate('HeaderAlbumArtist'), sortField: 'AlbumArtist,Album,SortName', type: 'Album Artist' },
{ name: Globalize.translate('HeaderAlbum'), type: 'Album', sortField: 'Album,SortName' },
{ name: Globalize.translate('HeaderDisc'), type: 'Disc' },
{ name: Globalize.translate('HeaderTrack'), type: 'Track' },
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderRuntime'), sortField: 'Runtime,SortName', type: 'Runtime' },
{ name: Globalize.translate('HeaderAudio'), type: 'Audio' },
{ name: Globalize.translate('HeaderEmbeddedImage'), type: 'Embedded Image' }
];
}
case 'Episode':
{
return [
{},
{ name: Globalize.translate('HeaderSeries'), sortField: 'SeriesSortName,SortName', type: 'Series' },
{ name: Globalize.translate('HeaderSeason') },
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' },
{ name: Globalize.translate('HeaderRuntime'), sortField: 'Runtime,SortName', type: 'Runtime' },
{ name: Globalize.translate('HeaderVideo'), type: 'Video' },
{ name: Globalize.translate('HeaderResolution'), type: 'Resolution' },
{ name: Globalize.translate('HeaderAudio'), type: 'Audio' },
{ name: Globalize.translate('HeaderSubtitles'), type: 'Subtitles' }
];
}
case 'BoxSet':
{
return [
{},
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderParentalRating'), sortField: 'OfficialRating,SortName', type: 'Parental Rating' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' },
{ name: Globalize.translate('HeaderTrailers'), type: 'Trailers' }
];
}
case 'Book':
{
return [
{},
{ name: Globalize.translate('HeaderSeries'), type: 'Series' },
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderParentalRating'), sortField: 'OfficialRating,SortName', type: 'Parental Rating' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' }
];
}
case 'MusicArtist':
{
return [
{},
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' }
];
}
case 'MusicAlbum':
{
return [
{},
{ name: Globalize.translate('HeaderAlbumArtist'), sortField: 'AlbumArtist,SortName', type: 'Album Artist' },
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderParentalRating'), sortField: 'OfficialRating,SortName', type: 'Parental Rating' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' },
{ name: Globalize.translate('HeaderRuntime'), sortField: 'Runtime,SortName', type: 'Runtime' }
];
}
default:
{
return [
{},
{ name: Globalize.translate('HeaderName'), sortField: 'SortName', type: 'Name' },
{ name: Globalize.translate('HeaderDateAdded'), sortField: 'DateCreated,SortName', type: 'Date Added' },
{ name: Globalize.translate('HeaderReleaseDate'), sortField: 'ProductionYear,PremiereDate,SortName', type: 'Release Date' },
{ name: Globalize.translate('HeaderParentalRating'), sortField: 'OfficialRating,SortName', type: 'Parental Rating' },
{ name: Globalize.translate('HeaderCommunityRating'), sortField: 'CommunityRating,SortName', type: 'Community Rating' },
{ name: Globalize.translate('HeaderRuntime'), sortField: 'Runtime,SortName', type: 'Runtime' },
{ name: Globalize.translate('HeaderVideo'), type: 'Video' },
{ name: Globalize.translate('HeaderResolution'), type: 'Resolution' },
{ name: Globalize.translate('HeaderAudio'), type: 'Audio' },
{ name: Globalize.translate('HeaderSubtitles'), type: 'Subtitles' },
{ name: Globalize.translate('HeaderTrailers'), type: 'Trailers' },
{ name: Globalize.translate('HeaderSpecials'), type: 'Specials' }
];
}
}
}
function getDefaultSortOrder(reportType) {
switch (reportType) {
case 'Season':
{
return "SeriesSortName,SortName";
}
case 'Series':
{
return "SortName";
}
case 'Game':
{
return "GameSystem,SortName";
}
case 'Audio':
{
return "AlbumArtist,Album,SortName";
}
case 'Episode':
{
return "SeriesSortName,SortName";
}
case 'BoxSet':
{
return "SortName";
}
case 'Book':
{
return "SortName";
}
case 'MusicArtist':
{
return "SortName";
}
case 'MusicAlbum':
{
return "AlbumArtist,SortName";
}
default:
{
return "SortName";
}
}
}
function getItemCellsHtml(item, headercells) {
var primaryVersion = (item.MediaSources || [])[0] || {};
var mediaStreams = primaryVersion.MediaStreams || [];
var videoStream = mediaStreams.filter(function (s) {
return s.Type == 'Video';
})[0];
var audioStream = mediaStreams.filter(function (s) {
return s.Type == 'Audio';
})[0];
return headercells.map(function (cell) {
var html = '';
html += '
';
switch (cell.type || cell.name) {
case 'Album Artist':
{
html += item.AlbumArtist || ' ';
break;
}
case 'Album':
{
html += item.Album || ' ';
break;
}
case 'Series':
{
html += item.SeriesName || ' ';
break;
}
case 'Game System':
{
html += item.GameSystem || ' ';
break;
}
case 'Network':
{
html += item.Studios.length ? item.Studios[0].Name : ' ';
break;
}
case 'Disc':
{
html += item.ParentIndexNumber == null ? '' : item.ParentIndexNumber;
break;
}
case 'Season Number':
case 'Track':
{
html += item.IndexNumber == null ? '' : item.IndexNumber;
break;
}
case 'Players':
{
html += item.Players || ' ';
break;
}
case 'Audio':
{
if (audioStream) {
var name = (audioStream.Codec || '').toUpperCase();
html += name == 'DCA' ? (audioStream.Profile || '').toUpperCase() : name;
}
break;
}
case 'Video':
{
if (videoStream) {
html += (videoStream.Codec || '').toUpperCase();
}
break;
}
case 'Resolution':
{
if (videoStream && videoStream.Width) {
html += videoStream.Width + "*" + (videoStream.Height || "-");
}
break;
}
case 'Embedded Image':
{
if (videoStream) {
html += '';
}
break;
}
case 'Subtitles':
{
var hasSubtitles = mediaStreams.filter(function (s) {
return s.Type == 'Subtitle';
}).length;
if (hasSubtitles) {
html += '';
}
break;
}
case 'Runtime':
{
if (item.RunTimeTicks) {
html += Dashboard.getDisplayTime(item.RunTimeTicks);
} else {
html += ' ';
}
break;
}
case 'Trailers':
{
if (item.LocalTrailerCount) {
html += '';
}
break;
}
case 'Specials':
{
if (item.SpecialFeatureCount) {
html += '';
}
break;
}
case 'Season':
{
if (item.Type == "Episode") {
html += item.ParentIndexNumber == null ? '' : ('Season ' + item.ParentIndexNumber);
} else {
html += '' + LibraryBrowser.getPosterViewDisplayName(item, false, false) + '';
}
break;
}
case 'Name':
{
html += '' + LibraryBrowser.getPosterViewDisplayName(item, false, false) + '';
break;
}
case 'Community Rating':
{
html += item.CommunityRating || ' ';
break;
}
case 'Parental Rating':
{
html += item.OfficialRating || ' ';
break;
}
case 'Year':
case 'Release Date':
{
if (item.PremiereDate && item.Type != "Series") {
try {
var date = parseISO8601Date(item.PremiereDate, { toLocal: true });
html += date.toLocaleDateString();
}
catch (e) {
html += ' ';
}
}
else if (item.ProductionYear) {
html += item.ProductionYear;
if (item.Status == "Continuing") {
html += "-Present";
}
else if (item.EndDate) {
try {
var endYear = parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear();
if (endYear != item.ProductionYear) {
html += "-" + parseISO8601Date(item.EndDate, { toLocal: true }).getFullYear();
}
}
catch (e) {
console.log("Error parsing date: " + item.EndDate);
}
}
} else {
html += ' ';
}
break;
}
case 'Date Added':
{
if (item.DateCreated) {
try {
html += parseISO8601Date(item.DateCreated, { toLocal: true }).toLocaleDateString();
}
catch (e) {
html += ' ';
}
}
break;
}
default:
{
if (item.LockData) {
html += '';
}
if (item.IsUnidentified) {
html += '';
}
if (!item.LocalTrailerCount && item.Type == "Movie") {
html += '';
}
if (!item.ImageTags || !item.ImageTags.Primary) {
html += '';
}
if (!item.BackdropImageTags || !item.BackdropImageTags.length) {
if (item.Type !== "Episode" && item.Type !== "Season" && item.MediaType !== "Audio" && item.Type !== "TvChannel" && item.Type !== "MusicAlbum") {
html += '';
}
}
if (!item.ImageTags || !item.ImageTags.Logo) {
if (item.Type == "Movie" || item.Type == "Trailer" || item.Type == "Series" || item.Type == "MusicArtist" || item.Type == "BoxSet") {
html += '';
}
}
break;
}
}
html += ' | ';
return html;
}).join('');
}
function getReportHtml(items, reportType, currentSortField, currentSortDirection) {
var html = '';
html += '';
html += '';
html += '';
var cells = getHeaderCells(reportType);
html += cells.map(function (c) {
var cellHtml = '';
if (c.sortField) {
cellHtml += '';
}
cellHtml += (c.name || ' ');
if (c.sortField) {
cellHtml += '';
if (c.sortField == currentSortField) {
if (currentSortDirection == "Descending") {
cellHtml += '↓';
} else {
cellHtml += '↑';
}
}
}
cellHtml += ' | ';
return cellHtml;
}).join('');
html += '
';
html += '';
html += '';
for (var i = 0, length = items.length; i < length; i++) {
var item = items[i];
html += '';
html += getItemCellsHtml(item, cells);
html += '
';
}
html += '';
html += '
';
return html;
}
function renderItems(page, result, reportType) {
// Scroll back up so they can see the results from the beginning
$(document).scrollTop(0);
$('.listTopPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false)).trigger('create');
updateFilterControls(page);
$('.listBottomPaging', page).html(LibraryBrowser.getPagingHtml(query, result.TotalRecordCount, false, [], false)).trigger('create');
$('.reportContainer', page).html(getReportHtml(result.Items, reportType, query.SortBy, query.SortOrder)).trigger('create');
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
$('.lnkColumnSort', page).on('click', function () {
var order = this.getAttribute('data-sortfield');
if (query.SortBy == order) {
if (query.SortOrder == "Descending") {
query.SortOrder = "Ascending";
query.SortBy = defaultSortBy;
} else {
query.SortOrder = "Descending";
query.SortBy = order;
}
} else {
query.SortOrder = "Ascending";
query.SortBy = order;
}
query.StartIndex = 0;
reloadItems(page);
});
}
function reloadItems(page) {
var url = ApiClient.getUrl("Items", query);
var reportType = $('#selectView', page).val();
ApiClient.getJSON(url).done(function (result) {
renderItems(page, result, reportType);
});
}
function updateFilterControls(page) {
$('#selectView').val(query.IncludeItemTypes).selectmenu('refresh');
$('.chkVideoTypeFilter', page).each(function () {
var filters = "," + (query.VideoTypes || "");
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
}).checkboxradio('refresh');
$('#chk3D', page).checked(query.Is3D == true).checkboxradio('refresh');
$('#chkHD', page).checked(query.IsHD == true).checkboxradio('refresh');
$('#chkSD', page).checked(query.IsHD == false).checkboxradio('refresh');
$('#chkSubtitle', page).checked(query.HasSubtitles == true).checkboxradio('refresh');
$('#chkNoSubtitle', page).checked(query.HasSubtitles === false).checkboxradio('refresh');
$('#chkTrailer', page).checked(query.HasTrailer == true).checkboxradio('refresh');
$('#chkNoTrailer', page).checked(query.HasTrailer == false).checkboxradio('refresh');
$('#chkSpecialFeature', page).checked(query.HasSpecialFeature == true).checkboxradio('refresh');
$('#chkThemeSong', page).checked(query.HasThemeSong == true).checkboxradio('refresh');
$('#chkNoThemeSong', page).checked(query.HasThemeSong == false).checkboxradio('refresh');
$('#chkThemeVideo', page).checked(query.HasThemeVideo == true).checkboxradio('refresh');
$('#chkNoThemeVideo', page).checked(query.HasThemeVideo == false).checkboxradio('refresh');
$('#chkIsPlaceHolder', page).checked(query.IsPlaceHolder == true).checkboxradio('refresh');
$('#chkMissingRating', page).checked(query.HasOfficialRating == false).checkboxradio('refresh');
$('#chkMissingOverview', page).checked(query.HasOverview == false).checkboxradio('refresh');
$('#chkYearMismatch', page).checked(query.IsYearMismatched == true).checkboxradio('refresh');
$('#chkIsUnidentified', page).checked(query.IsUnidentified == true).checkboxradio('refresh');
$('#chkIsLocked', page).checked(query.IsLocked == true).checkboxradio('refresh');
$('#chkSpecialEpisode', page).checked(query.ParentIndexNumber == 0).checkboxradio('refresh');
$('#chkMissingEpisode', page).checked(query.IsMissing == true).checkboxradio('refresh');
$('#chkFutureEpisode', page).checked(query.IsUnaired == true).checkboxradio('refresh');
}
$(document).on('pageinit', "#libraryReportPage", function () {
var page = this;
$('#radioBasicFilters', page).on('change', function () {
if (this.checked) {
$('.basicFilters', page).show();
$('.advancedFilters', page).hide();
} else {
$('.basicFilters', page).hide();
}
});
$('#radioAdvancedFilters', page).on('change', function () {
if (this.checked) {
$('.advancedFilters', page).show();
$('.basicFilters', page).hide();
} else {
$('.advancedFilters', page).hide();
}
});
$('#selectView', page).on('change', function () {
query.StartIndex = 0;
query.IncludeItemTypes = this.value;
query.SortBy = getDefaultSortOrder(this.value);
query.SortOrder = "Ascending";
reloadItems(page);
});
$('.chkVideoTypeFilter', page).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.VideoTypes || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
query.VideoTypes = filters;
reloadItems(page);
});
$('#chk3D', page).on('change', function () {
query.StartIndex = 0;
query.Is3D = this.checked ? true : null;
reloadItems(page);
});
$('#chkHD', page).on('change', function () {
query.StartIndex = 0;
query.IsHD = this.checked ? true : null;
reloadItems(page);
});
$('#chkSD', page).on('change', function () {
query.StartIndex = 0;
query.IsHD = this.checked ? false : null;
reloadItems(page);
});
$('#chkSubtitle', page).on('change', function () {
query.StartIndex = 0;
query.HasSubtitles = this.checked ? true : null;
$('#chkNoSubtitle', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkNoSubtitle', page).on('change', function () {
query.StartIndex = 0;
query.HasSubtitles = this.checked ? false : null;
$('#chkSubtitle', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkTrailer', page).on('change', function () {
query.StartIndex = 0;
query.HasTrailer = this.checked ? true : null;
$('#chkNoTrailer', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkNoTrailer', page).on('change', function () {
query.StartIndex = 0;
query.HasTrailer = this.checked ? false : null;
$('#chkTrailer', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkSpecialFeature', page).on('change', function () {
query.StartIndex = 0;
query.HasSpecialFeature = this.checked ? true : null;
reloadItems(page);
});
$('#chkIsPlaceHolder', page).on('change', function () {
query.StartIndex = 0;
query.IsPlaceHolder = this.checked ? true : null;
reloadItems(page);
});
$('#chkThemeSong', page).on('change', function () {
query.StartIndex = 0;
query.HasThemeSong = this.checked ? true : null;
$('#chkNoThemeSong', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkNoThemeSong', page).on('change', function () {
query.StartIndex = 0;
query.HasThemeSong = this.checked ? false : null;
$('#chkThemeSong', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkThemeVideo', page).on('change', function () {
query.StartIndex = 0;
query.HasThemeVideo = this.checked ? true : null;
$('#chkNoThemeVideo', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkNoThemeVideo', page).on('change', function () {
query.StartIndex = 0;
query.HasThemeVideo = this.checked ? false : null;
$('#chkThemeVideo', page).checked(false).checkboxradio('refresh');
reloadItems(page);
});
$('#chkMissingOverview', page).on('change', function () {
query.StartIndex = 0;
query.HasOverview = this.checked ? false : null;
reloadItems(page);
});
$('#chkMissingRating', page).on('change', function () {
query.StartIndex = 0;
query.HasOfficialRating = this.checked ? false : null;
reloadItems(page);
});
$('#chkYearMismatch', page).on('change', function () {
query.StartIndex = 0;
query.IsYearMismatched = this.checked ? true : null;
reloadItems(page);
});
$('#chkIsUnidentified', page).on('change', function () {
query.StartIndex = 0;
query.IsUnidentified = this.checked ? true : null;
reloadItems(page);
});
$('#chkIsLocked', page).on('change', function () {
query.StartIndex = 0;
query.IsLocked = this.checked ? true : null;
reloadItems(page);
});
$('#chkMissingEpisode', page).on('change', function () {
query.StartIndex = 0;
query.IsMissing = this.checked ? true : false;
reloadItems(page);
});
$('#chkFutureEpisode', page).on('change', function () {
query.StartIndex = 0;
if (this.checked) {
query.IsUnaired = true;
query.IsVirtualUnaired = null;
} else {
query.IsUnaired = null;
query.IsVirtualUnaired = false;
}
reloadItems(page);
});
$('#chkSpecialEpisode', page).on('change', function () {
query.ParentIndexNumber = this.checked ? 0 : null;
reloadItems(page);
});
}).on('pagebeforeshow', "#libraryReportPage", function () {
var page = this;
query.SortBy = getDefaultSortOrder($('#selectView', page).val());
query.SortOrder = "Ascending";
$('#selectView', page).val(query.IncludeItemTypes).selectmenu('refresh').trigger('change');
}).on('pageshow', "#libraryReportPage", function () {
updateFilterControls(this);
});
})(jQuery, document, window);