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

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.DevExpress().RenderScripts(Page,
        new Script { ExtensionSuite = ExtensionSuite.GridView }); %>
    <% Html.DevExpress().RenderStyleSheets(Page,
            new StyleSheet { ExtensionSuite = ExtensionSuite.NavigationAndLayout },
            new StyleSheet { ExtensionSuite = ExtensionSuite.Editors },
            new StyleSheet { ExtensionSuite = ExtensionSuite.HtmlEditor },
            new StyleSheet { ExtensionSuite = ExtensionSuite.GridView }
     ); %>
     <script type="text/javascript">
         function CustomButtonClicked(s, e) {
             var value = s.GetRowKey(e.visibleIndex);

             if (e.buttonID.toLowerCase() == "deletebutton") {
                 document.location = "<%= Url.Action("DeleteTaskSchedule") %>/" + value;
             }
             else if (e.buttonID.toLowerCase() == "editbutton") {
                 var location = "<%= Url.Action("EditTask") %>/" + value;
                 <% if (Model.IsEditInNewWindowOn) { %>
                    window.open(location);
                 <% } else {  %>
                    document.location = location;
                 <% } %>
             }
             else if (e.buttonID.toLowerCase() == "duplicatebutton") {
                 document.location = "<%= Url.Action("DuplicateTask") %>/" + value;
             }
             else if (e.buttonID.toLowerCase() == "runbutton") {
                 document.location = "<%= Url.Action("RunTask") %>/" + value;
             }
         }

         function ContextMenuItemClick(s, e) {

             if (e.htmlEvent && e.htmlEvent.target && e.htmlEvent.target.innerHTML === "Edit") {
                 var value = s.GetRowKey(e.index);

                 $("#task-context-menu").data("task-id", value);

                 $(".custom-menu").finish().toggle(100).css({
                     top: event.pageY + "px",
                     left: event.pageX + "px"
                 });

                 $(document).bind("mousedown", hideContextMenu);
             }
             else {
                 e.showBrowserMenu = true;
             }
         }

         function hideContextMenu(e) {

             // If the clicked element is not the menu
             if (!$(e.target).parents(".custom-menu").length > 0) {

                 // Hide it
                 $(".custom-menu").hide(100);
                 $(document).unbind("mousedown", hideContextMenu);
             }
         }

         function openEditInNewTab() {
             var value = $("#task-context-menu").data("task-id");
             var url = "<%= Url.Action("EditTask") %>/" + value;
             window.open(url, '_blank').focus();

             $(".custom-menu").hide(100);
             $(document).unbind("mousedown", hideContextMenu);
         }

         function enableAll() {
             window.location.href = "<%= Url.Action("EnableAllTaskSchedules/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>";
         }

         function disableAll() {
             window.location.href = "<%= Url.Action("DisableAllTaskSchedules/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>";
         }

         function grid_CustomizationWindowCloseUp(s, e) { }

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

         function DisableCustomizationWindow() {
             if (gvDataBinding.IsCustomizationWindowVisible())
                 gvDataBinding.HideCustomizationWindow();
         }

         $(document).ready(function () {
             $("#btShowCustomizationWindow").click(function () {
                 UpdateCustomizationWindowVisibility();
             });
         });
     </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.HasValue)
                                                                                  { %><%= 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") %>" class="active">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") %>">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 />
            <% if ((Model.AvailableTasks.Count == 0) && (Model.AllTaskSchedules.Count == 0)) { %>
                <div>No Task Types have been registered by a Task Server yet.</div>
            <% } else { %>
                <% if (Model.AvailableTasks.Count > 0) { %>
                    <% if (Model.AllTaskSchedules.Count > 0) { %><div class="left-floating-panel"><input id="btShowCustomizationWindow" type="button" value="Column Select" class="button" /></div><% } %>
                    <div class="right-floating-panel"><input type="button" value="Add a Task" onclick="window.location.href='<%= Url.Action("Select/" + Model.CurrentProject.ExternalId, "ProjectTasks") %>'" class="button" /></div>
                    <div class="right-floating-panel"><input type="button" value="Add a Task Sequence" onclick="window.location.href='<%= Url.Action("NewTask/" + Model.CurrentProject.ExternalId, "ProjectTasks", new { taskType = "task sequence" }) %>'" class="button" /></div>
                    <div class="clear"></div>
                    <br />
                <% } else if (Model.AllTaskSchedules.Count == 0) { %>
                    <div>No Task Types have been registered by a Task Server.</div>
                <% } %>
                <% if (Model.AllTaskSchedules.Count > 0) { %>
                    <div id="GridViewContainer"><% Html.RenderPartial("Partials/TaskSchedules", Model.GetTaskSchedulesPartialViewModel()); %></div>
                    <br />
                    <div class="right-floating-panel"><input type="button" value="Enable All" class="button" onclick="enableAll()" /></div>
                    <div class="right-floating-panel"><input type="button" value="Disable All" class="button" onclick="disableAll()" /></div>
                    <div class="clear"></div>
                <% }
                    else
                    { %>
                    <div>Click &quot;Add a Task&nbsp to create your first task.</div>
                <% } %>
            <% } %>
        </div>
    </div>
    <ul id="task-context-menu" class='custom-menu'>
      <li onclick="openEditInNewTab()">
          <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-up-right" viewBox="0 0 16 16">
              <path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5z"/>
              <path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0v-5z"/>
           </svg>
          <span>Open in new tab</span>
      </li>
    </ul>
    <script type="text/javascript">
        window.onunload = function () {
            var cookie = getCookieValue("ClarityScheduledProjectTasksView");
        
            if (typeof (cookie) !== 'undefined') {
                var date = new Date();
                date.setTime(date.getTime() + (10 * 60 * 1000 * 52560));

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