<%@ page language="C#" autoeventwireup="true" masterpagefile="~/MasterFile/TimeCheck.master" inherits="Organization_Settings_Organization_Levels, App_Web_zwx4uwl3" %>

<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="dxe" %>
<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<asp:Content ContentPlaceHolderID="BodyContentPH" runat="server">

    <script type="text/javascript">
        var MaxLength = "Maximum length is ";
        function MaxLengthh(maxLength) {
            MaxLength = maxLength;
        }
        function Delete_Conf() {
            //Alert_AreyousuretoDelete
            return confirm('Are you sure to Delete ?');
        }
    </script>

    <div class="content-header">
        <h1 style="background-image: url('../dist/img/org-icon.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lblTitle" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div class="emp-filter">
            <div class="form-horizontal">
                <div class="row">
                    <div class="col-md-12">
                        <div class="row">
                            <div class="col-md-12" style="overflow: auto; overflow-y: hidden; padding-bottom: 15px">
                                <asp:HiddenField ID="hdnSelectRow" runat="server" />
                                <asp:HiddenField ID="hdnGetAllid" runat="server" />
                                <dxGridview:ASPxGridView ID="grvLevel" EnableCallBacks="false" runat="server" ClientInstanceName="grvLevel"
                                    OnHtmlRowCreated="grvLevel_HtmlRowCreated" AutoGenerateColumns="false" Width="100%"
                                    DataSourceID="ObjectDataSource1" KeyFieldName="levelID">
                                    <Columns>
                                        <dxGridview:GridViewDataColumn VisibleIndex="0" Width="34px" HeaderStyle-VerticalAlign="Middle"
                                            HeaderStyle-HorizontalAlign="Center" CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center">
                                            <Settings AllowAutoFilter="False" />
                                            <HeaderTemplate>
                                                <input id="chkSelectAll" runat="server" type="checkbox" onclick="SelectAllOnThisPage(this)" />
                                            </HeaderTemplate>
                                            <DataItemTemplate>
                                                <input id="chkSelect" runat="server" type="checkbox" onclick="SelectOnRow(this)"
                                                    disabled='<%#DataBinder.Eval(Container.DataItem,"flag").ToString()=="0" %>' accesskey='<%# Eval("levelID") %>' />
                                            </DataItemTemplate>
                                            <EditItemTemplate>
                                                <input id="chkSelect" runat="server" type="checkbox" onclick="SelectOnRow(this)"
                                                    disabled='<%#DataBinder.Eval(Container.DataItem,"flag").ToString()=="0" %>' accesskey='<%# Eval("levelID") %>' />
                                            </EditItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" ForeColor="White" Wrap="True" BackColor="#5172AD" />
                                        </dxGridview:GridViewDataColumn>
                                        <dxGridview:GridViewDataTextColumn FieldName="levelId" Caption="Level Id" VisibleIndex="1"
                                            Width="34px" Visible="False">
                                            <DataItemTemplate>
                                                &nbsp;&nbsp;
                                                <asp:Label ID="lblleveId" Text='<%# Eval("levelID") %>' runat="server">
                                                </asp:Label>
                                            </DataItemTemplate>
                                            <EditItemTemplate>
                                                <asp:Label ID="lblleveId" Text='<%# Bind("levelID") %>' runat="server">
                                                </asp:Label>
                                            </EditItemTemplate>
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewDataTextColumn Caption="Level Name" FieldName="levelName" VisibleIndex="1"
                                            Width="480px">
                                            <PropertiesTextEdit MaxLength="50">
                                                <ValidationSettings ErrorDisplayMode="Text" ErrorTextPosition="Bottom" ValidateOnLeave="true"
                                                    EnableCustomValidation="true" SetFocusOnError="true">
                                                    <RequiredField IsRequired="True" ErrorText="Please Enter the Level Name" />
                                                    <ErrorFrameStyle Wrap="True" Font-Size="Smaller">
                                                    </ErrorFrameStyle>
                                                    <RegularExpression ValidationExpression="([a-z]|[A-Z]|[ ]|[-]|[_])*" ErrorText="Special Characters/Numbers are not Allowed" />
                                                </ValidationSettings>
                                            </PropertiesTextEdit>
                                            <DataItemTemplate>

                                                <asp:Label ID="lblLevelName" Text='<%# Eval("levelName") %>' CssClass="OrganizationLevel"
                                                    runat="server"></asp:Label>

                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" ForeColor="black" Wrap="True" BackColor="#5172AD" />
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewDataTextColumn Visible="False" FieldName="parentLevelID" VisibleIndex="3"
                                            Width="80px">
                                            <DataItemTemplate>
                                                <asp:Label ID="lblparentLevelId" Text='<%# Eval("parentLevelID") %>' runat="server">
                                                </asp:Label>
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="Center" Wrap="True" BackColor="#5172AD" />
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewCommandColumn VisibleIndex="2" Width="60px" Caption="Edit">
                                            <EditButton Visible="True">
                                            </EditButton>
                                            <HeaderStyle HorizontalAlign="Center" Wrap="True" BackColor="#5172AD" />
                                        </dxGridview:GridViewCommandColumn>
                                        <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                            CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="32px">
                                            <Settings AllowAutoFilter="false" />
                                            <DataItemTemplate>
                                                <a href="Organization_LevelDetails.aspx?tid=<%# Eval("levelID") %>&sid=<%=Session.SessionID %>"
                                                    title='<%# Session["View"] %>' data-placement="top" data-toggle="tooltip"><span class="btn btn-defalut view-icons"></span></a>
                                            </DataItemTemplate>
                                            <EditItemTemplate>
                                                <label>
                                                </label>
                                            </EditItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataColumn>
                                        <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                            CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="32px">
                                            <Settings AllowAutoFilter="false" />
                                            <DataItemTemplate>
                                                <asp:LinkButton ID="btnDelete" runat="server" ToolTip='<%# Session["Delete"] %>' data-toggle="tooltip"
                                                    OnClick="btn_delete_Click_1" CommandName='<%# Eval("levelID") %>' data-placement="top"
                                                    CssClass="btn btn-defalut del-icons" Style="color: Red" OnClientClick="return Delete_Conf();"
                                                    Visible='<%# DataBinder.Eval(Container.DataItem,"flag").ToString()=="1"%>'></asp:LinkButton>
                                            </DataItemTemplate>
                                            <EditItemTemplate>
                                                <label>
                                                </label>
                                            </EditItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataColumn>
                                    </Columns>
                                    <SettingsEditing Mode="Inline" />
                                    <Settings ShowFilterRow="True" />
                                    <SettingsBehavior SortMode="Value" />
                                    <%-- <StylesEditors>
                                        <Style HorizontalAlign="Left"></Style>
                                    </StylesEditors>--%>
                                    <SettingsText EmptyDataRow="No Records Found" />
                                    <Styles AlternatingRow-CssClass="table-bg">
                                    </Styles>
                                </dxGridview:ASPxGridView>
                                <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="selectLevels"
                                    TypeName="levelsEventData" UpdateMethod="updateLevel">
                                    <UpdateParameters>
                                        <asp:Parameter Name="opr" DefaultValue="I" Type="String" />
                                        <asp:Parameter Name="levelId" Type="Int32" />
                                        <asp:Parameter Name="levelName" Type="String" />
                                        <asp:SessionParameter Name="emp_id" SessionField="EmpAutoID" />
                                    </UpdateParameters>
                                </asp:ObjectDataSource>
                            </div>
                        </div>
                        <div class="row form-group" style="padding-top: 10px">
                            <div class="col-md-12">
                                <div class="pull-right-button">
                                    <asp:LinkButton ID="butAdd" CssClass="btn add-btn fa-plus" runat="server" OnClick="butAdd_Click" />
                                    <asp:LinkButton ID="btn_Delete" CssClass="btn add-btn fa-trash-o" runat="server"
                                        CausesValidation="False" OnClick="btn_Delete_Click" OnClientClick="return confirmdelete(this.form);"
                                        Visible="false" />
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="callout callout-info" style="margin-bottom: 0!important;">
                                    <asp:Label ID="lblImportNote" runat="server"></asp:Label>
                                </div>
                                <br />
                                <ul>
                                    <li>
                                        <asp:Label ID="lblnotes1" runat="server" Text="If you want to create any other sub - level under last category, click the edit button"></asp:Label>
                                        <span class="btn btn-defalut view-icons"></span>
                                        <asp:Label ID="Label2" runat="server" Text="  of corresponding category it will redirect to sub - level creation page."></asp:Label>
                                    </li>
                                    <li>
                                        <asp:Label ID="Label1" runat="server" Text="Otherwise, If you want to create different hierarchy instead of above hierarchy, delete the above hierarchy in above list first (one by one), then click the add button."></asp:Label></li>
                                    <li>
                                        <asp:Label ID="Label3" runat="server" Text="Once the first level is created, then click the edit button for creating the sub-levels. Dont <b>click add button for creating the sub-levels.</b>"></asp:Label></li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript" language="javascript">
        function SelectAllOnThisPage(chkSelectAll) {

            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
            var hdnSelectAll = document.getElementById('<%= hdnGetAllid.ClientID %>');
            if (chkSelectAll.checked == true) {
                for (var i = 0; i < grvLevel.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').accessKey;
                        var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
                        var removeId = hdnSelectRow.value.split(",");
                        if (hdnUserId != "" && !Array.contains(removeId, hdnUserId)) {
                            if (hdnSelectRow.value != "")
                                hdnSelectRow.value += ",";
                            hdnSelectRow.value += hdnUserId;
                        }
                    }
                }
            }
            else {
                for (var i = 0; i < grvLevel.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').checked = false;
                }
                hdnSelectRow.value = '';
            }
        }


        function SelectOnRow(chkOnSelect) {

            var hdnUserId = chkOnSelect.accessKey;
            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
            var removeId = hdnSelectRow.value.split(",");

            if (chkOnSelect.checked) {
                if (hdnUserId != "" && !Array.contains(removeId, hdnUserId)) {
                    if (hdnSelectRow.value != "")
                        hdnSelectRow.value += ",";
                    hdnSelectRow.value += hdnUserId;
                }

                var varTotalCheckedCount = 0;
                for (var i = 0; i < grvLevel.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').checked)
                        varTotalCheckedCount = varTotalCheckedCount + 1;
                    else
                        break;
                }
                if (varTotalCheckedCount == grvLevel.pageRowCount)
                    document.getElementById('ctl00_BodyContentPH_grvLevel_header0_chkSelectAll').checked = true;
                else
                    document.getElementById('ctl00_BodyContentPH_grvLevel_header0_chkSelectAll').checked = false;
            }
            else {
                if (Array.contains(removeId, hdnUserId)) {
                    Array.remove(removeId, hdnUserId);
                }
                hdnSelectRow.value = removeId;

                document.getElementById('ctl00_BodyContentPH_grvLevel_header0_chkSelectAll').checked = false;
            }
        }
    </script>

</asp:Content>
