<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Client/ClientMaster.master" CodeBehind="EditTraining.aspx.vb" Inherits="Web.EditTraining" %>
<%@ MasterType VirtualPath="ClientMaster.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="phContent" runat="server">

    <div class="container">
        <h1><%= If(trainingId, "Edit Training", "Add Training") %></h1>


        <ul id="tabList" class="nav nav-tabs">
            <li class="nav-item">
                <a class="nav-link active" href="#general" data-toggle="tab">General Information</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="#docs" data-toggle="tab">Documents</a>
            </li>
        </ul>

        <div class="tab-content bg-white border border-top-0 p-3 mb-3">

            <!-- General information tab -->
            <div id="general" class="tab-pane show active">
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="ddlDriver" Text="Driver" />
                    <asp:DropDownList ID="ddlDriver" runat="server" CssClass="form-control" />
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="ddlDriver"
                        Text="required" Display="Dynamic" CssClass="text-danger" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtDriverName" Text="Employee Name" />
                    <asp:TextBox ID="txtDriverName" runat="server" MaxLength="250" CssClass="form-control" />
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="txtDriverName"
                        Text="required" Display="Dynamic" CssClass="text-danger" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="ddlTopic" Text="Training Topic" />
                    <asp:DropDownList ID="ddlTopic" runat="server" CssClass="form-control" />
                    <asp:RequiredFieldValidator runat="server" ControlToValidate="ddlTopic"
                        Text="required" Display="Dynamic" CssClass="text-danger" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtSpecificTopic" Text="Specific Topic" />
                    <asp:TextBox ID="txtSpecificTopic" runat="server" MaxLength="250" CssClass="form-control" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtDate" Text="Training Date" />
                    <asp:TextBox ID="txtDate" runat="server" TextMode="Date" CssClass="form-control" />
                </div>
                <div class="form-group">
                    <asp:CheckBox ID="chkExpires" runat="server" CssClass="mr-1" />
                    <asp:Label runat="server" AssociatedControlID="chkExpires" Text="Expires" CssClass="mr-1" />
                    <asp:TextBox ID="txtExpires" runat="server" TextMode="Date" CssClass="form-control" />
                </div>
                <div class="form-group">
                    <asp:CheckBox ID="chkQuiz" runat="server" Text="Training Quiz: " />
                    <asp:TextBox ID="txtQuiz" runat="server" TextMode="Date" CssClass="form-control" />
                </div>
                <div class="form-group">
                    <asp:Label runat="server" AssociatedControlID="txtNotes" Text="Notes" />
                    <asp:TextBox ID="txtNotes" runat="server" TextMode="MultiLine" MaxLength="1000" CssClass="form-control" />
                </div>
                <script>
                    $(document).ready(function () {
                        var chkExpires = $('#<%= chkExpires.ClientID %>');
                        var txtExpires = $('#<%= txtExpires.ClientID %>');
                        chkExpires.change(function () {
                            txtExpires.prop('disabled', !chkExpires.prop('checked'));
                        });
                        var chkQuiz = $('#<%= chkQuiz.ClientID %>');
                        var txtQuiz = $('#<%= txtQuiz.ClientID %>');
                        chkQuiz.change(function () {
                            txtQuiz.prop('disabled', !chkQuiz.prop('checked'));
                        });
                    });
                </script>
            </div>

            <!-- Documents tab -->
            <div id="docs" class="tab-pane">
                <div class="table-responsive">
                    <asp:GridView ID="gvDocs" runat="server" DataSourceID="dsDocs" AutoGenerateColumns="false" AllowSorting="true"
                        CssClass="table clickable-rows table-hover floating-hscroll" CellSpacing="-1" GridLines="None" data-fixed-columns="true" data-fixed-number="2">
                        <HeaderStyle CssClass="thead-light" />
                        <Columns>
                            <asp:BoundField HeaderText="Document Type" SortExpression="DocSubCategory" DataField="DocSubCategory" />
                            <asp:BoundField HeaderText="File name" SortExpression="DocName" DataField="DocName" />
                            <asp:BoundField HeaderText="Date" SortExpression="EnteredDate" DataField="EnteredDate" DataFormatString="{0:d}" />
                            <asp:HyperLinkField DataNavigateUrlFields="ContractID,ID,Ctx,ItemID" DataNavigateUrlFormatString="DocumentEdit.aspx?cid={0}&docid={1}&ctx={2}&id={3}" Text="Edit" />
                            <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="/_assets/Document.aspx?context=DocumentNew&id={0}" Target="_blank" Text="view" />
                        </Columns>
                        <EmptyDataTemplate>
                            <p>There are no note entries.</p>
                        </EmptyDataTemplate>
                    </asp:GridView>
                    <asp:SqlDataSource ID="dsDocs" runat="server"
                        SelectCommand ="
                            SELECT DocumentsNew.ContractID,ISNULL(DocumentsNew.ItemID,0) AS ItemID,'TrainingEdit' as Ctx,DocumentsNew.ID,DocumentsNew.DocName,DocumentsNew.EnteredDate,ISNULL(DocumentsSubCategory.Name,'') AS DocSubCategory,DocumentsNew.UploadNotes
                            FROM DocumentsNew LEFT JOIN DocumentsSubCategory ON DocumentsNew.SubCategoryID=DocumentsSubCategory.Id
                            WHERE DocumentsNew.ItemID=@ItemId AND DocumentsNew.CategoryID=@CatID AND (ISNULL(DocumentsNew.Deleted,0) = 0) ORDER BY ISNULL(DocumentsSubCategory.Name,''),DocumentsNew.DocName,DocumentsNew.ID">
                        <SelectParameters>
                            <asp:Parameter Name="CatID" />
                            <asp:Parameter Name="ItemId" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </div>
            </div>

        </div>


        <div class="row">
            <div class="col">
                <asp:Button ID="btnCancel" runat="server" CssClass="btn btn-secondary" Text="Cancel" CausesValidation="false" />
            </div>
            <div class="col text-right">
                <asp:Button ID="btnDownloadAll" runat="server" CssClass="btn btn-primary" Text="Download All" CausesValidation="false" Width="150px" />
                <asp:Button ID="btnUploadDoc" runat="server" CssClass="btn btn-primary" Text="Upload Document"  CausesValidation="false" Width="150px" />
                <asp:Button ID="btnSave" runat="server" CssClass="btn btn-primary" Text="Save" Width="150px" />
            </div>
        </div>

    </div>

</asp:Content>
