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

1137 lines
36 KiB
JavaScript
Raw Normal View History

2016-09-15 16:17:50 -07:00
define(['jQuery', 'libraryBrowser', 'fnchecked'], function ($, libraryBrowser) {
2016-10-22 22:11:46 -07:00
'use strict';
2016-03-19 20:28:03 -07:00
2014-03-08 11:17:05 -07:00
var defaultSortBy = "SortName";
2015-05-13 08:39:07 -07:00
var topItems = 5;
2014-03-08 11:17:05 -07:00
2014-03-02 13:44:48 -07:00
var query = {
2014-03-02 19:17:12 -07:00
StartIndex: 0,
2015-05-13 08:39:07 -07:00
Limit: 100,
2014-03-03 21:53:48 -07:00
IncludeItemTypes: "Movie",
2015-05-13 08:39:07 -07:00
HasQueryLimit: true,
2015-07-16 11:35:53 -07:00
GroupBy: "None",
ReportView: "ReportData",
DisplayType: "Screen",
2014-03-02 13:44:48 -07:00
};
2015-05-13 08:39:07 -07:00
function getTable(result) {
var html = '';
//Report table
html += '<table id="tblReport" data-role="table" data-mode="reflow" class="tblLibraryReport stripedTable ui-responsive table-stroke detailTable" style="display:table;">';
html += '<thead>';
2014-03-02 19:17:12 -07:00
2015-05-13 08:39:07 -07:00
//Report headers
result.Headers.map(function (header) {
var cellHtml = '<th data-priority="' + 'persist' + '">';
if (header.ShowHeaderLabel) {
if (header.SortField) {
cellHtml += '<a class="lnkColumnSort" href="#" data-sortfield="' + header.SortField + '" style="text-decoration:underline;">';
}
2015-05-13 08:39:07 -07:00
cellHtml += (header.Name || '&nbsp;');
if (header.SortField) {
cellHtml += '</a>';
if (header.SortField === defaultSortBy) {
2015-05-13 08:39:07 -07:00
if (query.SortOrder === "Descending") {
cellHtml += '<span style="font-weight:bold;margin-left:5px;vertical-align:top;font-size:14px">&darr;</span>';
} else {
cellHtml += '<span style="font-weight:bold;margin-left:5px;vertical-align:top;font-size:14px;">&uarr;</span>';
}
2015-05-13 08:39:07 -07:00
}
2014-03-03 21:53:48 -07:00
}
2015-05-13 08:39:07 -07:00
}
cellHtml += '</th>';
html += cellHtml;
});
html += '</thead>';
//Report body
html += '<tbody>';
if (result.IsGrouped === false) {
result.Rows.map(function (row) {
html += getRow(result.Headers, row);
});
}
else {
result.Groups.map(function (group) {
html += '<tr style="background-color: rgb(51, 51, 51);">';
html += '<th scope="rowgroup" colspan="' + result.Headers.length + '">' + (group.Name || '&nbsp;') + '</th>';
html += '</tr>';
group.Rows.map(function (row) {
html += getRow(result.Headers, row);
});
html += '<tr>';
html += '<th scope="rowgroup" colspan="' + result.Headers.length + '">' + '&nbsp;' + '</th>';
html += '</tr>';
});
2014-03-02 13:44:48 -07:00
}
2015-05-13 08:39:07 -07:00
html += '</tbody>';
html += '</table>';
return html;
2014-03-02 13:44:48 -07:00
}
2015-05-13 08:39:07 -07:00
function getRow(rHeaders, rRow) {
var html = '';
html += '<tr>';
2015-05-13 08:39:07 -07:00
for (var j = 0; j < rHeaders.length; j++) {
var rHeader = rHeaders[j];
var rItem = rRow.Columns[j];
html += getItem(rHeader, rRow, rItem);
}
html += '</tr>';
return html;
}
2015-05-13 08:39:07 -07:00
function getItem(rHeader, rRow, rItem) {
var html = '';
html += '<td>';
switch (rHeader.ItemViewType) {
case "None":
html += rItem.Name;
break;
case "Detail":
var id = rRow.Id;
if (rItem.Id)
id = rItem.Id;
html += '<a href="itemdetails.html?id=' + id + '">' + rItem.Name + '</a>';
break;
case "Edit":
html += '<a href="edititemmetadata.html?id=' + rRow.Id + '">' + rItem.Name + '</a>';
break;
case "List":
html += '<a href="itemlist.html?id=' + rRow.Id + '">' + rItem.Name + '</a>';
break;
case "ItemByNameDetails":
2015-08-18 21:08:03 -07:00
html += '<a href="itemdetails.html?id=' + rItem.Id + '&context=' + rRow.RowType + '">' + rItem.Name + '</a>';
2015-05-13 08:39:07 -07:00
break;
case "EmbeddedImage":
if (rRow.HasEmbeddedImage) {
html += '<div class="libraryReportIndicator clearLibraryReportIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
}
2015-05-13 08:39:07 -07:00
break;
case "SubtitleImage":
if (rRow.HasSubtitles) {
html += '<div class="libraryReportIndicator clearLibraryReportIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
}
2015-05-13 08:39:07 -07:00
break;
case "TrailersImage":
if (rRow.HasLocalTrailer) {
html += '<div class="libraryReportIndicator clearLibraryReportIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
}
2015-05-13 08:39:07 -07:00
break;
case "SpecialsImage":
if (rRow.HasSpecials) {
html += '<div class="libraryReportIndicator clearLibraryReportIndicator"><div class="ui-icon-check ui-btn-icon-notext"></div></div>';
}
2015-05-13 08:39:07 -07:00
break;
case "LockDataImage":
if (rRow.HasLockData) {
2016-07-15 12:54:34 -07:00
html += '<i class="md-icon">lock</i>';
}
break;
case "TagsPrimaryImage":
if (!rRow.HasImageTagsPrimary) {
html += '<a href="edititemimages.html?id=' + rRow.Id + '"><img src="css/images/editor/missingprimaryimage.png" title="Missing primary image." style="width:18px"/></a>';
}
break;
case "TagsBackdropImage":
if (!rRow.HasImageTagsBackdrop) {
if (rRow.RowType !== "Episode" && rRow.RowType !== "Season" && rRow.MediaType !== "Audio" && rRow.RowType !== "TvChannel" && rRow.RowType !== "MusicAlbum") {
html += '<a href="edititemimages.html?id=' + rRow.Id + '"><img src="css/images/editor/missingbackdrop.png" title="Missing backdrop image." style="width:18px"/></a>';
}
}
break;
case "TagsLogoImage":
if (!rRow.HasImageTagsLogo) {
if (rRow.RowType === "Movie" || rRow.RowType === "Trailer" || rRow.RowType === "Series" || rRow.RowType === "MusicArtist" || rRow.RowType === "BoxSet") {
html += '<a href="edititemimages.html?id=' + rRow.Id + '"><img src="css/images/editor/missinglogo.png" title="Missing logo image." style="width:18px"/></a>';
}
}
break;
case "UserPrimaryImage":
if (rRow.UserId) {
var userImage = ApiClient.getUserImageUrl(rRow.UserId, {
height: 24,
type: 'Primary'
});
if (userImage) {
html += '<img src="' + userImage + '" />';
} else {
html += '';
}
}
break;
2015-05-13 08:39:07 -07:00
case "StatusImage":
if (rRow.HasLockData) {
2016-07-15 12:54:34 -07:00
html += '<i class="md-icon">lock</i>';
}
2015-05-13 08:39:07 -07:00
if (!rRow.HasLocalTrailer && rRow.RowType === "Movie") {
2016-07-15 12:54:34 -07:00
html += '<i title="Missing local trailer." class="md-icon">videocam</i>';
}
2015-05-13 08:39:07 -07:00
if (!rRow.HasImageTagsPrimary) {
2015-07-16 11:35:53 -07:00
html += '<a href="edititemimages.html?id=' + rRow.Id + '"><img src="css/images/editor/missingprimaryimage.png" title="Missing primary image." style="width:18px"/></a>';
}
2015-05-13 08:39:07 -07:00
if (!rRow.HasImageTagsBackdrop) {
if (rRow.RowType !== "Episode" && rRow.RowType !== "Season" && rRow.MediaType !== "Audio" && rRow.RowType !== "TvChannel" && rRow.RowType !== "MusicAlbum") {
2015-07-16 11:35:53 -07:00
html += '<a href="edititemimages.html?id=' + rRow.Id + '"><img src="css/images/editor/missingbackdrop.png" title="Missing backdrop image." style="width:18px"/></a>';
2015-05-13 08:39:07 -07:00
}
}
2015-05-13 08:39:07 -07:00
if (!rRow.HasImageTagsLogo) {
if (rRow.RowType === "Movie" || rRow.RowType === "Trailer" || rRow.RowType === "Series" || rRow.RowType === "MusicArtist" || rRow.RowType === "BoxSet") {
2015-07-16 11:35:53 -07:00
html += '<a href="edititemimages.html?id=' + rRow.Id + '"><img src="css/images/editor/missinglogo.png" title="Missing logo image." style="width:18px"/></a>';
2015-05-13 08:39:07 -07:00
}
}
2015-05-13 08:39:07 -07:00
break;
default:
html += rItem.Name;
}
2015-05-13 08:39:07 -07:00
html += '</td>';
return html;
}
2015-05-13 08:39:07 -07:00
function getStats(result) {
var html = '';
html += '<div class="detailSection" >';
//html += '<div class="detailSectionHeader">If you like Africa Fever II, check these out...</div>';
html += '<div class="detailSectionContent">';
result.Groups.map(function (group) {
//html += '<div class="card transparentCard detailPageSquareCard" style="vertical-align: top;">';
//html += '<div class="card transparentCard horizontalBackdropCard" style="vertical-align: top;">';
//html += '<div class="card transparentCard backdropCard" style="vertical-align: top;">';
html += '<div class="card transparentCard bannerCard" style="vertical-align: top;">';
//html += '<div class="card transparentCard cardImage" style="vertical-align: top;">';
html += '<div class="visualCardBox">';
html += '<div class="cardBox " >';
html += '<div class="detailSection">'
html += '<div class="detailSectionHeader">';
html += '<span>' + group.Header + '&nbsp;' + '</span>';
html += '</div>';
html += '<div class="detailSectionContent">';
2015-12-14 08:43:03 -07:00
html += '<div class="childrenItemsContainer itemsContainer" style="text-align: left;">';
2015-05-13 08:39:07 -07:00
html += '<ul class="itemsListview ui-listview" >';
var l = group.Items.length - 1;
for (var j = 0; j < topItems ; j++) {
html += '<li class="ui-li listItem ui-li-has-alt ui-first-child">';
if (j <= l) {
var rItem = group.Items[j];
html += '<a class="item ui-btn"';
if (rItem.Id > "")
2015-08-18 21:08:03 -07:00
html += ' href="itemdetails.html?id=' + rItem.Id + '"';
2015-05-13 08:39:07 -07:00
html += '>' + rItem.Name + '&nbsp;' + '</a>';
html += '<a title="" class="listviewMenuButton ui-btn ui-btn-inline">' + rItem.Value + '&nbsp;' + '</a>';
}
else
html += '<a class="item ui-btn">' + '&nbsp;' + '</a>';
2015-05-13 08:39:07 -07:00
html += '</li>';
2015-05-13 08:39:07 -07:00
}
html += '</ul>';
html += '</div>';
html += '</div>';
html += '</div>';
2014-03-20 20:31:40 -07:00
2015-05-13 08:39:07 -07:00
html += '</div>';
html += '</div>';
html += '</div>';
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
});
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
html += '</div>';
//html += '</div>';
html += '</div>';
return html;
}
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
function ExportReport(page, e) {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
query.UserId = Dashboard.getCurrentUserId();
query.HasQueryLimit = false;
var url = ApiClient.getUrl("Reports/Items/Download", query);
2014-03-03 21:53:48 -07:00
2015-05-13 08:39:07 -07:00
if (url) {
window.location.href = url;
}
}
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
function loadGroupByFilters(page) {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
query.UserId = Dashboard.getCurrentUserId();
var url = "";
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
url = ApiClient.getUrl("Reports/Headers", query);
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(url).then(function (result) {
2015-05-13 08:39:07 -07:00
var selected = "None";
$('#selectReportGroup', page).find('option').remove().end();
$('#selectReportGroup', page).append('<option value="None"></option>');
result.map(function (header) {
if ((header.DisplayType === "Screen" || header.DisplayType === "ScreenExport") && header.CanGroup) {
2015-05-13 08:39:07 -07:00
if (header.FieldName.length > 0) {
var option = '<option value="' + header.FieldName + '">' + header.Name + '</option>';
$('#selectReportGroup', page).append(option);
if (query.GroupBy === header.FieldName)
selected = header.FieldName;
2014-03-03 21:53:48 -07:00
}
2015-05-13 08:39:07 -07:00
}
});
2015-09-03 10:01:51 -07:00
$('#selectPageSize', page).val(selected);
2014-03-02 19:17:12 -07:00
2015-05-13 08:39:07 -07:00
});
2014-03-03 21:53:48 -07:00
}
2014-03-02 19:17:12 -07:00
2015-05-13 08:39:07 -07:00
function renderItems(page, result) {
2014-03-02 19:17:12 -07:00
2015-06-28 07:45:21 -07:00
window.scrollTo(0, 0);
2014-03-03 21:53:48 -07:00
var html = '';
2014-03-02 19:17:12 -07:00
2015-07-16 11:35:53 -07:00
if (query.ReportView === "ReportData" || query.ReportView === "ReportStatistics") {
$('#selectIncludeItemTypesBox', page).show();
$('#tabFilter', page).show();
}
else {
$('#selectIncludeItemTypesBox', page).hide();
$('#tabFilterBox', page).hide();
$('#tabFilter', page).hide();
}
2014-03-02 19:17:12 -07:00
2016-07-18 20:57:55 -07:00
var pagingHtml = libraryBrowser.getQueryPagingHtml({
2015-07-16 11:35:53 -07:00
startIndex: query.StartIndex,
limit: query.Limit,
totalRecordCount: result.TotalRecordCount,
updatePageSizeSetting: false,
viewButton: true,
showLimit: false
});
if (query.ReportView === "ReportData" || query.ReportView === "ReportActivities") {
2014-03-02 19:17:12 -07:00
2015-07-16 11:35:53 -07:00
$('.listTopPaging', page).html(pagingHtml).trigger('create');
2016-03-19 20:28:03 -07:00
// page.querySelector('.listTopPaging').innerHTML = pagingHtml;
2015-05-13 08:39:07 -07:00
$('.listTopPaging', page).show();
2014-03-02 19:17:12 -07:00
2015-05-13 08:39:07 -07:00
$('.listBottomPaging', page).html(pagingHtml).trigger('create');
$('.listBottomPaging', page).show();
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
$('.btnNextPage', page).on('click', function () {
query.StartIndex += query.Limit;
reloadItems(page);
});
$('.btnNextPage', page).show();
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
$('.btnPreviousPage', page).on('click', function () {
query.StartIndex -= query.Limit;
reloadItems(page);
});
$('.btnPreviousPage', page).show();
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
$('#btnReportExport', page).show();
$('#selectPageSizeBox', page).show();
$('#selectReportGroupingBox', page).show();
$('#grpReportsColumns', page).show();
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
html += getTable(result);
2015-05-13 08:39:07 -07:00
$('.reporContainer', page).html(html).trigger('create');
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
$('.lnkColumnSort', page).on('click', function () {
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
var order = this.getAttribute('data-sortfield');
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
if (query.SortBy === order) {
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
if (query.SortOrder === "Descending") {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
query.SortOrder = "Ascending";
query.SortBy = defaultSortBy;
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
} else {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
query.SortOrder = "Descending";
query.SortBy = order;
}
} else {
2014-03-03 21:53:48 -07:00
2015-05-13 08:39:07 -07:00
query.SortOrder = "Ascending";
query.SortBy = order;
}
2014-03-03 21:53:48 -07:00
2015-05-13 08:39:07 -07:00
query.StartIndex = 0;
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
reloadItems(page);
});
}
else {
2015-07-16 11:35:53 -07:00
$('.listTopPaging', page).html(pagingHtml).trigger('create');
// page.querySelector('.listTopPaging').innerHTML = pagingHtml;
$('.listTopPaging', page).show();
2015-05-13 08:39:07 -07:00
$('.listBottomPaging', page).hide();
2015-07-16 11:35:53 -07:00
2015-05-13 08:39:07 -07:00
$('.btnNextPage', page).hide();
$('.btnPreviousPage', page).hide();
$('#btnReportExport', page).hide();
$('#selectPageSizeBox', page).hide();
$('#selectReportGroupingBox', page).hide();
$('#grpReportsColumns', page).hide();
html += getStats(result);
$('.reporContainer', page).html(html).trigger('create');
2014-03-02 13:44:48 -07:00
}
2015-05-13 08:39:07 -07:00
$('#GroupStatus', page).hide();
$('#GroupAirDays', page).hide();
$('#GroupEpisodes', page).hide();
switch (query.IncludeItemTypes) {
case "Series":
case "Season":
$('#GroupStatus', page).show();
$('#GroupAirDays', page).show();
break;
case "Episode":
$('#GroupStatus', page).show();
$('#GroupAirDays', page).show();
$('#GroupEpisodes', page).show();
break;
}
2015-07-16 11:35:53 -07:00
$('.viewPanel', page).refresh;
2014-03-02 13:44:48 -07:00
}
2015-05-13 08:39:07 -07:00
function reloadItems(page) {
Dashboard.showLoadingMsg();
query.UserId = Dashboard.getCurrentUserId();
var url = "";
2015-07-16 11:35:53 -07:00
switch (query.ReportView) {
2015-05-13 08:39:07 -07:00
case "ReportData":
query.HasQueryLimit = true;
url = ApiClient.getUrl("Reports/Items", query);
break;
2015-07-16 11:35:53 -07:00
case "ReportStatistics":
2015-05-13 08:39:07 -07:00
query.TopItems = topItems;
query.HasQueryLimit = false;
url = ApiClient.getUrl("Reports/Statistics", query);
break;
2015-07-16 11:35:53 -07:00
case "ReportActivities":
query.HasQueryLimit = true;
url = ApiClient.getUrl("Reports/Activities", query);
break;
2015-05-13 08:39:07 -07:00
}
2014-03-02 13:44:48 -07:00
2015-12-14 08:43:03 -07:00
ApiClient.getJSON(url).then(function (result) {
2015-05-13 08:39:07 -07:00
updateFilterControls(page);
renderItems(page, result);
2014-03-02 13:44:48 -07:00
});
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
Dashboard.hideLoadingMsg();
}
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
function updateFilterControls(page) {
$('.chkStandardFilter', page).each(function () {
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
var filters = "," + (query.Filters || "");
var filterName = this.getAttribute('data-filter');
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
this.checked = filters.indexOf(',' + filterName) != -1;
2014-03-08 11:17:05 -07:00
2016-09-11 14:02:32 -07:00
});
2014-03-08 11:17:05 -07:00
2015-05-13 08:39:07 -07:00
$('.chkVideoTypeFilter', page).each(function () {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
var filters = "," + (query.VideoTypes || "");
var filterName = this.getAttribute('data-filter');
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
this.checked = filters.indexOf(',' + filterName) != -1;
2014-03-02 13:44:48 -07:00
2016-09-11 14:02:32 -07:00
});
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
$('.chkStatus', page).each(function () {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
var filters = "," + (query.SeriesStatus || "");
var filterName = this.getAttribute('data-filter');
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
this.checked = filters.indexOf(',' + filterName) != -1;
2014-03-02 13:44:48 -07:00
2016-09-11 14:02:32 -07:00
});
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
$('.chkAirDays', page).each(function () {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
var filters = "," + (query.AirDays || "");
2014-03-02 13:44:48 -07:00
var filterName = this.getAttribute('data-filter');
this.checked = filters.indexOf(',' + filterName) != -1;
2016-09-11 14:02:32 -07:00
});
2014-03-02 13:44:48 -07:00
2016-09-11 14:02:32 -07:00
$('#chk3D', page).checked(query.Is3D == true);
$('#chkHD', page).checked(query.IsHD == true);
$('#chkSD', page).checked(query.IsHD == false);
2014-03-02 13:44:48 -07:00
2016-09-11 14:02:32 -07:00
$('#chkSubtitle', page).checked(query.HasSubtitles == true);
$('#chkTrailer', page).checked(query.HasTrailer == true);
$('#chkMissingTrailer', page).checked(query.HasTrailer == false);
$('#chkSpecialFeature', page).checked(query.HasSpecialFeature == true);
$('#chkThemeSong', page).checked(query.HasThemeSong == true);
$('#chkThemeVideo', page).checked(query.HasThemeVideo == true);
2014-03-02 13:44:48 -07:00
2015-09-03 10:01:51 -07:00
$('#selectPageSize', page).val(query.Limit);
2015-05-13 08:39:07 -07:00
//Management
2016-09-11 14:02:32 -07:00
$('#chkMissingRating', page).checked(query.HasOfficialRating == false);
$('#chkMissingOverview', page).checked(query.HasOverview == false);
$('#chkIsLocked', page).checked(query.IsLocked == true);
$('#chkMissingImdbId', page).checked(query.HasImdbId == false);
$('#chkMissingTmdbId', page).checked(query.HasTmdbId == false);
$('#chkMissingTvdbId', page).checked(query.HasTvdbId == false);
2014-03-03 21:53:48 -07:00
2015-05-13 08:39:07 -07:00
//Episodes
2016-09-11 14:02:32 -07:00
$('#chkSpecialEpisode', page).checked(query.ParentIndexNumber == 0);
$('#chkMissingEpisode', page).checked(query.IsMissing == true);
$('#chkFutureEpisode', page).checked(query.IsUnaired == true);
2015-05-13 08:39:07 -07:00
2015-09-03 10:01:51 -07:00
$('#selectIncludeItemTypes').val(query.IncludeItemTypes);
// isfavorite
if (query.IsFavorite == true) {
$('#isFavorite').val("true");
}
else if (query.IsFavorite == false) {
$('#isFavorite').val("false");
}
else {
$('#isFavorite').val("-");
}
2016-03-19 20:28:03 -07:00
2014-03-02 13:44:48 -07:00
}
2015-05-13 08:39:07 -07:00
var filtersLoaded;
function reloadFiltersIfNeeded(page) {
if (!filtersLoaded) {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
filtersLoaded = true;
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
QueryReportFilters.loadFilters(page, Dashboard.getCurrentUserId(), query, function () {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
reloadItems(page);
});
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
QueryReportColumns.loadColumns(page, Dashboard.getCurrentUserId(), query, function () {
reloadItems(page);
});
}
}
2015-09-01 07:01:59 -07:00
$(document).on('pageinit', "#libraryReportManagerPage", function () {
2015-05-13 08:39:07 -07:00
var page = this;
2014-03-02 13:44:48 -07:00
2015-07-16 11:35:53 -07:00
$('#selectIncludeItemTypes', page).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-07-16 11:35:53 -07:00
query.ReportView = $('#selectViewType', page).val();
2014-03-02 19:17:12 -07:00
query.IncludeItemTypes = this.value;
2015-05-13 08:39:07 -07:00
query.SortOrder = "Ascending";
query.ReportColumns = null;
$('.btnReportExport', page).hide();
filtersLoaded = false;
loadGroupByFilters(page);
reloadFiltersIfNeeded(page);
reloadItems(page);
});
2015-07-16 11:35:53 -07:00
$('#selectViewType', page).on('change', function () {
2015-05-13 08:39:07 -07:00
query.StartIndex = 0;
2015-07-16 11:35:53 -07:00
query.ReportView = this.value;
query.IncludeItemTypes = $('#selectIncludeItemTypes', page).val();
query.SortOrder = "Ascending";
2015-05-13 08:39:07 -07:00
filtersLoaded = false;
2015-07-16 11:35:53 -07:00
query.ReportColumns = null;
2015-05-13 08:39:07 -07:00
loadGroupByFilters(page);
reloadFiltersIfNeeded(page);
reloadItems(page);
});
$('#selectReportGroup', page).on('change', function () {
query.GroupBy = this.value;
query.StartIndex = 0;
reloadItems(page);
});
$('#btnReportExportCsv', page).on('click', function (e) {
query.ExportType = "CSV";
ExportReport(page, e);
});
$('#btnReportExportExcel', page).on('click', function (e) {
query.ExportType = "Excel";
ExportReport(page, e);
});
$('#btnResetReportColumns', page).on('click', function (e) {
query.ReportColumns = null;
query.StartIndex = 0;
filtersLoaded = false;
reloadFiltersIfNeeded(page);
reloadItems(page);
});
$('.viewPanel', page).on('panelopen', function () {
reloadFiltersIfNeeded(page);
});
$('#selectPageSize', page).on('change', function () {
query.Limit = parseInt(this.value);
query.StartIndex = 0;
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
$('#isFavorite', page).on('change', function () {
if (this.value == "true") {
query.IsFavorite = true;
}
else if (this.value == "false") {
query.IsFavorite = false;
}
else {
query.IsFavorite = null;
}
query.StartIndex = 0;
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('.chkStandardFilter', this).on('change', function () {
2014-03-02 13:44:48 -07:00
var filterName = this.getAttribute('data-filter');
2015-05-13 08:39:07 -07:00
var filters = query.Filters || "";
2014-03-02 13:44:48 -07:00
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.Filters = filters;
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('.chkVideoTypeFilter', this).on('change', function () {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.VideoTypes || "";
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
filters = (',' + filters).replace(',' + filterName, '').substring(1);
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.VideoTypes = filters;
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chk3D', this).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.Is3D = this.checked ? true : null;
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkHD', this).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.IsHD = this.checked ? true : null;
2014-05-02 07:49:28 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkSD', this).on('change', function () {
2014-05-02 07:49:28 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.IsHD = this.checked ? false : null;
2014-05-02 07:49:28 -07:00
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkSubtitle', this).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.HasSubtitles = this.checked ? true : null;
2014-08-22 19:58:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkTrailer', this).on('change', function () {
2014-08-22 19:58:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.HasTrailer = this.checked ? true : null;
2014-08-22 19:58:48 -07:00
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2015-07-16 11:35:53 -07:00
$('#chkMissingTrailer', this).on('change', function () {
query.StartIndex = 0;
query.HasTrailer = this.checked ? false : null;
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkSpecialFeature', this).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
query.HasSpecialFeature = this.checked ? true : null;
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkThemeSong', this).on('change', function () {
2014-03-03 21:53:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.HasThemeSong = this.checked ? true : null;
2014-03-03 21:53:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkThemeVideo', this).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.HasThemeVideo = this.checked ? true : null;
2014-08-22 19:58:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#radioBasicFilters', this).on('change', function () {
2014-08-22 19:58:48 -07:00
2015-05-13 08:39:07 -07:00
if (this.checked) {
$('.basicFilters', page).show();
$('.advancedFilters', page).hide();
} else {
$('.basicFilters', page).hide();
}
});
2014-08-22 19:58:48 -07:00
2015-05-13 08:39:07 -07:00
$('#radioAdvancedFilters', this).on('change', function () {
2014-08-22 19:58:48 -07:00
2015-05-13 08:39:07 -07:00
if (this.checked) {
$('.advancedFilters', page).show();
$('.basicFilters', page).hide();
} else {
$('.advancedFilters', page).hide();
}
2014-03-02 13:44:48 -07:00
});
2015-05-13 08:39:07 -07:00
//Management
$('#chkIsLocked', page).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.IsLocked = this.checked ? true : null;
2014-08-22 19:58:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkMissingOverview', page).on('change', function () {
2014-08-22 19:58:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.HasOverview = this.checked ? false : null;
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
$('#chkMissingEpisode', page).on('change', function () {
2014-03-02 13:44:48 -07:00
query.StartIndex = 0;
2015-05-13 08:39:07 -07:00
query.IsMissing = this.checked ? true : false;
2014-03-02 13:44:48 -07:00
reloadItems(page);
});
2014-03-03 21:53:48 -07:00
$('#chkMissingRating', page).on('change', function () {
query.StartIndex = 0;
query.HasOfficialRating = this.checked ? false : null;
reloadItems(page);
});
$('#chkMissingImdbId', page).on('change', function () {
query.StartIndex = 0;
query.HasImdbId = this.checked ? false : null;
reloadItems(page);
});
$('#chkMissingTmdbId', page).on('change', function () {
query.StartIndex = 0;
query.HasTmdbId = this.checked ? false : null;
reloadItems(page);
});
$('#chkMissingTvdbId', page).on('change', function () {
query.StartIndex = 0;
query.HasTvdbId = this.checked ? false : null;
reloadItems(page);
});
2015-05-13 08:39:07 -07:00
//Episodes
2014-03-03 21:53:48 -07:00
$('#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);
});
2015-05-13 08:39:07 -07:00
$('.chkAirDays', this).on('change', function () {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
var filterName = this.getAttribute('data-filter');
var filters = query.AirDays || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.AirDays = filters;
query.StartIndex = 0;
reloadItems(page);
});
$('.chkStatus', this).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.SeriesStatus || "";
filters = (',' + filters).replace(',' + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + ',' + filterName) : filterName;
}
query.SeriesStatus = filters;
query.StartIndex = 0;
reloadItems(page);
});
2015-10-14 21:32:10 -07:00
$(page.getElementsByClassName('viewTabButton')).on('click', function () {
var parent = $(this).parents('.viewPanel');
$('.viewTabButton', parent).removeClass('ui-btn-active');
this.classList.add('ui-btn-active');
$('.viewTab', parent).addClass('hide');
$('.' + this.getAttribute('data-tab'), parent).removeClass('hide');
});
2015-05-13 08:39:07 -07:00
})
2015-09-24 10:08:10 -07:00
.on('pageshow', "#libraryReportManagerPage", function () {
2015-05-13 08:39:07 -07:00
query.UserId = Dashboard.getCurrentUserId();
var page = this;
query.SortOrder = "Ascending";
2015-05-18 10:51:48 -07:00
QueryReportFilters.onPageShow(page, query);
QueryReportColumns.onPageShow(page, query);
2015-09-03 10:01:51 -07:00
$('#selectIncludeItemTypes', page).val(query.IncludeItemTypes).trigger('change');
2015-05-13 08:39:07 -07:00
updateFilterControls(page);
filtersLoaded = false;
updateFilterControls(this);
});
function renderOptions(page, selector, cssClass, items) {
var elem;
if (items.length) {
elem = $(selector, page).show();
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
} else {
elem = $(selector, page).hide();
}
var html = '';
// style="margin: -.2em -.8em;"
html += '<div data-role="controlgroup">';
var index = 0;
var idPrefix = 'chk' + selector.substring(1);
html += items.map(function (filter) {
var itemHtml = '';
var id = idPrefix + index;
var label = filter;
var value = filter;
var checked = false;
if (filter.FieldName) {
label = filter.Name;
value = filter.FieldName;
checked = filter.Visible;
}
itemHtml += '<label for="' + id + '">' + label + '</label>';
itemHtml += '<input id="' + id + '" type="checkbox" data-filter="' + value + '" class="' + cssClass + '"';
if (checked)
itemHtml += ' checked="checked" ';
itemHtml += '/>';
index++;
return itemHtml;
}).join('');
html += '</div>';
$('.filterOptions', elem).html(html).trigger('create');
}
function renderFilters(page, result) {
if (result.Tags) {
result.Tags.length = Math.min(result.Tags.length, 50);
}
renderOptions(page, '.genreFilters', 'chkGenreFilter', result.Genres);
renderOptions(page, '.officialRatingFilters', 'chkOfficialRatingFilter', result.OfficialRatings);
renderOptions(page, '.tagFilters', 'chkTagFilter', result.Tags);
renderOptions(page, '.yearFilters', 'chkYearFilter', result.Years);
}
function renderColumnss(page, result) {
if (result.Tags) {
result.Tags.length = Math.min(result.Tags.length, 50);
}
renderOptions(page, '.reportsColumns', 'chkReportColumns', result);
}
function onFiltersLoaded(page, query, reloadItemsFn) {
$('.chkGenreFilter', page).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.Genres || "";
var delimiter = '|';
filters = (delimiter + filters).replace(delimiter + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + delimiter + filterName) : filterName;
}
query.StartIndex = 0;
query.Genres = filters;
reloadItemsFn();
});
$('.chkTagFilter', page).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.Tags || "";
var delimiter = '|';
filters = (delimiter + filters).replace(delimiter + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + delimiter + filterName) : filterName;
}
query.StartIndex = 0;
query.Tags = filters;
reloadItemsFn();
});
$('.chkYearFilter', page).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.Years || "";
var delimiter = ',';
filters = (delimiter + filters).replace(delimiter + filterName, '').substring(1);
2015-05-13 08:39:07 -07:00
if (this.checked) {
filters = filters ? (filters + delimiter + filterName) : filterName;
}
query.StartIndex = 0;
query.Years = filters;
reloadItemsFn();
});
$('.chkOfficialRatingFilter', page).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.OfficialRatings || "";
var delimiter = '|';
filters = (delimiter + filters).replace(delimiter + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + delimiter + filterName) : filterName;
}
query.StartIndex = 0;
query.OfficialRatings = filters;
reloadItemsFn();
});
}
function onColumnsLoaded(page, query, reloadItemsFn) {
$('.chkReportColumns', page).on('change', function () {
var filterName = this.getAttribute('data-filter');
var filters = query.ReportColumns || "";
var delimiter = '|';
filters = (delimiter + filters).replace(delimiter + filterName, '').substring(1);
if (this.checked) {
filters = filters ? (filters + delimiter + filterName) : filterName;
}
query.StartIndex = 0;
query.ReportColumns = filters;
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
reloadItemsFn();
});
}
function loadFilters(page, userId, itemQuery, reloadItemsFn) {
return ApiClient.getJSON(ApiClient.getUrl('Items/Filters', {
UserId: userId,
ParentId: itemQuery.ParentId,
2015-07-16 11:35:53 -07:00
IncludeItemTypes: itemQuery.IncludeItemTypes,
ReportView: itemQuery.ReportView
2015-05-13 08:39:07 -07:00
2015-12-14 08:43:03 -07:00
})).then(function (result) {
2015-05-13 08:39:07 -07:00
renderFilters(page, result);
onFiltersLoaded(page, itemQuery, reloadItemsFn);
});
}
function loadColumns(page, userId, itemQuery, reloadItemsFn) {
return ApiClient.getJSON(ApiClient.getUrl('Reports/Headers', {
UserId: userId,
2015-07-16 11:35:53 -07:00
IncludeItemTypes: itemQuery.IncludeItemTypes,
ReportView: itemQuery.ReportView
2014-03-02 13:44:48 -07:00
2015-12-14 08:43:03 -07:00
})).then(function (result) {
2014-03-02 13:44:48 -07:00
2015-05-13 08:39:07 -07:00
renderColumnss(page, result);
var filters = "";
var delimiter = '|';
result.map(function (item) {
2014-03-02 13:44:48 -07:00
if ((item.DisplayType === "Screen" || item.DisplayType === "ScreenExport"))
2015-05-13 08:39:07 -07:00
filters = filters ? (filters + delimiter + item.FieldName) : item.FieldName;
});
if (!itemQuery.ReportColumns)
itemQuery.ReportColumns = filters;
onColumnsLoaded(page, itemQuery, reloadItemsFn);
});
}
function onPageShow(page, query) {
query.Genres = null;
query.Years = null;
query.OfficialRatings = null;
query.Tags = null;
}
function onPageReportColumnsShow(page, query) {
query.ReportColumns = null;
}
window.QueryReportFilters = {
loadFilters: loadFilters,
onPageShow: onPageShow
};
window.QueryReportColumns = {
loadColumns: loadColumns,
onPageShow: onPageReportColumnsShow
};
});