<%@ Page Language="C#" MasterPageFile="~/MasterFile/TimeCheck.master" AutoEventWireup="true"
    CodeFile="TA_UI_Transactions_PermissionBulkSanction.aspx.cs" Inherits="Transactions_TA_UI_Transactions_PermissionBulkSanction" %>

<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="Server">
    <div class="content-header">
        <h1 style="background-image: url('../dist/img/lve-san.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_HeaderPermissionSanction" 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 form-group">
                    <div class="col-md-12">
                        <div class="table-responsive" style="padding-bottom: 10px">
                            <asp:HiddenField ID="hdnSelectRow" runat="server" />
                            <asp:HiddenField ID="hdnGetAllid" runat="server" />
                            <dxGridview:ASPxGridView ID="gdPermissionSanctionView" EnableCallBacks="false" runat="server"
                                ClientInstanceName="gdPermissionSanctionView" AutoGenerateColumns="false" Width="100%"
                                OnHtmlRowCreated="gdPermissionSanctionView_HtmlRowCreated">
                                <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)"
                                                accesskey='<%# Eval("Permission_Id") %>' />
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataColumn>
                                    <dxGridview:GridViewDataTextColumn FieldName="employeeid" VisibleIndex="1" Width="150px">
                                        <Settings AllowDragDrop="False" />
                                        <DataItemTemplate>
                                            <asp:Label Style="overflow-y: auto; overflow-x: auto; word-break: break-all; cursor: pointer; word-wrap: break-word; display: inline-block;"
                                                ID="lblEmpid"
                                                runat="server" Text='<%# Eval("employeeid")%>'></asp:Label>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataTextColumn Caption="Employee Name" FieldName="Employee_FirstName"
                                        VisibleIndex="2" Width="250px">
                                        <Settings AllowDragDrop="False" />
                                        <DataItemTemplate>
                                            <asp:Label Style="overflow-y: auto; overflow-x: auto; word-break: break-all; cursor: pointer; word-wrap: break-word; display: inline-block;"
                                                ID="lblEmployeeName"
                                                runat="server" Text='<%# Eval("Employee_FirstName")%>'></asp:Label>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataTextColumn FieldName="Permission_AppliedDate" VisibleIndex="3"
                                        Width="250px">
                                        <Settings AllowDragDrop="False" />
                                        <DataItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Permission_AppliedDate") %>'></asp:Label>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataTextColumn FieldName="Duration" VisibleIndex="4" Width="220px">
                                        <Settings AllowDragDrop="False" />
                                        <DataItemTemplate>
                                            <asp:Label ID="lbl_Duration" runat="server" Text='<%# Bind("Duration") %>'></asp:Label>
                                        </DataItemTemplate>
                                        <Settings AllowAutoFilter="False" />
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataTextColumn>
                                    <dxGridview:GridViewDataTextColumn FieldName="Permission_Status" VisibleIndex="5"
                                        Width="70px">
                                        <Settings AllowDragDrop="False" />
                                        <DataItemTemplate>
                                            <asp:Label ID="lblPermissionStatus" runat="server" Text='<%# Bind("Permission_Status") %>'></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="40px">
                                        <Settings AllowAutoFilter="false" />
                                        <DataItemTemplate>
                                            <a href="TA_UI_Transactions_PermissionSanctionModify.aspx?Permission_Id=<%# Eval("Permission_Id")%>&Status=<%# Eval("Permission_Status")%>">
                                                <span class="btn btn-defalut edit-icons"></span></a>
                                        </DataItemTemplate>
                                        <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                    </dxGridview:GridViewDataColumn>
                                    <dxGridview:GridViewDataColumn FieldName="Permission_FromTime" VisibleIndex="6" Visible="false">
                                    </dxGridview:GridViewDataColumn>
                                    <dxGridview:GridViewDataColumn FieldName="Permission_ToTime" VisibleIndex="7" Visible="false">
                                    </dxGridview:GridViewDataColumn>
                                </Columns>
                                <SettingsText EmptyDataRow="No Records Found" />
                                <SettingsPager PageSize="10">
                                </SettingsPager>
                                <SettingsText EmptyDataRow="No Records Found" />
                                <Settings ShowFilterRow="true" />
                                <SettingsBehavior SortMode="Value" AllowSort="true" AllowDragDrop="true" />
                                <Styles AlternatingRow-CssClass="table-bg">
                                </Styles>
                            </dxGridview:ASPxGridView>
                        </div>
                    </div>
                </div>
                <div class="row form-group">
                    <div class="col-md-12">
                        <div class="pull-right-button">
                            <asp:LinkButton ID="btnSave" runat="server" CssClass="btn save-btn fa-floppy-o" Text="Sanction"
                                OnClick="btnSave_Click" />
                            <asp:LinkButton ID="btnBack" runat="server" CssClass="btn save-btn fa-angle-left"
                                OnClick="btnBack_Click" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript" language="javascript">
        function OnInit(s, e) {

            AdjustSize();
        }
        function OnEndCallback(s, e) {
            AdjustSize();
        }

        function AdjustSize() {

            var height = Math.max(0, document.documentElement.clientHeight);
            var width = Math.max(0, document.documentElement.clientWidth);
            grid.SetHeight(height);
        }
        function SelectAllOnThisPage(chkSelectAll) {

            var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
        var hdnSelectAll = document.getElementById('<%= hdnGetAllid.ClientID %>');
        if (chkSelectAll.checked == true) {
            for (var i = 0; i < gdPermissionSanctionView.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_cell' + (i + gdPermissionSanctionView.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                    document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_cell' + (i + gdPermissionSanctionView.visibleStartIndex) + '_0_chkSelect').checked = true;
                    var hdnUserId = document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_cell' + (i + gdPermissionSanctionView.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 < gdPermissionSanctionView.pageRowCount; i++) {
                document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_cell' + (i + gdPermissionSanctionView.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 < gdPermissionSanctionView.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_cell' + (i + gdPermissionSanctionView.visibleStartIndex) + '_0_chkSelect').checked)
                    varTotalCheckedCount = varTotalCheckedCount + 1;
                else
                    break;
            }
            if (varTotalCheckedCount == gdPermissionSanctionView.pageRowCount)
                document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_header0_chkSelectAll').checked = true;
            else
                document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_header0_chkSelectAll').checked = false;
        }
        else {
            if (Array.contains(removeId, hdnUserId)) {
                Array.remove(removeId, hdnUserId);
            }
            hdnSelectRow.value = removeId;

            document.getElementById('ctl00_BodyContentPH_gdPermissionSanctionView_header0_chkSelectAll').checked = false;
        }
    }

    </script>

</asp:Content>
