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

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <% Html.DevExpress().RenderScripts(Page, new Script { ExtensionSuite = ExtensionSuite.Editors }); %>
    <% Html.DevExpress().RenderStyleSheets(Page, new StyleSheet { ExtensionSuite = ExtensionSuite.Editors, Theme = "Youthful" }); %>
    <script language="javascript" type="text/javascript">

        function SwitchLinkLoad(linkId, projectId, projectFolder) {
            var link = document.getElementById(linkId);
            var linkLocation = link.href.split("?")[0];
            var linkPartitions = linkLocation.split("/");

            if (linkPartitions.length > 0) {
                var linkAction = linkPartitions[linkPartitions.length - 1];

                switch (linkAction.toLowerCase()) {
                    case "loadartifactfoldercontents":
                        var newLink = "";

                        for (var i = 0; i < linkPartitions.length - 1; i++) {
                            newLink += linkPartitions[i] + "/";
                        }

                        newLink += "CloseFolderContents?projectId=" + projectId + "&projectFolder=" + encodeURIComponent(projectFolder);
                        link.href = newLink;
                        break;
                    case "closefoldercontents":
                        var newLink = "";

                        for (var i = 0; i < linkPartitions.length - 1; i++) {
                            newLink += linkPartitions[i] + "/";
                        }

                        newLink += "LoadArtifactFolderContents?projectId=" + projectId + "&projectFolder=" + encodeURIComponent(projectFolder);
                        link.href = newLink;
                        break;
                }
            }
        }

        function selectFolderForUpload(folderPath) {
            $("#uploadPath").val(folderPath);
            document.querySelector('#uploadFile').click();
        }

        function loadProjectDetail() {
            <% if (ProjectTypeHelper.GetIsRevitServerProject(Model.CurrentProject.RevitServerVersion)) { %>
                var getURL = '<%= Url.Action("ProjectArtifactsHeader", "RevitServer") %>';
            <% } else { %>
                var getURL = '<%= Url.Action("ProjectArtifactsHeader", Model.CurrentProject.RevitServerVersion) %>';
            <% } %>

            $.ajax({
                type: 'GET',
                url: getURL,
                data: {
                    projectId: '<%= Model.CurrentProject.ExternalId %>'
                },
                cache: false,
                success: function (response) {
                    $('#project-detail-container').html(response);
                    $("#content").show();
                },
                error: function() {
                    $("#content").show();
                }
            });
        }

        window.onload = function () {
            loadProjectDetail();
        };
    </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" style="display:none;">
            <div id="project-detail-container"></div>
            <br />
            <% using(Html.BeginForm("ArtifactUpload/" + Model.CurrentProject.ExternalId, "Project", FormMethod.Post, new { @id="artifact-file-upload", @enctype="multipart/form-data" })) { %>
                <input type="hidden" id="uploadPath" name="uploadPath" />
                <input type="file" id="uploadFile" name="uploadFile" onchange="$('#artifact-file-upload').submit();" style="display:none" />
            <% } %>
            <div class="filebrowser-panel">
                <div class="none-float-panel" onmouseover="$('#upload-artifact-root').show();" onmouseout="$('#upload-artifact-root').hide();">
                    <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td style="width:23px"><img src="<%= Request.ApplicationPath.TrimEnd(new char[] { '/' }) %>/Images/Icons/FolderIcon.jpg" alt="Folder" /></td>
                            <td><span class="file-panel-folder"><%= Ajax.ActionLink(Model.CurrentProject.Name, "LoadArtifactFolderContents", new { projectId = Model.CurrentProject.ExternalId, projectFolder = string.Empty }, new AjaxOptions { UpdateTargetId = "root_folder", InsertionMode = InsertionMode.Replace })%></span></td>
                            <td style="width:15px"><img id="upload-artifact-root" src="<%= Request.ApplicationPath.TrimEnd(new char[] { '/' }) %>/Images/Icons/upload.png" alt="Folder" class="upload-icon" onclick="selectFolderForUpload('')" /></td>
                        </tr>
                    </table>
                </div>
                <hr />
                <div id="root_folder" class="none-float-panel" style="padding-left:8px"><% Html.RenderPartial("Partials/ArtifactList", Model.GenerateArtifactFolderModel());%></div>
            </div>
        </div>
    </div>
</asp:Content>