define(["jQuery","libraryBrowser","loading","fnchecked"],function($,libraryBrowser,loading){"use strict";function getTable(result){var html="";return html+='',html+="",result.Headers.map(function(header){var cellHtml='",html+=cellHtml}),html+="",html+="",result.IsGrouped===!1?result.Rows.map(function(row){html+=getRow(result.Headers,row)}):result.Groups.map(function(group){html+='',html+='",html+="",group.Rows.map(function(row){html+=getRow(result.Headers,row)}),html+="",html+='',html+=""}),html+="",html+="
';header.ShowHeaderLabel&&(header.SortField&&(cellHtml+=''),cellHtml+=header.Name||" ",header.SortField&&(cellHtml+="",header.SortField===defaultSortBy&&(cellHtml+="Descending"===query.SortOrder?'':''))),cellHtml+="
'+(group.Name||" ")+"
 
"}function getRow(rHeaders,rRow){var html="";html+="";for(var j=0;j'+rItem.Name+"";break;case"Edit":html+=''+rItem.Name+"";break;case"List":html+=''+rItem.Name+"";break;case"ItemByNameDetails":html+=''+rItem.Name+"";break;case"EmbeddedImage":rRow.HasEmbeddedImage&&(html+='
');break;case"SubtitleImage":rRow.HasSubtitles&&(html+='
');break;case"TrailersImage":rRow.HasLocalTrailer&&(html+='
');break;case"SpecialsImage":rRow.HasSpecials&&(html+='
');break;case"LockDataImage":rRow.HasLockData&&(html+='lock');break;case"TagsPrimaryImage":rRow.HasImageTagsPrimary||(html+='');break;case"TagsBackdropImage":rRow.HasImageTagsBackdrop||"Episode"!==rRow.RowType&&"Season"!==rRow.RowType&&"Audio"!==rRow.MediaType&&"TvChannel"!==rRow.RowType&&"MusicAlbum"!==rRow.RowType&&(html+='');break;case"TagsLogoImage":rRow.HasImageTagsLogo||"Movie"!==rRow.RowType&&"Trailer"!==rRow.RowType&&"Series"!==rRow.RowType&&"MusicArtist"!==rRow.RowType&&"BoxSet"!==rRow.RowType||(html+='');break;case"UserPrimaryImage":if(rRow.UserId){var userImage=ApiClient.getUserImageUrl(rRow.UserId,{height:24,type:"Primary"});html+=userImage?'':""}break;case"StatusImage":rRow.HasLockData&&(html+='lock'),rRow.HasLocalTrailer||"Movie"!==rRow.RowType||(html+='videocam'),rRow.HasImageTagsPrimary||(html+=''),rRow.HasImageTagsBackdrop||"Episode"!==rRow.RowType&&"Season"!==rRow.RowType&&"Audio"!==rRow.MediaType&&"TvChannel"!==rRow.RowType&&"MusicAlbum"!==rRow.RowType&&(html+=''),rRow.HasImageTagsLogo||"Movie"!==rRow.RowType&&"Trailer"!==rRow.RowType&&"Series"!==rRow.RowType&&"MusicArtist"!==rRow.RowType&&"BoxSet"!==rRow.RowType||(html+='');break;default:html+=rItem.Name}return html+=""}function ExportReport(page,e){query.UserId=Dashboard.getCurrentUserId(),query.HasQueryLimit=!1;var url=ApiClient.getUrl("Reports/Items/Download",query);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(("Screen"===header.DisplayType||"ScreenExport"===header.DisplayType)&&header.CanGroup&&header.FieldName.length>0){var option='";$("#selectReportGroup",page).append(option),query.GroupBy===header.FieldName&&(selected=header.FieldName)}}),$("#selectPageSize",page).val(selected)})}function renderItems(page,result){window.scrollTo(0,0);var html="";"ReportData"===query.ReportView?($("#selectIncludeItemTypesBox",page).show(),$("#tabFilter",page).show()):($("#selectIncludeItemTypesBox",page).hide(),$("#tabFilterBox",page).hide(),$("#tabFilter",page).hide());var pagingHtml=libraryBrowser.getQueryPagingHtml({startIndex:query.StartIndex,limit:query.Limit,totalRecordCount:result.TotalRecordCount,updatePageSizeSetting:!1,viewButton:!0,showLimit:!1});switch("ReportData"!==query.ReportView&&"ReportActivities"!==query.ReportView||($(".listTopPaging",page).html(pagingHtml).trigger("create"),$(".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");query.SortBy===order?"Descending"===query.SortOrder?(query.SortOrder="Ascending",query.SortBy=defaultSortBy):(query.SortOrder="Descending",query.SortBy=order):(query.SortOrder="Ascending",query.SortBy=order),query.StartIndex=0,reloadItems(page)})),$("#GroupStatus",page).hide(),$("#GroupAirDays",page).hide(),$("#GroupEpisodes",page).hide(),query.IncludeItemTypes){case"Series":case"Season":$("#GroupStatus",page).show(),$("#GroupAirDays",page).show();break;case"Episode":$("#GroupStatus",page).show(),$("#GroupAirDays",page).show(),$("#GroupEpisodes",page).show()}$(".viewPanel",page).refresh}function reloadItems(page){loading.show(),query.UserId=Dashboard.getCurrentUserId();var url="";switch(query.ReportView){case"ReportData":query.HasQueryLimit=!0,url=ApiClient.getUrl("Reports/Items",query);break;case"ReportActivities":query.HasQueryLimit=!0,url=ApiClient.getUrl("Reports/Activities",query)}ApiClient.getJSON(url).then(function(result){updateFilterControls(page),renderItems(page,result)}),loading.hide()}function updateFilterControls(page){$(".chkStandardFilter",page).each(function(){var filters=","+(query.Filters||""),filterName=this.getAttribute("data-filter");this.checked=filters.indexOf(","+filterName)!=-1}),$(".chkVideoTypeFilter",page).each(function(){var filters=","+(query.VideoTypes||""),filterName=this.getAttribute("data-filter");this.checked=filters.indexOf(","+filterName)!=-1}),$(".chkStatus",page).each(function(){var filters=","+(query.SeriesStatus||""),filterName=this.getAttribute("data-filter");this.checked=filters.indexOf(","+filterName)!=-1}),$(".chkAirDays",page).each(function(){var filters=","+(query.AirDays||""),filterName=this.getAttribute("data-filter");this.checked=filters.indexOf(","+filterName)!=-1}),$("#chk3D",page).checked(1==query.Is3D),$("#chkHD",page).checked(1==query.IsHD),$("#chkSD",page).checked(0==query.IsHD),$("#chkSubtitle",page).checked(1==query.HasSubtitles),$("#chkTrailer",page).checked(1==query.HasTrailer),$("#chkMissingTrailer",page).checked(0==query.HasTrailer),$("#chkSpecialFeature",page).checked(1==query.HasSpecialFeature),$("#chkThemeSong",page).checked(1==query.HasThemeSong),$("#chkThemeVideo",page).checked(1==query.HasThemeVideo),$("#selectPageSize",page).val(query.Limit),$("#chkMissingRating",page).checked(0==query.HasOfficialRating),$("#chkMissingOverview",page).checked(0==query.HasOverview),$("#chkIsLocked",page).checked(1==query.IsLocked),$("#chkMissingImdbId",page).checked(0==query.HasImdbId),$("#chkMissingTmdbId",page).checked(0==query.HasTmdbId),$("#chkMissingTvdbId",page).checked(0==query.HasTvdbId),$("#chkSpecialEpisode",page).checked(0==query.ParentIndexNumber),$("#chkMissingEpisode",page).checked(1==query.IsMissing),$("#chkFutureEpisode",page).checked(1==query.IsUnaired),$("#selectIncludeItemTypes").val(query.IncludeItemTypes),1==query.IsFavorite?$("#isFavorite").val("true"):0==query.IsFavorite?$("#isFavorite").val("false"):$("#isFavorite").val("-")}function reloadFiltersIfNeeded(page){filtersLoaded||(filtersLoaded=!0,QueryReportFilters.loadFilters(page,Dashboard.getCurrentUserId(),query,function(){reloadItems(page)}),QueryReportColumns.loadColumns(page,Dashboard.getCurrentUserId(),query,function(){reloadItems(page)}))}function renderOptions(page,selector,cssClass,items){var elem;elem=items.length?$(selector,page).show():$(selector,page).hide();var html="";html+='
';var index=0,idPrefix="chk"+selector.substring(1);html+=items.map(function(filter){var itemHtml="",id=idPrefix+index,label=filter,value=filter,checked=!1;return filter.FieldName&&(label=filter.Name,value=filter.FieldName,checked=filter.Visible),itemHtml+='",itemHtml+='