define(['jQuery'], function ($) { var defaultSortBy = "SortName"; var topItems = 5; var query = { StartIndex: 0, Limit: 100, IncludeItemTypes: "Movie", HasQueryLimit: true, GroupBy: "None", ReportView: "ReportData", DisplayType: "Screen", }; 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.ShowHeaderLabel) { 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 "LockDataImage": if (rRow.HasLockData) { html += ''; } break; case "TagsPrimaryImage": if (!rRow.HasImageTagsPrimary) { html += ''; } break; case "TagsBackdropImage": if (!rRow.HasImageTagsBackdrop) { if (rRow.RowType !== "Episode" && rRow.RowType !== "Season" && rRow.MediaType !== "Audio" && rRow.RowType !== "TvChannel" && rRow.RowType !== "MusicAlbum") { html += ''; } } break; case "TagsLogoImage": if (!rRow.HasImageTagsLogo) { if (rRow.RowType === "Movie" || rRow.RowType === "Trailer" || rRow.RowType === "Series" || rRow.RowType === "MusicArtist" || rRow.RowType === "BoxSet") { html += ''; } } break; case "UserPrimaryImage": if (rRow.UserId) { var userImage = ApiClient.getUserImageUrl(rRow.UserId, { height: 24, type: 'Primary' }); if (userImage) { html += ''; } else { html += ''; } } break; case "StatusImage": if (rRow.HasLockData) { 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) { window.location.href = url; } } function loadGroupByFilters(page) { query.UserId = Dashboard.getCurrentUserId(); var url = ""; url = ApiClient.getUrl("Reports/Headers", query); ApiClient.getJSON(url).then(function (result) { var selected = "None"; $('#selectReportGroup', page).find('option').remove().end(); $('#selectReportGroup', page).append(''); result.map(function (header) { if ((header.DisplayType === "Screen" || header.DisplayType === "ScreenExport") && 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); }); } function renderItems(page, result) { window.scrollTo(0, 0); var html = ''; if (query.ReportView === "ReportData" || query.ReportView === "ReportStatistics") { $('#selectIncludeItemTypesBox', page).show(); $('#tabFilter', page).show(); } else { $('#selectIncludeItemTypesBox', page).hide(); $('#tabFilterBox', page).hide(); $('#tabFilter', page).hide(); } var pagingHtml = LibraryBrowser.getQueryPagingHtml({ startIndex: query.StartIndex, limit: query.Limit, totalRecordCount: result.TotalRecordCount, updatePageSizeSetting: false, viewButton: true, showLimit: false }); if (query.ReportView === "ReportData" || query.ReportView === "ReportActivities") { $('.listTopPaging', page).html(pagingHtml).trigger('create'); // 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).html(pagingHtml).trigger('create'); // page.querySelector('.listTopPaging').innerHTML = pagingHtml; $('.listTopPaging', page).show(); $('.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; } $('.viewPanel', page).refresh; } function reloadItems(page) { Dashboard.showLoadingMsg(); query.UserId = Dashboard.getCurrentUserId(); var url = ""; switch (query.ReportView) { case "ReportData": query.HasQueryLimit = true; url = ApiClient.getUrl("Reports/Items", query); break; case "ReportStatistics": query.TopItems = topItems; query.HasQueryLimit = false; url = ApiClient.getUrl("Reports/Statistics", query); break; case "ReportActivities": query.HasQueryLimit = true; url = ApiClient.getUrl("Reports/Activities", query); break; } ApiClient.getJSON(url).then(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'); $('#chkMissingTrailer', page).checked(query.HasTrailer == false).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); //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'); $('#chkIsLocked', page).checked(query.IsLocked == true).checkboxradio('refresh'); $('#chkMissingImdbId', page).checked(query.HasImdbId == false).checkboxradio('refresh'); $('#chkMissingTmdbId', page).checked(query.HasTmdbId == false).checkboxradio('refresh'); $('#chkMissingTvdbId', page).checked(query.HasTvdbId == false).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'); $('#selectIncludeItemTypes').val(query.IncludeItemTypes); // isfavorite if (query.IsFavorite == true) { $('#isFavorite').val("true"); } else if (query.IsFavorite == false) { $('#isFavorite').val("false"); } else { $('#isFavorite').val("-"); } } 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('pageinit', "#libraryReportManagerPage", function () { var page = this; $('#selectIncludeItemTypes', page).on('change', function () { query.StartIndex = 0; query.ReportView = $('#selectViewType', page).val(); query.IncludeItemTypes = this.value; query.SortOrder = "Ascending"; query.ReportColumns = null; $('.btnReportExport', page).hide(); filtersLoaded = false; loadGroupByFilters(page); reloadFiltersIfNeeded(page); reloadItems(page); }); $('#selectViewType', page).on('change', function () { query.StartIndex = 0; query.ReportView = this.value; query.IncludeItemTypes = $('#selectIncludeItemTypes', page).val(); query.SortOrder = "Ascending"; filtersLoaded = false; query.ReportColumns = null; 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); }); $('#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); }); $('.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); }); $('#chkMissingTrailer', this).on('change', function () { query.StartIndex = 0; query.HasTrailer = this.checked ? false : 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); }); $('#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); }); $('#chkYearMismatch', page).on('change', function () { query.StartIndex = 0; query.IsYearMismatched = 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); }); $(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'); }); }) .on('pageshow', "#libraryReportManagerPage", function () { query.UserId = Dashboard.getCurrentUserId(); var page = this; query.SortOrder = "Ascending"; QueryReportFilters.onPageShow(page, query); QueryReportColumns.onPageShow(page, query); $('#selectIncludeItemTypes', page).val(query.IncludeItemTypes).trigger('change'); updateFilterControls(page); filtersLoaded = false; updateFilterControls(this); }); 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 += '