(function ($, document) { var defaultSortBy = "SortName"; var SelectedReportView = "ReportData"; var topItems = 5; var query = { StartIndex: 0, Limit: 100, IncludeItemTypes: "Movie", HasQueryLimit: true, GroupBy: "None" }; function getTable(result) { var html = ''; //Report table html += ''; html += ''; //Report headers result.Headers.map(function (header) { var cellHtml = ''; html += cellHtml; }); html += ''; //Report body html += ''; if (result.IsGrouped === false) { result.Rows.map(function (row) { html += getRow(result.Headers, row); }); } else { result.Groups.map(function (group) { html += ''; html += ''; html += ''; group.Rows.map(function (row) { html += getRow(result.Headers, row); }); html += ''; html += ''; html += ''; }); } html += ''; html += '
'; if (header.SortField) { cellHtml += ''; } cellHtml += (header.Name || ' '); if (header.SortField) { cellHtml += ''; if (header.SortField === defaultSortBy) { if (query.SortOrder === "Descending") { cellHtml += ''; } else { cellHtml += ''; } } } cellHtml += '
' + (group.Name || ' ') + '
' + ' ' + '
'; return html; } function getRow(rHeaders, rRow) { var html = ''; html += ''; for (var j = 0; j < rHeaders.length; j++) { var rHeader = rHeaders[j]; var rItem = rRow.Columns[j]; html += getItem(rHeader, rRow, rItem); } html += ''; return html; } function getItem(rHeader, rRow, rItem) { var html = ''; html += ''; switch (rHeader.ItemViewType) { case "None": html += rItem.Name; break; case "Detail": var id = rRow.Id; if (rItem.Id) id = rItem.Id; html += '' + rItem.Name + ''; break; case "Edit": html += '' + rItem.Name + ''; break; case "List": html += '' + rItem.Name + ''; break; case "ItemByNameDetails": html += '' + rItem.Name + ''; break; case "EmbeddedImage": if (rRow.HasEmbeddedImage) { html += '
'; } break; case "SubtitleImage": if (rRow.HasSubtitles) { html += '
'; } break; case "TrailersImage": if (rRow.HasLocalTrailer) { html += '
'; } break; case "SpecialsImage": if (rRow.HasSpecials) { html += '
'; } break; case "StatusImage": if (rRow.HasLockData) { html += ''; } if (rRow.IsUnidentified) { html += '
'; } if (!rRow.HasLocalTrailer && rRow.RowType === "Movie") { html += ''; } if (!rRow.HasImageTagsPrimary) { html += ''; } if (!rRow.HasImageTagsBackdrop) { if (rRow.RowType !== "Episode" && rRow.RowType !== "Season" && rRow.MediaType !== "Audio" && rRow.RowType !== "TvChannel" && rRow.RowType !== "MusicAlbum") { html += ''; } } if (!rRow.HasImageTagsLogo) { if (rRow.RowType === "Movie" || rRow.RowType === "Trailer" || rRow.RowType === "Series" || rRow.RowType === "MusicArtist" || rRow.RowType === "BoxSet") { html += ''; } } break; default: html += rItem.Name; } html += ''; return html; } function getStats(result) { var html = ''; html += '
'; //html += '
If you like Africa Fever II, check these out...
'; html += '
'; result.Groups.map(function (group) { //html += '
'; //html += '
'; //html += '
'; html += '
'; //html += '
'; html += '
'; html += '
'; html += '
' html += '
'; html += '' + group.Header + ' ' + ''; html += '
'; html += '
'; html += '
'; html += ''; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; html += '
'; }); html += '
'; //html += '
'; html += '
'; return html; } function ExportReport(page, e) { query.UserId = Dashboard.getCurrentUserId(); query.HasQueryLimit = false; var url = ApiClient.getUrl("Reports/Items/Download", query); if (url) { e.preventDefault(); //stop the browser from following window.location.href = url; } } function loadGroupByFilters(page) { query.UserId = Dashboard.getCurrentUserId(); var url = ""; url = ApiClient.getUrl("Reports/Headers", query); ApiClient.getJSON(url).done(function (result) { var selected = "None"; $('#selectReportGroup', page).find('option').remove().end(); $('#selectReportGroup', page).append(''); result.map(function (header) { if (header.Visible && header.CanGroup) { if (header.FieldName.length > 0) { var option = ''; $('#selectReportGroup', page).append(option); if (query.GroupBy === header.FieldName) selected = header.FieldName; } } }); $('#selectPageSize', page).val(selected).selectmenu('refresh'); }); } function renderItems(page, result) { window.scrollTo(0, 0); var html = ''; if (SelectedReportView === "ReportData") { var pagingHtml = LibraryBrowser.getQueryPagingHtml({ startIndex: query.StartIndex, limit: query.Limit, totalRecordCount: result.TotalRecordCount, updatePageSizeSetting: false, viewButton: true, showLimit: false }); page.querySelector('.listTopPaging').innerHTML = pagingHtml; $('.listTopPaging', page).show(); $('.listBottomPaging', page).html(pagingHtml).trigger('create'); $('.listBottomPaging', page).show(); $('.btnNextPage', page).on('click', function () { query.StartIndex += query.Limit; reloadItems(page); }); $('.btnNextPage', page).show(); $('.btnPreviousPage', page).on('click', function () { query.StartIndex -= query.Limit; reloadItems(page); }); $('.btnPreviousPage', page).show(); $('#btnReportExport', page).show(); $('#selectPageSizeBox', page).show(); $('#selectReportGroupingBox', page).show(); $('#grpReportsColumns', page).show(); html += getTable(result); $('.reporContainer', page).html(html).trigger('create'); $('.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); }); } else { $('.listTopPaging', page).hide(); $('.listBottomPaging', page).hide(); $('.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'); } $('#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; } } function reloadItems(page) { Dashboard.showLoadingMsg(); query.UserId = Dashboard.getCurrentUserId(); var url = ""; switch (SelectedReportView) { case "ReportData": query.HasQueryLimit = true; url = ApiClient.getUrl("Reports/Items", query); break; case "ReportStatistic": query.TopItems = topItems; query.HasQueryLimit = false; url = ApiClient.getUrl("Reports/Statistics", query); break; } ApiClient.getJSON(url).done(function (result) { updateFilterControls(page); renderItems(page, result); }); Dashboard.hideLoadingMsg(); } function updateFilterControls(page) { $('.chkStandardFilter', page).each(function () { var filters = "," + (query.Filters || ""); var filterName = this.getAttribute('data-filter'); this.checked = filters.indexOf(',' + filterName) != -1; }).checkboxradio('refresh'); $('.chkVideoTypeFilter', page).each(function () { var filters = "," + (query.VideoTypes || ""); var filterName = this.getAttribute('data-filter'); this.checked = filters.indexOf(',' + filterName) != -1; }).checkboxradio('refresh'); $('.chkStatus', page).each(function () { var filters = "," + (query.SeriesStatus || ""); var filterName = this.getAttribute('data-filter'); this.checked = filters.indexOf(',' + filterName) != -1; }).checkboxradio('refresh'); $('.chkAirDays', page).each(function () { var filters = "," + (query.AirDays || ""); 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'); $('#chkTrailer', page).checked(query.HasTrailer == true).checkboxradio('refresh'); $('#chkSpecialFeature', page).checked(query.HasSpecialFeature == true).checkboxradio('refresh'); $('#chkThemeSong', page).checked(query.HasThemeSong == true).checkboxradio('refresh'); $('#chkThemeVideo', page).checked(query.HasThemeVideo == true).checkboxradio('refresh'); $('#selectPageSize', page).val(query.Limit).selectmenu('refresh'); //Management $('#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'); //Episodes $('#chkSpecialEpisode', page).checked(query.ParentIndexNumber == 0).checkboxradio('refresh'); $('#chkMissingEpisode', page).checked(query.IsMissing == true).checkboxradio('refresh'); $('#chkFutureEpisode', page).checked(query.IsUnaired == true).checkboxradio('refresh'); $('#selectView').val(query.IncludeItemTypes).selectmenu('refresh'); } var filtersLoaded; function reloadFiltersIfNeeded(page) { if (!filtersLoaded) { filtersLoaded = true; QueryReportFilters.loadFilters(page, Dashboard.getCurrentUserId(), query, function () { reloadItems(page); }); QueryReportColumns.loadColumns(page, Dashboard.getCurrentUserId(), query, function () { reloadItems(page); }); } } $(document).on('pageinitdepends', "#libraryReportManagerPage", function () { var page = this; $('#selectView', page).on('change', function () { query.StartIndex = 0; SelectedReportView = $('#selectReportType', page).val(); query.IncludeItemTypes = this.value; query.SortOrder = "Ascending"; query.ReportColumns = null; $('.btnReportExport', page).hide(); filtersLoaded = false; loadGroupByFilters(page); reloadFiltersIfNeeded(page); reloadItems(page); }); $('#selectReportType', page).on('change', function () { query.StartIndex = 0; query.IncludeItemTypes = $('#selectView', page).val(); SelectedReportView = this.value; query.SortOrder = "Ascending"; filtersLoaded = false; 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; 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); }); $('.chkVideoTypeFilter', this).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', this).on('change', function () { query.StartIndex = 0; query.Is3D = this.checked ? true : null; reloadItems(page); }); $('#chkHD', this).on('change', function () { query.StartIndex = 0; query.IsHD = this.checked ? true : null; reloadItems(page); }); $('#chkSD', this).on('change', function () { query.StartIndex = 0; query.IsHD = this.checked ? false : null; reloadItems(page); }); $('#chkSubtitle', this).on('change', function () { query.StartIndex = 0; query.HasSubtitles = this.checked ? true : null; reloadItems(page); }); $('#chkTrailer', this).on('change', function () { query.StartIndex = 0; query.HasTrailer = this.checked ? true : null; reloadItems(page); }); $('#chkSpecialFeature', this).on('change', function () { query.StartIndex = 0; query.HasSpecialFeature = this.checked ? true : null; reloadItems(page); }); $('#chkThemeSong', this).on('change', function () { query.StartIndex = 0; query.HasThemeSong = this.checked ? true : null; reloadItems(page); }); $('#chkThemeVideo', this).on('change', function () { query.StartIndex = 0; query.HasThemeVideo = this.checked ? true : null; reloadItems(page); }); $('#radioBasicFilters', this).on('change', function () { if (this.checked) { $('.basicFilters', page).show(); $('.advancedFilters', page).hide(); } else { $('.basicFilters', page).hide(); } }); $('#radioAdvancedFilters', this).on('change', function () { if (this.checked) { $('.advancedFilters', page).show(); $('.basicFilters', page).hide(); } else { $('.advancedFilters', page).hide(); } }); //Management $('#chkIsLocked', page).on('change', function () { query.StartIndex = 0; query.IsLocked = this.checked ? true : null; reloadItems(page); }); $('#chkMissingOverview', page).on('change', function () { query.StartIndex = 0; query.HasOverview = this.checked ? false : null; reloadItems(page); }); $('#chkMissingEpisode', page).on('change', function () { query.StartIndex = 0; query.IsMissing = this.checked ? true : false; 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); }); //Episodes $('#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); }); $('.chkAirDays', this).on('change', function () { 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); }); }) .on('pageshowready', "#libraryReportManagerPage", function () { query.UserId = Dashboard.getCurrentUserId(); var page = this; query.SortOrder = "Ascending"; QueryReportFilters.onPageShow(page, query); QueryReportColumns.onPageShow(page, query); $('#selectView', page).val(query.IncludeItemTypes).selectmenu('refresh').trigger('change'); updateFilterControls(page); filtersLoaded = false; updateFilterControls(this); }); })(jQuery, document); (function (window) { function renderOptions(page, selector, cssClass, items) { var elem; if (items.length) { elem = $(selector, page).show(); } else { elem = $(selector, page).hide(); } var html = ''; // style="margin: -.2em -.8em;" html += '
'; 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 += ''; itemHtml += '