<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Task.Master" Inherits="System.Web.Mvc.ViewPage<AdministratorConsole.Models.TaskController.CompletedViewModel>" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.DevExpress().RenderScripts(Page,
        new Script { ExtensionSuite = ExtensionSuite.GridView },
        new Script { ExtensionSuite = ExtensionSuite.Editors }); %>
    <% Html.DevExpress().RenderStyleSheets(Page,
            new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
            new StyleSheet { ExtensionSuite = ExtensionSuite.GridView } ); %>
    <script type="text/javascript">
        function viewCompletedTasks() {
            var startDate = StartDate.GetText(),
                endDate = EndDate.GetText();
            
            window.location.href = "<%= Url.Action("Completed", "Task") %>?startDate=" + startDate + "&endDate=" + endDate;
        }

        $(document).ready(function () {
            $("#btShowCustomizationWindow").click(function () {
                UpdateCustomizationWindowVisibility();
            });
        });

        function grid_CustomizationWindowCloseUp(s, e) { }

        function UpdateCustomizationWindowVisibility() {
            if (gvDataBinding.IsCustomizationWindowVisible()) gvDataBinding.HideCustomizationWindow();
            else gvDataBinding.ShowCustomizationWindow();
        }

        function DisableCustomizationWindow() {
            if (gvDataBinding.IsCustomizationWindowVisible()) gvDataBinding.HideCustomizationWindow();
        }
    </script>
    <div id="content-wrap">
        <% Html.RenderPartial("Navigation/_SideNavigation", Model.MenuNavigationModel); %>
        <div id="content">
		    <h1 class="left-floating-panel">Completed Tasks</h1>
            <div class="right-floating-panel">Server Timezone<br /><b><%= DateTimeHelper.GetTimezoneName() %></b></div>
            <div class="clear"></div>
            <table>
                <tr>
                    <td class="small-right-padded"><%= Html.Encode("Start Date: ") %>
                    <td><% Html.DevExpress().DateEdit(settings =>
                                                    {
                                                        settings.Name = "StartDate";
                                                        settings.Properties.NullText = "MM/dd/yyyy";
                                                        settings.Properties.EditFormat = EditFormat.Custom;
                                                        settings.Properties.EditFormatString = "MM/dd/yyyy";
                                                        settings.Properties.AllowNull = false;
                                                        settings.Properties.ValidationSettings.CausesValidation = false;
                                                        settings.Properties.ValidationSettings.ValidateOnLeave = false;
                                                        settings.Date = Model.StartDate;
                                                    }).GetHtml(); %></td>
                    <td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
                    <td class="small-right-padded"><%= Html.Encode("End Date: ") %></td>
                    <td><% Html.DevExpress().DateEdit(settings =>
                                                    {
                                                        settings.Name = "EndDate";
                                                        settings.Properties.NullText = "MM/dd/yyyy";
                                                        settings.Properties.EditFormat = EditFormat.Custom;
                                                        settings.Properties.EditFormatString = "MM/dd/yyyy";
                                                        settings.Properties.AllowNull = false;
                                                        settings.Properties.ValidationSettings.CausesValidation = false;
                                                        settings.Properties.ValidationSettings.ValidateOnLeave = false;
                                                        settings.Date = Model.EndDate;
                                                    }).GetHtml(); %></td>
                    <td>&nbsp;&nbsp;</td>
                    <td><input type="button" value="Update" class="button" onclick="viewCompletedTasks()" /></td>
                </tr>
            </table>
            <br />
            <% if (Model.Tasks.Count > 0) { %>
                <div class="left-floating-panel"><input id="btShowCustomizationWindow" type="button" value="Column Select" class="button" /></div>
                <div class="expand-icon-button"><img src="<%= Request.ApplicationPath.TrimEnd(new char[] { '/' }) %>/Images/Icons/expand.png" title="Full Screen" onclick="fullscreenDiv('GridViewContainer');" /></div>
                <div class="clear"></div>
                <div id="GridViewContainer" class="reportPanel-scrollingbody" style="min-height:200px;"><% Html.RenderPartial("Partials/CompletedTasks", Model.GetCompletedTasksGridViewModel()); %></div>
                <div class="left-floating-panel"><input type="button" value="Purge Errored" onclick="window.location='<%: Url.Action("PurgeCompleted", "Task") %>'" class="button" /></div>
                <div class="left-floating-panel"><input type="button" value="Export" class="button" onclick="window.location = '<%: Url.Action("ExportCompletedTasksToXLS", "Task", new { startDate = Model.StartDate.ToString("MM#dd#yyyy"), endDate = Model.EndDate.ToString("MM#dd#yyyy") }) %>'" /></div>
            <% } else { %>
                <div>No Completed Tasks</div>
                <br />
            <% } %>
            <div class="right-floating-panel"><input type="button" value="Refresh" onclick="window.location='<%: Url.Action("Completed", "Task") %>'" class="button" /></div>
            <div class="clear"></div>
        </div>
    </div>
    <script type="text/javascript">
        window.onunload = function () {
            var cookie = getCookieValue("ClarityCompletedTasksView");
        
            if (typeof (cookie) !== 'undefined') {
                var date = new Date();
                //expires next year
                date.setTime(date.getTime() + (10 * 60 * 1000 * 52560));

                ASPxClientUtils.SetCookie("ClarityCompletedTasksView", cookie, date);
            }
        }
    </script>
</asp:Content>
