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

<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="dxe" %>
<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<%@ Register Src="../UserControls/TA_uc_Levels.ascx" TagName="TA_uc_Levels" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="server">

    <script type="text/javascript">
        function navi(loc) {
            document.getElementById('ctl00_BodyContentPH_iframePopup').src = loc;
            return false;
        }
        function Delete_Conf() {
            //Alert_AreyousuretoDelete
            return confirm('Are you sure to Delete ?');
        }
    </script>

    <script language="javascript" src="../js/jquery.autocomplete.js" type="text/javascript"></script>

    <script type="text/javascript" src="../bootstrap/js/1.4.3/jquery.min.js"></script>



    <div class="content-header">
        <%--<h1 style="background-image: url('../dist/img/org-icon.png'); background-repeat: no-repeat;
            padding-left: 35px">--%>
        <h1 style="background-image: url('../dist/img/org-icon.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lblHead" runat="server" Text="Organization Levels"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div id="myModal" class="modal modal-default fade" role="dialog">
            <div class="modal-dialog" style="width: 90%;">
                <!-- Modal content-->
                <div class="modal-content" style="margin-top: 50px">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" style="border-radius: 50px;">
                            &times;</button>
                        <h4 class="modal-title">
                            <asp:Label ID="lblHead2" ToolTip="test" runat="server"></asp:Label>
                        </h4>
                    </div>
                    <div class="modal-body">
                        <iframe id="iframePopup" runat="server" scrolling="auto" width="100%" height="400px"
                            style="border-style: none"></iframe>
                    </div>
                    <div class="modal-footer" style="display: none">
                        <button type="button" class="btn btn-primary pull-right" data-dismiss="modal">
                            Close</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="inr-ftr">
            <div class="row">
                <div class="col-sm-2">
                    <div class="inr-fil-text">
                        <asp:Label ID="lblFilter" runat="server" Text="Filter"></asp:Label>
                    </div>
                </div>
                <div class="clearfix">
                </div>
            </div>
        </div>
        <div class="form-horizontal">
            <div class="emp-filter">
                <div id="divFilter" runat="server">
                    <div class="row form-group">
                        <div class="col-md-12">
                            <uc1:TA_uc_Levels ID="TA_uc_Levels1" runat="server" />
                        </div>
                    </div>
                    <div class="row " runat="server" id="btnDiv">
                        <div class="col-md-2">
                        </div>
                        <div class="col-md-3">
                        </div>
                        <div class="col-md-1">
                        </div>
                        <div class="col-md-2">
                        </div>
                        <div class="col-md-3">
                            <div class="pull-right-button">
                                <asp:LinkButton ID="btn_Search" runat="server" OnClick="btn_Search_Click" CssClass="btn src-btn fa fa-search">
                                </asp:LinkButton>
                                <asp:LinkButton ID="btn_Clear" runat="server" OnClick="btn_Clear_Click" CssClass="btn clr-btn fa fa-refresh">
                                </asp:LinkButton>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="border-table new-space">
                <div class="row form-group">
                    <div class="col-md-12" style="overflow: auto; overflow-y: hidden; padding-bottom: 10px">
                        <asp:HiddenField ID="hdnSelectRow" runat="server" />
                        <asp:HiddenField ID="hdnGetAllid" runat="server" />
                        <div>
                            <dxGridview:ASPxGridView ID="grvLevel" runat="server" AutoGenerateColumns="False"
                                EnableCallBacks="false" ClientInstanceName="grvLevel" DataSourceID="ObjectDataSource2"
                                OnHtmlRowCreated="grvLevel_HtmlRowCreated" KeyFieldName="id" Width="100%">
                                <Columns>
                                    <dxGridview:GridViewDataColumn VisibleIndex="0" Width="34px" HeaderStyle-VerticalAlign="Middle"
                                        HeaderStyle-HorizontalAlign="Center" CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center">
                                        <HeaderTemplate>
                                            <input id="chkSelectAll" runat="server" type="checkbox" onclick="SelectAllOnThisPage(this)" />
                                        </HeaderTemplate>
                                        <DataItemTemplate>
                                            <input id="chkSelect" runat="server" type="checkbox" onclick="SelectOnRow(this)"
                                                accesskey='<%# Eval("id") %>' />
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="Center" Wrap="True" />
                                    </dxGridview:GridViewDataColumn>
                                    <dxGridview:GridViewDataTextColumn FieldName="id" Visible="False" VisibleIndex="6">
                                        <DataItemTemplate>
                                            <asp:Label ID="lblleveId" Text='<%# Eval("id") %>' runat="server">
                                            </asp:Label>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="Center" Wrap="True" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataTextColumn Caption="Level Name" FieldName="childLevelName"
                                        Width="40%" VisibleIndex="1">
                                        <DataItemTemplate>
                                            <asp:Label ID="lblLevelName" Text='<%# Eval("childLevelName") %>' runat="server"
                                                CssClass="dxlabel"></asp:Label>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="Center" Wrap="True" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataTextColumn FieldName="description" VisibleIndex="2" Width="40%">
                                        <DataItemTemplate>
                                            <asp:Label ID="lblDescription" Text='<%# Eval("description") %>' runat="server" CssClass="dxlabel">
                                            </asp:Label>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="Center" Wrap="True" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                        CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="10%">
                                        <Settings AllowAutoFilter="false" />
                                        <DataItemTemplate>
                                            <a data-toggle="modal" title='<%# Session["View"] %>' data-placement="top" data-target="#myModal
                                                " onclick="return navi('TA_UI_Master_LevelChildView.aspx?tid=<%# Eval("levelId") %>&chID=<%# Eval("Id") %>&sid=<%=Session.SessionID %>')"
                                                href="#"><span class="btn btn-defalut view-icons"></span></a>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataColumn>
                                    <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                        CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="10%">
                                        <Settings AllowAutoFilter="false" />
                                        <DataItemTemplate>
                                            <asp:LinkButton ID="btnEdit" CommandName='<%# Eval("levelId") %>' CommandArgument='<%# Eval("Id") %>'
                                                OnClick="EditLinkButton_Click" runat="server" ToolTip='<%# Session["Edit"] %>' data-toggle="tooltip"
                                                data-placement="top" CssClass="btn btn-defalut edit-icons" Style="color: #3C8DBC"></asp:LinkButton>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataColumn>
                                    <dxGridview:GridViewDataColumn HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Center"
                                        CellStyle-VerticalAlign="Middle" CellStyle-HorizontalAlign="Center" Width="10%">
                                        <Settings AllowAutoFilter="false" />
                                        <DataItemTemplate>
                                            <asp:LinkButton ID="btnDelete" runat="server" OnClientClick="return Delete_Conf();"
                                                CommandName='<%# Eval("levelId") %>' CommandArgument='<%# Eval("Id") %>' OnClick="deleteLinkButton_Click"
                                                ToolTip='<%# Session["Delete"] %>' data-toggle="tooltip" data-placement="top" CssClass="btn btn-defalut del-icons"
                                                Style="color: Red"></asp:LinkButton>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataColumn>

                                </Columns>
                                <SettingsPager PageSize="10">
                                    <PageSizeItemSettings Visible="true" ShowAllItem="true" Items="10,20,50,100,200" />
                                </SettingsPager>
                                <Settings ShowFilterRow="true" ShowFilterRowMenu="true" HorizontalScrollBarMode="Auto" ShowGroupPanel="true" VerticalScrollBarMode="Hidden" VerticalScrollableHeight="400" />
                                <SettingsText EmptyDataRow="No Records Found" />
                                <SettingsSearchPanel Visible="true" HighlightResults="true" ShowApplyButton="true" ShowClearButton="true" />
                                <SettingsBehavior AllowDragDrop="true" ColumnResizeMode="Control" />
                                <Styles AlternatingRow-CssClass="table-bg"
                                    Table-CssClass="MinWidth">
                                </Styles>
                            </dxGridview:ASPxGridView>
                            <dxGridview:ASPxGridViewExporter ID="ASPxGridViewExporter1" runat="server" GridViewID="grvLevel">
                                <PageFooter Right="[Page # of Pages #]">
                                </PageFooter>
                            </dxGridview:ASPxGridViewExporter>
                            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="selectLevelDetails"
                                TypeName="org_levelsEventData">
                                <SelectParameters>
                                    <asp:SessionParameter Name="UserLevels" SessionField="LevelRights" Type="string" />
                                    <asp:QueryStringParameter Name="lel_Id" QueryStringField="tid" Type="Int32" />
                                    <asp:Parameter Name="UserGroupName" DefaultValue="" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                            <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="selectLevelDetailsForSearch"
                                TypeName="org_levelsEventData">
                                <SelectParameters>
                                    <asp:SessionParameter Name="UserLevels" SessionField="LevelRights" Type="string" />
                                    <asp:SessionParameter Name="parentLevelId" SessionField="parentLevelIdForSearch"
                                        Type="Int32" />
                                    <asp:QueryStringParameter Name="lel_Id" QueryStringField="tid" Type="Int32" />
                                    <asp:SessionParameter Name="UserGroupName" SessionField="UserGroupName" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-md-12">
                        <div class="pull-right-button">
                            <asp:LinkButton ID="btn_Add" CssClass="btn save-btn fa-plus" runat="server" OnClick="btn_Add_Click" />
                            <asp:HiddenField ID="hdnDeletedData" runat="server" />
                            <asp:LinkButton ID="btn_PermanentDelete" OnClientClick="return Permanentconfirmdelete(this.form)"
                                CssClass="btn save-btn fa fa-trash-o" runat="server" OnClick="btn_PermanentDelete_Click" />
                            <asp:LinkButton ID="btn_cancel" CssClass="btn save-btn fa-angle-left" runat="server"
                                OnClick="btn_cancel_Click" />
                             <asp:LinkButton ID="btnExport" CommandName="excel" runat="server" CssClass="btn del-btn fa-file-excel-o" OnClick="btnExport_Click">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnExportPdf" CommandName="pdf" runat="server" CssClass="btn del-btn fa-file-pdf-o" OnClick="btnExport_Click">
                            </asp:LinkButton>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript" language="javascript">
            function indexInArray(arr, val) {
                for (var i = 0; i < arr.length; i++) if (arr[i] == val) return i;
                return -1;
            }
            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 != "" && indexInArray(removeId, hdnUserId) == -1) {
                                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 != "" && indexInArray(removeId, hdnUserId) == -1) {
                        if (hdnSelectRow.value != "")
                            hdnSelectRow.value += ",";
                        hdnSelectRow.value += hdnUserId;
                    }
                    var varTotalCheckedCount = 0;
                    var varTotalEnabled = 0;
                    for (var i = 0; i < grvLevel.pageRowCount; i++) {
                        if (document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                            varTotalEnabled = varTotalEnabled + 1;
                        }
                        if (document.getElementById('ctl00_BodyContentPH_grvLevel_cell' + (i + grvLevel.visibleStartIndex) + '_0_chkSelect').checked)
                            varTotalCheckedCount = varTotalCheckedCount + 1;
                    }
                    if (varTotalCheckedCount == varTotalEnabled)
                        document.getElementById('ctl00_BodyContentPH_grvLevel_header0_chkSelectAll').checked = true;
                    else
                        document.getElementById('ctl00_BodyContentPH_grvLevel_header0_chkSelectAll').checked = false;
                }
                else {
                    if (indexInArray(removeId, hdnUserId) != -1) {
                        for (var i = 0; i < removeId.length; i++) {
                            if (removeId[i] == hdnUserId) {
                                removeId.splice(i, 1);
                                break;
                            }
                        }
                    }
                    hdnSelectRow.value = removeId;
                    document.getElementById('ctl00_BodyContentPH_grvLevel_header0_chkSelectAll').checked = false;
                }
            }
            var Norecordsavailable = "No records available ";
            var AreyousuretoRestore = "Are you sure to Restore? ";
            var Selecteddataisnotindeletedstatus = "Selected data is not in deleted status ";
            var Selectdatatorestore = "Select data to restore ";
            var Nodeletedrecordsavailable = "No deleted records available ";
            function RestoreAlert(norecordsavailable, areyousuretoRestore, selecteddataisnotindeletedstatus, selectdatatorestore, nodeletedrecordsavailable) {
                Norecordsavailable = norecordsavailable;
                AreyousuretoRestore = areyousuretoRestore;
                Selecteddataisnotindeletedstatus = selecteddataisnotindeletedstatus;
                Selectdatatorestore = selectdatatorestore;
                Nodeletedrecordsavailable = nodeletedrecordsavailable;
            }
            function RestoreData() {
                var rowscount = grvLevel.pageRowCount;
                if (rowscount == 0) {
                    alert(AreyousuretoRestore);
                    return false;
                }
                var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
        var DeleteDataRow = document.getElementById('<%= hdnDeletedData.ClientID %>');
        if (DeleteDataRow.value != '') {
            if (hdnSelectRow.value != '') {
                var selectedRow = new Array();
                selectedRow = hdnSelectRow.value.split(",");
                var deletedRow = new Array();
                deletedRow = DeleteDataRow.value.split(",");
                var Status = false;
                for (var i = 0; i < selectedRow.length; i++) {
                    //alert(selectedRow[i]);
                    if (Array.contains(deletedRow, selectedRow[i])) {
                        Status = true;
                    }
                }
                if (Status == true) {
                    return confirm(AreyousuretoRestore);
                }
                else {
                    alert(Selecteddataisnotindeletedstatus);
                    return false;
                }
            }
            else {
                alert(Selectdatatorestore);
                return false;
            }
        }
        else {
            if (hdnSelectRow.value == '') {
                alert(Nodeletedrecordsavailable);
                return false;
            }
            else {
                alert(Selecteddataisnotindeletedstatus);
                return false;
            }
        }
    }
        </script>
    </div>
</asp:Content>
