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

<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="dxe" %>
<%@ 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/email-shudule.png'); background-repeat: no-repeat; padding-left: 35px">
            <asp:Label ID="lbl_HeaderTemplate" Text="Email Scheduler" runat="server"></asp:Label>
        </h1>
        <asp:SiteMapPath ID="site" runat="server" CssClass="breadcrumb">
            <NodeStyle CssClass="active" />
        </asp:SiteMapPath>
    </div>
    <div class="content">
        <div class="border-table new-space" style="margin-top: 0px; padding-bottom: 10px">
            <div class="form-horizontal">
                <div class="row form-group">
                    <div class="col-md-12">
                        <asp:HiddenField ID="hdnSelectRow" runat="server" />
                        <asp:HiddenField ID="hdnGetAllid" runat="server" />
                        <dxGridview:ASPxGridView ID="gvEmailSchedule" EnableCallBacks="false" runat="server"
                            ClientInstanceName="gvEmailSchedule" AutoGenerateColumns="false" KeyFieldName="ScheduleId"
                            DataSourceID="ObjectDataSource1" OnHtmlRowPrepared="gvEmailSchedule_HtmlRowPrepared"
                            OnHtmlDataCellPrepared="gvEmailSchedule_HtmlDataCellPrepared" Width="100%">
                            <Columns>
                                <dxGridview:GridViewDataColumn VisibleIndex="0" Width="30px" 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("ScheduleId") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn CellStyle-HorizontalAlign="left" Caption="Schedule Name"
                                    FieldName="ScheduleName" Width="25%">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblScheduleName" runat="server" Text='<%# Eval("ScheduleName") %>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="displayName" Caption="Report Name"
                                    Width="25%">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblReportName" runat="server" Text=' <%# Eval("displayName")%>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Frequency" Caption="Frequency" Width="13%">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblFrequency" runat="server" Text=' <%# Eval("Frequency")%>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="EmployeeName" Caption="Created by"
                                    Width="100px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblEmployeeName" runat="server" Text=' <%# Eval("EmployeeName")%>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Enabled" Caption="Status" Width="13%">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblStatus" runat="server" Text=' <%# Eval("Enabled")%>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                 <dxGridview:GridViewDataTextColumn FieldName="Time" Width="100px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTimeToSend" runat="server" Text=' <%# Eval("TimeToSend")%>'></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Preview" Visible="false">
                                    <DataItemTemplate>
                                        <asp:LinkButton runat="server" ID="lbPreview" Text="Preview" OnClick="lbPreview_Click"></asp:LinkButton>
                                    </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_EmailSchedule.aspx?ScheduleId=<%# Eval("ScheduleId") %>"><span class="btn btn-defalut edit-icons"></span></a>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                            </Columns>
                            <SettingsPager PageSize="15">
                                <PageSizeItemSettings Visible="true" ShowAllItem="true" Items="10,20,50,100,200" />
                            </SettingsPager>
                            <Settings ShowFilterRow="true" ShowFilterRowMenu="true" HorizontalScrollBarMode="Auto" VerticalScrollBarMode="Hidden" VerticalScrollableHeight="400"/>
                            <SettingsText EmptyDataRow="No Records Found" />
                            <SettingsBehavior AutoExpandAllGroups="True" ColumnResizeMode="Control" />
                            <GroupSummary>
                                <dxGridview:aspxsummaryitem fieldname="DepartmentName" summarytype="Count" />
                            </GroupSummary>
                            <SettingsBehavior AllowDragDrop="true" />
                        </dxGridview:ASPxGridView>
                        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="SelectScheduleDetails"
                            TypeName="EmailConfiguration">
                            <SelectParameters>
                                <asp:SessionParameter Name="UserGroupName" SessionField="UserGroupName" Type="string" />
                                <asp:SessionParameter Name="EmployeeId" SessionField="EmpAutoId" Type="int32" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                    </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:LinkButton>
                            <asp:LinkButton ID="btnEnable" OnClientClick="return EnableData();" CssClass="btn save-btn fa-check-square-o"
                                CausesValidation="False" runat="server" OnClick="btnEnable_Click" Text="&nbsp;&nbsp;Enable">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btnDisable" OnClientClick="return DisableData();" CssClass="btn save-btn fa-square-o"
                                CausesValidation="False" runat="server" OnClick="btnDisable_Click" Text="&nbsp;&nbsp;Disable">
                            </asp:LinkButton>
                            <asp:LinkButton ID="btn_Delete" CssClass="btn save-btn fa-trash-o" runat="server"
                                CausesValidation="False" OnClick="btn_Delete_Click" OnClientClick="return confirmdelete(this.form);">
                            </asp:LinkButton>
                            <asp:HiddenField ID="hdnDisabledData" runat="server" />
                            <asp:HiddenField ID="hdnEnabledData" runat="server" />
                            <asp:Button runat="server" ID="btnBack" CssClass="but" Text="BACK" OnClick="btnBack_Click"
                                Visible="false" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
        //     function OnInit(s, e) {
        // 
        //            AdjustSize();
        //        }
        //        function OnEndCallback(s, e) {
        //            AdjustSize();
        //        }
        //         
        //            function OnColumnSorting(s, e) {
        //            AdjustSize();
        //        }
        //        function AdjustSize() {        
        //        
        //            var height = Math.max(0, document.documentElement.clientHeight);
        //            var width = Math.max(0, document.documentElement.clientWidth);
        //            grid.SetHeight(height);            
        //        }
        //    

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

    <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 < gvEmailSchedule.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_cell' + (i + gvEmailSchedule.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                    document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_cell' + (i + gvEmailSchedule.visibleStartIndex) + '_0_chkSelect').checked = true;
                    var hdnUserId = document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_cell' + (i + gvEmailSchedule.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 < gvEmailSchedule.pageRowCount; i++) {
                document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_cell' + (i + gvEmailSchedule.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; var varTotalEnabled = 0;
            for (var i = 0; i < gvEmailSchedule.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_cell' + (i + gvEmailSchedule.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                    varTotalEnabled = varTotalEnabled + 1;
                }
                if (document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_cell' + (i + gvEmailSchedule.visibleStartIndex) + '_0_chkSelect').checked)
                    varTotalCheckedCount = varTotalCheckedCount + 1;
            }
            if (varTotalCheckedCount == varTotalEnabled)
                document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_header0_chkSelectAll').checked = true;
            else
                document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_header0_chkSelectAll').checked = false;
        }
        else {
            if (Array.contains(removeId, hdnUserId)) {
                Array.remove(removeId, hdnUserId);
            }
            hdnSelectRow.value = removeId;
            document.getElementById('ctl00_BodyContentPH_gvEmailSchedule_header0_chkSelectAll').checked = false;
        }
    }
    var Norecordsavailable = "No records available ";
    var AreyousuretoEnable = "Are you sure to Enable? ";
    var AreyousuretoDisable = "Are you sure to Disable? ";
    var Selecteddataisnotindisabledstatus = "Selected data is not in disabled status ";
    var Selecteddataisnotinenabledstatus = "Selected data is not in enabled status ";
    var Selectdatatoenable = "Select data to enable ";
    var Selectdatatodisable = "Select data to disable ";
    var Nodisabledrecordsavailable = "No disabled records available ";
    var Noenabledrecordsavailable = "No enabled records available ";
    function EnableDisableAlert(norecordsavailable, areyousuretoEnable, areyousuretoDisable, selecteddataisnotindisabledstatus,
    selecteddataisnotinenabledstatus, selectdatatoenable, selectdatatodisable, nodisabledrecordsavailable, noenabledrecordsavailable) {
        var Norecordsavailable = norecordsavailable;
        var AreyousuretoEnable = areyousuretoEnable;
        var AreyousuretoDisable = areyousuretoDisable;
        var Selecteddataisnotindisabledstatus = selecteddataisnotindisabledstatus;
        var Selecteddataisnotinenabledstatus = selecteddataisnotinenabledstatus;
        var Selectdatatoenable = selectdatatoenable;
        var Selectdatatodisable = selectdatatodisable;
        var Nodisabledrecordsavailable = nodisabledrecordsavailable;
        var Noenabledrecordsavailable = noenabledrecordsavailable;
    }
    function DisableData() {
        var rowscount = gvEmailSchedule.pageRowCount;
        if (rowscount == 0) {
            alert(Norecordsavailable);
            return false;
        }
        var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
        var EnabledDataRow = document.getElementById('<%= hdnEnabledData.ClientID %>');
        if (EnabledDataRow.value != '') {
            if (hdnSelectRow.value != '') {
                var selectedRow = new Array();
                selectedRow = hdnSelectRow.value.split(",");
                var enabledRow = new Array();
                enabledRow = EnabledDataRow.value.split(",");
                var Status = false;
                for (var i = 0; i < selectedRow.length; i++) {
                    //alert(selectedRow[i]);
                    if (Array.contains(enabledRow, selectedRow[i])) {
                        Status = true;
                    }
                }
                if (Status == true) {
                    return confirm(AreyousuretoDisable);
                }
                else {
                    alert(Selecteddataisnotinenabledstatus);
                    return false;
                }
            }
            else {
                alert(Selectdatatodisable);
                return false;
            }
        }
        else {
            if (hdnSelectRow.value == '') {
                alert(Noenabledrecordsavailable);
                return false;
            }
            else {
                alert(Selecteddataisnotinenabledstatus);
                return false;
            }
        }
    }
    function EnableData() {
        var rowscount = gvEmailSchedule.pageRowCount;
        if (rowscount == 0) {
            alert(Norecordsavailable);
            return false;
        }
        var hdnSelectRow = document.getElementById('<%= hdnSelectRow.ClientID %>');
        var DisabledDataRow = document.getElementById('<%= hdnDisabledData.ClientID %>');
        if (DisabledDataRow.value != '') {
            if (hdnSelectRow.value != '') {
                var selectedRow = new Array();
                selectedRow = hdnSelectRow.value.split(",");
                var disabledRow = new Array();
                disabledRow = DisabledDataRow.value.split(",");
                var Status = false;
                for (var i = 0; i < selectedRow.length; i++) {
                    //alert(selectedRow[i]);
                    if (Array.contains(disabledRow, selectedRow[i])) {
                        Status = true;
                    }
                }
                if (Status == true) {
                    return confirm(AreyousuretoEnable);
                }
                else {
                    alert(Selecteddataisnotindisabledstatus);
                    return false;
                }
            }
            else {
                alert(Selectdatatoenable);
                return false;
            }
        }
        else {
            if (hdnSelectRow.value == '') {
                alert(Nodisabledrecordsavailable);
                return false;
            }
            else {
                alert(Selecteddataisnotindisabledstatus);
                return false;
            }
        }
    }
    </script>

</asp:Content>
