<%@ page language="C#" masterpagefile="~/MasterPage.master" autoeventwireup="true" inherits="LogOutUsers, CardAccess.Web.UI_deploy" title="Logout Users" theme="Office2007Black" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script language="javascript" type="text/javascript">
        let operatorLoginName = '<%=OperatorLoginName %>';
        function SelectedUsersLogout() {
            let checkedUser = false;
            let grid_id = $find('<%=this.grdLoggedIn.ClientID %>');
            for (let i = 0; i < grid_id.get_rows().get_length(); i++) {
                let checkbox = grid_id.get_rows().get_row(i).get_cell(0).get_element().children[0].children[0];
                if (checkbox && checkbox.checked) {
                    checkedUser = true;
                    break;
                }
            }
            if (checkedUser) {
                if (confirm("<%=this.SelectedUserLogout%>"))
                    checkedUser = true;
                else
                    checkedUser = false;
            }
            return checkedUser;
        }

        function handleRowChange(e) {
            let grid = $find('<%=this.grdLoggedIn.ClientID %>');
            let index = grid.get_behaviors().get_selection().get_selectedRows().getItem(0).get_index();
            let userName = grid.get_rows().get_row(index).get_cell(1).get_text();
            if (operatorLoginName == userName) {
                let checkbox = e.target;
                if (checkbox) {
                    checkbox.checked = false;
                }
            }
        }

        function handleHeaderChange(e) {
            let grid = $find('<%=this.grdLoggedIn.ClientID %>');
            let chkHeaderCheck = e.target;
            for (i = 0; i < grid.get_rows().get_length(); i++) {
                let userName = grid.get_rows().get_row(i).get_cell(1).get_text();
                let checkbox = grid.get_rows().get_row(i).get_cell(0).get_element().children[0].children[0];
                if (checkbox) {
                    checkbox.checked = chkHeaderCheck.checked;
                    if (operatorLoginName == userName) {
                        checkbox.checked = false;
                    }
                }
            }
        }
    </script>

    <asp:UpdatePanel ID="updLogout" runat="server">
        <ContentTemplate>
            <igmisc:WebGroupBox ID="WebGroupBox1" BorderWidth="0px" runat="server" BackColor="Transparent">
                <Template>
                    <div style="width: 100%;">
                        <div style="float: left;" class="ig_Office_2007ReportPreViewBg">
                            <asp:LinkButton Style="margin-top: 10px; text-decoration: none; color: #033E82" ID="lnkLogOut"
                                OnClick="lnkLogOut_Click" runat="server" OnClientClick="return SelectedUsersLogout();">Logged Out</asp:LinkButton>
                        </div>
                        <div style="float: left;" class="ig_Office_2007ReportPreViewBg">
                            <asp:LinkButton Style="margin-top: 10px; text-decoration: none; color: #033E82" ID="lnkRefresh"
                                OnClick="lnkRefresh_Click" runat="server">Refresh</asp:LinkButton>
                        </div>
                    </div>                    
                    <div style="clear: both;">
                    </div>
                    <div style="width: 100%;">
                        <ig:WebDataGrid ID="grdLoggedIn" runat="server" Width="100%" AutoGenerateColumns="false"
                            EnableViewState="true" EnableDataViewState="true" DataKeyFields="NetStationId">
                            <EmptyRowsTemplate>
                                <%=EmptyRowTemplateMsg %>
                            </EmptyRowsTemplate>
                            <Columns>
                                <ig:TemplateDataField Key="Check">
                                    <HeaderTemplate>
                                        <asp:CheckBox ID="chkHeaderCheck" runat="server" onchange="handleHeaderChange(event)" />
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkItemCheck" runat="server" onchange="handleRowChange(event)" />
                                    </ItemTemplate>
                                </ig:TemplateDataField>                            
                                <ig:BoundDataField DataFieldName="Operator" Header-Text="Name" Key="Operator">
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="UNCNameModified" Header-Text="Workstation" Key="UNCNameModified">
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="LoggedOnTime" Header-Text="LoggedOnTime" Key="LoggedOnTime"
                                    DataFormatString="{0:dd/MM/yyyy hh:mm:ss tt}">
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="NetStationId" Header-Text="NetStationId" Key="NetStationId"
                                    Hidden="true">
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="Device" Header-Text="Device" Key="Device" Hidden="true">
                                </ig:BoundDataField>
                                <ig:BoundDataField DataFieldName="UNCName" Header-Text="Workstation" Key="UNCName" Hidden="true">
                                </ig:BoundDataField>
                            </Columns>
                            <Behaviors>
                                <ig:EditingCore>
                                    <Behaviors>
                                        <ig:CellEditing>
                                            <ColumnSettings>
                                            </ColumnSettings>
                                        </ig:CellEditing>
                                    </Behaviors>
                                </ig:EditingCore>
                                <ig:Selection CellClickAction="Row" RowSelectType="Single" CellSelectType="Single">
                                </ig:Selection>
                            </Behaviors>
                        </ig:WebDataGrid>
                    </div>
                </Template>
            </igmisc:WebGroupBox>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
