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

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $("#ProcessorType_All").change(function () {
                $('#preferred-office-container').hide();
                $('#preferred-processor-container').hide();
                $("#office-fallback-checkbox-container").hide();

                $("input[name='PreferredTaskProcessor']").each(function () {
                    $(this).removeAttr('checked');
                });

                $("input[name='PreferredTaskProcessorOffice']").each(function () {
                    $(this).removeAttr('checked');
                });
            });

            $("#ProcessorType_Selected").change(function () {
                $('#preferred-office-container').hide();
                $("#office-fallback-checkbox-container").hide();
                $('#preferred-processor-container').show();


                $("input[name='PreferredTaskProcessorOffice']").each(function () {
                    $(this).removeAttr('checked');
                });
            });

            $("#ProcessorType_Office").change(function () {
                $('#preferred-processor-container').hide();
                $("#office-fallback-checkbox-container").show();
                $('#preferred-office-container').show();

                $("input[name='PreferredTaskProcessor']").each(function () {
                    $(this).removeAttr('checked');
                });
            });

            $("input[name=PreferredTaskProcessorOffice]").click(function () {
                var thisProjectSelected = false;
                if ($(this).val() == "-1") thisProjectSelected = $(this).is(":checked");

                $("input[name=PreferredTaskProcessorOffice]").each(function () {
                    if ((thisProjectSelected) && ($(this).val() != "-1")) $(this).removeAttr('checked');
                    else if ((!thisProjectSelected) && ($(this).val() == "-1")) $(this).removeAttr('checked');
                })
            });
        });
    </script>
    <div id="banner-space">
        <div id="banner-detail-container">
            <div class="left-floating-panel">
	            <div id="project-title"><span><%= Html.Encode(Model.CurrentProject.Name) %></span><span id="project-number"><%= Html.Encode(Model.CurrentProject.Number) %></span></div>
                <div id="project-database-export"><b>Last Database Export:</b> <% if (Model.CurrentProject.LastDatabaseExport != null) { %><%= DateTimeHelper.ToString(Model.CurrentProject.LastDatabaseExport.Value) %><% } else { %>No Exports<% } %></div>
	        </div>
            <% if (Model.LicenseType != LicenseType.ODP)
               { %>
                <div class="right-floating-panel total-time-container-outer">
                    <div id="total-time-container">
				        <div class="header">Total Time Saved</div>
			            <div class="value"><%= (Math.Ceiling(Model.CurrentProject.CompletedTasksTime.TotalHours)).ToString("000") %> hrs</div>
                    </div>
                </div> 
            <% } %>
            <% Html.RenderPartial("Partials/LaunchableTasks", new LaunchableTasksModel(Model.CurrentProject, Model.TaskSchedules, Model.CurrentUser)); %>
            <div class="clear"></div>
        </div>
    </div>
    <div id="content-wrap">
        <% Html.RenderPartial("Navigation/_SideNavigation", Model.MenuNavigationModel); %>
	    <div id="content">
	        <h1 class="left-floating-panel">Tasks</h1>
            <div class="right-floating-panel">Server Timezone<br /><b><%= DateTimeHelper.GetTimezoneName() %></b></div>
            <div class="clear"></div>
            <div id="tab-container">
                <ul class="tabs">
			        <li><a href="<%= Url.Action("TaskDashboard/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>">Dashboard</a></li>
			        <li><a href="<%= Url.Action("CurrentTasks/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>">Current Tasks</a></li>
			        <li><a href="<%= Url.Action("CompletedTasks/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>">Completed Tasks</a></li>
                    <% if ((Model.CurrentProject.HasAdministratorAccess(Model.CurrentUser)) || (Model.CurrentProject.HasTaskCoordinatorAccess(Model.CurrentUser)))
                        { %>
                            <li><a href="<%= Url.Action("TaskSchedules/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>">Setup Tasks</a></li>
                    <% } %>
                    <% if (Model.CurrentProject.HasAdministratorAccess(Model.CurrentUser))
                        { %>
                        <li><a href="<%= Url.Action("Authorization/" + Model.CurrentProject.ExternalId,"ProjectTasks") %>">Authorization</a></li>
			            <li><a href="<%= Url.Action("TaskServers/" + Model.CurrentProject.ExternalId,"ProjectTasks") %>" class="active">Task Servers</a></li>
                    <% } %>
			        <li><a href="<%= Url.Action("TaskTimelineOverview/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>" >Timeline</a></li>
			        <li><a href="<%= Url.Action("TaskTimeline/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>" class="line-height-24">Timeline <br /> Detailed</a></li>
                    <% if (Model.CurrentProject.UserHasTaskAccess(Model.CurrentUser))
                    { %>
                        <li><a href="<%= Url.Action("CommonTaskTargets/"+ Model.CurrentProject.ExternalId, "ProjectTasks" ) %>" class="line-height-24">Task <br /> Targets</a></li>
                        <li><a href="<%= Url.Action("MetadataMapping/"+ Model.CurrentProject.ExternalId, "Project" )%>" class="line-height-24" >Metadata <br /> Mapping</a></li>
                    <% } %>
                </ul>
	        </div>
            <br />
            <h2>Preferred Task Servers</h2>
            <% using (Html.BeginForm("TaskServers/" + Model.CurrentProject.ExternalId, "ProjectTasks"))
                { %>
                <table>
                    <tr>
                        <td><input type="radio" id="ProcessorType_All" name="ProcessorType" value="All"<% if (Model.PreferredTaskProcessors.Count == 0) { %> checked="checked"<% } %> /></td>
                        <td style="padding-left:10px;">Use any available task servers</td>
                    </tr>
                    <tr>
                        <td><input type="radio" id="ProcessorType_Selected" name="ProcessorType" value="Selected"<% if (Model.PreferredTaskProcessors.Count > 0) { %> checked="checked"<% } %> /></td>
                        <td style="padding-left:10px;">Use the selected servers</td>
                    </tr>
                    <tr>
                        <td><input type="radio" id="ProcessorType_Office" name="ProcessorType" value="Office"<% if (Model.PreferredTaskProcessorOffices.Count > 0) { %> checked="checked"<% } %> /></td>
                        <td style="padding-left:10px;">Use the selected office servers</td>
                    </tr>
                </table>
                <div id="preferred-processor-container" class="scrolling-container outlined top-margin" style="max-height:300px;<% if (Model.PreferredTaskProcessors.Count == 0) { %>display: none;<% } %>">
                    <% if (Model.TaskProcessors.Count > 0) { %>
                    <table class="standard-list full">
                        <% foreach (TaskProcessor taskProcessor in Model.TaskProcessors) { %>
                            <tr>
                                <td style="width:25px;text-align:center"><input type="checkbox" id="PreferredTaskProcessor_<%= taskProcessor.Id %>" name="PreferredTaskProcessor" value="<%= taskProcessor.Id %>"<% if (Model.IsPreferredTaskServer(taskProcessor)) { %> checked="checked"<% } %> /></td>
                                <td><label for="PreferredTaskProcessor_<%= taskProcessor.Id %>"><b><%= taskProcessor.Server %></b> - <%= taskProcessor.Name %><% if (taskProcessor.IsPaused) { %>&nbsp;-&nbsp;<b>Paused</b><% } %></label></td>
                            </tr>
                        <% } %>
                    </table>
                    <% } else { %>
                        <div>No task servers are available.</div>
                    <% } %>
                </div>
                <div id="preferred-office-container" class="scrolling-container outlined top-margin" style="max-height:300px;<% if (Model.PreferredTaskProcessorOffices.Count == 0) { %>display: none;<% } %>">
                    <table class="standard-list full">
                        <tr>
                            <td style="width:25px;text-align:center"><input type="checkbox" id="PreferredTaskProcessorOffice_local" name="PreferredTaskProcessorOffice" value="-1"<% if (Model.IsPreferredTaskProcessorOffice(null))
                                                                                                           { %> checked="checked"<% } %> /></td>
                            <td><label for="PreferredTaskProcessorOffice_local"><b><%= TextHelper.GetText("This project's office") %></b></label></td>
                        </tr>
                        <% foreach (Office taskProcessorOffice in Model.Offices) { %>
                            <tr>
                                <td style="width:25px;text-align:center"><input type="checkbox" id="PreferredTaskProcessorOffice_<%= taskProcessorOffice.Name.Replace(" ", string.Empty) %>" name="PreferredTaskProcessorOffice" value="<%= taskProcessorOffice.Id %>"<% if (Model.IsPreferredTaskProcessorOffice(taskProcessorOffice.Name))
                                                                                                           { %> checked="checked"<% } %> /></td>
                                <td><label for="PreferredTaskProcessorOffice_<%= taskProcessorOffice.Name.Replace(" ", string.Empty) %>"><b><%= taskProcessorOffice.Name %></b></label></td>
                            </tr>
                        <% } %>
                    </table>
                </div>
                <div id="office-fallback-checkbox-container" class="top-margin" <% if (Model.PreferredTaskProcessorOffices.Count == 0) { %> style="display: none;"<% } %>>
                    <input type="checkbox" id="UseOfficeFallbacks" name="UseOfficeFallbacks" <% if (Model.UseOfficeFallbacks){ %> checked="checked"<% } %> />
                    <label ><b>Use office fallbacks</b></label>
                </div>
                <br />
                <div class="left-floating-panel"><input type="submit" value="Update" class="button" /></div>
                <div class="clear"></div>
            <% } %>
        </div>
    </div>
</asp:Content>
