@model IEnumerable<NzbDrone.Web.Models.MissingEpisodeModel>
@using DataTables.Mvc.Core
@using NzbDrone.Web.Helpers
@using SortDirection = DataTables.Mvc.Core.Enum.SortDirection
@{ViewBag.Title = "Missing";}

@section ActionMenu{
    <ul class="sub-menu">
        <li>@Ajax.ActionLink("Start RSS Sync", "RssSync", "Command", null, null, new { Title = "Check for newly released downloads" })</li>
        <li>@Ajax.ActionLink("Start Backlog Search", "BacklogSearch", "Command",null, null, new { title = "Search and download all missing episodes"})</li>
        <li>@Ajax.ActionLink("Start Recent Backlog Search", "RecentBacklogSearch", "Command", null, null, new { title = "Search and download missing episodes that aired in the last 30 days" })</li>
        <li>@Ajax.ActionLink("Force Past Week Backlog Search", "PastWeekBacklogSearch", "Command", null, null, new { title = "Search and download missing episodes that aired in the last 7 days (Ignores backlog search settings)" })</li>
    </ul>
}

@Html.GridHtml("missingGrid", "dataTablesGrid")   

@section Scripts
{
    @( Html.GridScriptForModel("#missingGrid")
               .Paginate(true)
               .PageLength(20)
               .ChangePageLength(false)
               .Filter(true)
               .Sort(true)
               .PaginationType("four_button")
               .AddColumn(new Column().DataProperty("return seriesTitle(source, type, val);", true).Title("Series Title"))
               .AddColumn(new Column().DataProperty("EpisodeNumbering").Width("80px").Sortable(false).Title("Episode"))
               .AddColumn(new Column().DataProperty("EpisodeTitle").Sortable(false).Title("Episode Title"))
               .AddColumn(new Column().DataProperty("return airDate(source, type, val);", true).Width("150px").Title("Air Date"))
               .AddColumn(new Column().DataProperty("EpisodeId").Width("40px").Sortable(false).RenderFunction("return actions(row);"))
               .AddColumn(new Column().DataProperty("Details").Sortable(false).Visible(false).RenderFunction("return details(row);"))
               .AddSorting(3, SortDirection.Desc)
               .Language(new Language().EmptyTable("No missing episodes found").ZeroRecords("No missing episodes match the filter"))
    )

    <script type="text/javascript">
        
        
        function seriesTitle (source, type, val) {
            // 'display' and 'filter' use our fancy naming
            if (type === 'display' || type === 'filter') {
                return "<a href='/series/details/" + source["SeriesId"] + "'>" + source["SeriesTitle"] + "</a>";
            }
            // 'sort' and 'type' both just use the raw data
            return source["SeriesTitleSorter"];
        }
        
        function airDate (source, type, val) {
            // 'display' and 'filter' use our fancy naming
            if (type === 'display' || type === 'filter') {
                return source["AirDate"];
            }
            // 'sort' and 'type' both just use the raw data
            return source["AirDateSorter"];
        }
        
        function actions(row) {
            var link = '@Ajax.IconActionLink("icon-search gridAction", "", "Search", "Episode", new { EpisodeId = "REPLACE" }, null, new { title = "Search for episode" })';
            link = link.replace("REPLACE", row.aData["EpisodeId"]);
            return link;
        }
        
        function details (row) {
            var result = "<b>Overview: </b>" + row.aData["Overview"] + "<br/>";
            return result;
        }
    </script>
}