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

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" runat="server">
    <script language="javascript" type="text/javascript">
        function loadBrowseWindow() {
            $.ajax({
                type: 'GET',
                url: '<%= Url.Action("GetBrowseFolders", "Project") %>',
                data: {
                    targetInput: "ArchiveLocation",
                    workingDirectory: $("#ArchiveLocation").val()
                },
                cache: false,
                success: function (response) {
                    $("#modal-overlay").html(response);
                },
                complete: function () {
                    showModelDialog();
                }
            });
        }
    </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"><%= TextHelper.GetText("Archive Project") %></h1>
            <div class="right-floating-panel"><%= Html.ActionLink("Back", "Archive/" + Model.CurrentProject.ExternalId, "Project", null, new { @class="button" })%></div>
            <div class="clear"></div>
            <% if ((Model.CurrentProject.DatabaseReady) || ((Model.CurrentProject.DateCreated != null) && ((DateTime.Now - ((DateTime)Model.CurrentProject.DateCreated)).TotalMinutes > 10)))
                { %>
                <div>
                    <p><%= TextHelper.GetText("Archiving makes a complete backup of your Clarity project, including") %>:</p>
                    <ul>
                        <li><%= TextHelper.GetText("Project Database") %></li>
                        <li>Tasks, File Filters</li>
                        <li>Datasheet and Report Templates</li>
                        <li><%= TextHelper.GetText("Project Artifacts") %></li>
                        <li><%= TextHelper.GetText("Optionally, Revit models via project backups") %></li>
                    </ul>
                    <p>The archive file can be restored in the future.</p>
                    <p>NOTE: The selected output location must have write access for both the App Pool User (<%= System.Security.Principal.WindowsIdentity.GetCurrent().Name %>) and the SQL Server User.</p>
                </div>
                <% using(Html.BeginForm("CreateArchive/" + Model.CurrentProject.ExternalId, "Project")) 
                    { %>
                    <table>
                        <tr>
                            <td align="left" style="width:130px;">Output Location:</td>
                            <td align="left"><%= Html.TextBox("ArchiveLocation", Model.ArchiveLocation, new { @class="standard-textbox" })%></td>
                            <td align="left"><input type="button" value="Browse..." onclick="loadBrowseWindow()" class="browse" /></td>
                        </tr>
                        <tr>
                            <td align="left" style="width:130px;">Archive Backups:</td>
                            <td align="left">
                                <select name="ArchiveBackups">
                                    <option value="-1" selected="selected">All</option>
                                    <option value="5">Last 5</option>
                                    <option value="3">Last 3</option>
                                    <option value="1">Last 1</option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td align="left" style="width:130px;">Archive Artifacts:</td>
                            <td align="left"><input type="checkbox" name="ArchiveArtifacts" value="true" checked="checked" /></td>
                        </tr>
                    </table>
                    <br />
                    <% if (Model.ProjectBackups.Count > 0)
                       { %>
                        <div>There are currently <%= Model.ProjectBackups.Count %> <%= TextHelper.GetText("backups for the project. The latest created at") %> <%= Model.ProjectBackups.First().DateCreated.ToString("dd MMM yyyy hh:mm tt") %>.</div>
                    <% }
                       else
                       { %>
                        <div class="validation-error-content"><%= TextHelper.GetText("There are currently NO BACKUPS FOR THIS PROJECT. No Models will be backed up.") %></div>
                    <% } %>
                    <br />
                    <div><input type="submit" value="Archive Project" class="button" /></div>
                <% } %>
            <% } else { %>
                <div><%= TextHelper.GetText("The project database is currently unavailable and therefore the project cannot be deleted, please try again in several minutes") %></div>
            <% } %>
        </div>
    </div>
</asp:Content>
