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

<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="devxEditors" %>
<%--Added user control for levelwise search in addtional weekly off by Manjula.P on 07-Apr-2014--%>
<%@ Register Src="~/UserControls/TA_uc_OrganizationLevels.ascx" TagName="OrganizationLevel"
    TagPrefix="uc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ContentPlaceHolderID="BodyContentPH" ID="conAddlWeekoff" runat="server">
    <div class="content-header">
        <h1 style="background-image: url(../dist/img/add-weekoff.png); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_Header" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div class="inr-ftr">
            <div class="row">
                <div class="col-sm-12">
                    <div class="inr-fil-text pull-left">
                        <asp:Label ID="lblFilter" runat="server" Text="Filters"></asp:Label>
                    </div>
                    <div class="pull-right">
                        <h6></h6>
                    </div>
                </div>
                <div class="clearfix">
                </div>
            </div>
        </div>
        <div class="form-horizontal">
            <div class="emp-filter">
                <div class="row form-group">
                    <div class="col-md-12">
                        <div class="row" id="trOrgLevel" runat="server">
                            <div class="col-md-12">
                                <asp:UpdatePanel ID="upOrgLevel" runat="server" UpdateMode="Conditional">
                                    <ContentTemplate>
                                        <asp:PlaceHolder ID="PlaceHolderLateEntry" runat="server">
                                            <uc:OrganizationLevel ID="ucOrganizationLevel" runat="server" />
                                        </asp:PlaceHolder>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </div>
                        </div>
                        <div class="clearfix">
                        </div>
                        <div class="row">
                            <div class="row">
                                <div class="line16">
                                </div>
                            </div>
                        </div>
                        <div class="row form-group">
                            <div class="col-md-2">
                                <asp:Label ID="lbl_Weekof" runat="server" Style="padding-left: 5px;"></asp:Label>
                            </div>
                            <div class="col-md-3">
                                <asp:DropDownList ID="ddl_Day" CssClass="form-control select2" runat="server">
                                    <asp:ListItem Value="All" Text="All"></asp:ListItem>
                                    <asp:ListItem Value="Sunday" Text="Sunday"></asp:ListItem>
                                    <asp:ListItem Value="Monday" Text="Monday"></asp:ListItem>
                                    <asp:ListItem Value="Tuesday" Text="Tuesday"></asp:ListItem>
                                    <asp:ListItem Value="Wednesday" Text="Wednesday"></asp:ListItem>
                                    <asp:ListItem Value="Thursday" Text="Thursday"></asp:ListItem>
                                    <asp:ListItem Value="Friday" Text="Friday"></asp:ListItem>
                                    <asp:ListItem Value="Saturday" Text="Saturday"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                            <div class="col-md-1">
                            </div>
                            <div class="col-md-2">
                                <asp:Label ID="lbl_selectedweek" runat="server"></asp:Label>
                            </div>
                            <div class="col-md-3">
                                <asp:DropDownList ID="ddl_Week" CssClass="form-control select2" runat="server">
                                    <asp:ListItem Value="All" Text="All"></asp:ListItem>
                                    <asp:ListItem Value="First Week" Text="First Week"></asp:ListItem>
                                    <asp:ListItem Value="Second Week" Text="Second Week"></asp:ListItem>
                                    <asp:ListItem Value="Third Week" Text="Third Week"></asp:ListItem>
                                    <asp:ListItem Value="Fourth Week" Text="Fourth Week"></asp:ListItem>
                                    <asp:ListItem Value="Fifth Week" Text="Fifth Week"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <div class="row" id="trSearchButton" runat="server">
                            <div class="col-md-6">
                            </div>
                            <div class="col-md-5">
                                <div class="pull-right-button">
                                    <asp:LinkButton ID="btn_Search" CssClass="btn save-btn fa-search" runat="server"
                                        OnClick="btn_Search_Click" />
                                    <asp:LinkButton ID="btn_Clear" CssClass="btn save-btn fa-refresh" runat="server"
                                        OnClick="btn_Clear_Click" />
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="border-table new-space">
                <div class="row">
                    <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" />
                        <dxGridview:ASPxGridView ID="grv_Addl_Weekoff" EnableCallBacks="false" runat="server"
                            ClientInstanceName="grv_Addl_Weekoff" DataSourceID="ObjectDataSource1" AutoGenerateColumns="false"
                            KeyFieldName="chkSelect" Width="100%" OnHtmlRowCreated="grv_Addl_Weekoff_HtmlRowCreated">
                            <Columns>
                                <dxGridview:GridViewDataTextColumn FieldName="Addl_WeeklyOff_Id" Caption="Addl_WeeklyOff_Id"
                                    Visible="false" VisibleIndex="0">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblAddlWeekoffID" Text='<%# Eval("Addl_WeeklyOff_Id") %>' runat="server"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataColumn VisibleIndex="1" 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("Addl_WeeklyOff_Id") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="AddWeekday_week" Caption="Additional Weekoff Day-Week"
                                    VisibleIndex="2" CellStyle-HorizontalAlign="Left" Width="600px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblRegionname" Text='<%# Eval("AddWeekday_week") %>' runat="server">
                                        </asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="IsDeleted" Caption="Deleted" VisibleIndex="3"
                                    Width="70px" CellStyle-HorizontalAlign="Left" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblIsDeleted" runat="server" Text='<%# Bind("IsDeleted") %>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="LevelId" Caption="LevelId" Visible="false"
                                    VisibleIndex="4">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblLevelId" runat="server" Text='<%# Bind("LevelId") %>'></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 data-toggle="tooltip" title='<%# Session["View"] %>' data-placement="top" href="Organization_AddlWeekoff_Add.aspx?AddlWeekoff_Id=<%# Eval("Addl_WeeklyOff_Id") %>"
                                            href="#"><span class="btn btn-defalut view-icons"></span></a>
                                    </DataItemTemplate>
                                </dxGridview:GridViewDataColumn>
                            </Columns>
                            <SettingsPager PageSize="10">
                            </SettingsPager>
                            <Settings ShowFilterRow="true" />
                            <SettingsBehavior SortMode="Value" AllowSort="true" AllowDragDrop="true" />
                            <Styles AlternatingRow-CssClass="table-bg">
                            </Styles>
                        </dxGridview:ASPxGridView>
                    </div>
                </div>
                <div class="row" style="padding-top: 10px">
                    <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:LinkButton ID="btn_Delete" CssClass="btn save-btn fa-trash-o" runat="server"
                                OnClientClick="return Permanentconfirmdelete(this.form);" OnClick="btn_PermanentDelete_Click"
                                Visible="false" />
                            <asp:Button ID="btn_Restore" CssClass="but" runat="server" OnClientClick="return RestoreData();"
                                OnClick="btn_Restore_Click" Visible="false" />
                            <asp:HiddenField ID="hdnDeletedData" runat="server" />
                            <asp:Button ID="btn_PermanentDelete" CssClass="but" runat="server" Width="150px"
                                OnClientClick="return Permanentconfirmdelete(this.form);" OnClick="btn_PermanentDelete_Click"
                                Visible="false" />
                            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" InsertMethod="Insert_AddlWeekoffDetails"
                                SelectMethod="Select_AddlWeekoffdetails" TypeName="AddlWeekOffEventData">
                                <SelectParameters>
                                    <asp:SessionParameter Name="UserGroupName" Type="String" SessionField="UserGroupName" />
                                    <asp:SessionParameter Name="ParentId" Type="int32" SessionField="parentLevelId" DefaultValue="0" />
                                    <asp:ControlParameter Name="WeekOffDay" Type="string" DefaultValue="All" ControlID="ddl_Day"
                                        PropertyName="SelectedValue" />
                                    <asp:ControlParameter Name="WeekOffWeek" Type="string" DefaultValue="All" ControlID="ddl_Week"
                                        PropertyName="SelectedValue" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                        </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 < grv_Addl_Weekoff.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_cell' + (i + grv_Addl_Weekoff.visibleStartIndex) + '_1_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_cell' + (i + grv_Addl_Weekoff.visibleStartIndex) + '_1_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_cell' + (i + grv_Addl_Weekoff.visibleStartIndex) + '_1_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 < grv_Addl_Weekoff.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_cell' + (i + grv_Addl_Weekoff.visibleStartIndex) + '_1_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 < grv_Addl_Weekoff.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_cell' + (i + grv_Addl_Weekoff.visibleStartIndex) + '_1_chkSelect').checked)
                        varTotalCheckedCount = varTotalCheckedCount + 1;
                    else
                        break;
                }
                if (varTotalCheckedCount == grv_Addl_Weekoff.pageRowCount)
                    document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_header1_chkSelectAll').checked = true;
                else
                    document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_header1_chkSelectAll').checked = false;
            }
            else {
                if (Array.contains(removeId, hdnUserId)) {
                    Array.remove(removeId, hdnUserId);
                }
                hdnSelectRow.value = removeId;

                document.getElementById('ctl00_BodyContentPH_grv_Addl_Weekoff_header1_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 = grv_Addl_Weekoff.pageRowCount;
            if (rowscount == 0) {
                alert(Norecordsavailable);
                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>

</asp:Content>
