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

<%@ 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/leave-type.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="form-horizontal">
            <div class="border-table new-space" style="margin-top: 0px">
                <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" />
                        <dxGridview:ASPxGridView ID="grdSmstemplate" EnableCallBacks="false" runat="server"
                            ClientInstanceName="grdSmstemplate" AutoGenerateColumns="false" KeyFieldName="Templateid"
                            OnHtmlDataCellPrepared="grdSmstemplate_HtmlDataCellPrepared" OnHtmlRowPrepared="grdSmstemplate_HtmlRowPrepared">
                            <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)"
                                            style="vertical-align: middle" accesskey='<%# Eval("Templateid") %>' />
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Templateid" VisibleIndex="1" Visible="false">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTemplateid" runat="server" Text=' <%# Eval("Templateid")%>' CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn Caption="Template Name" FieldName="TemplateName"
                                    VisibleIndex="2" Width="100px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblTemplateName" runat="server" Text='<%# Eval("TemplateName")%>'
                                            CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Message" VisibleIndex="3" Width="300px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblMessage" runat="server" Text=' <%# Eval("Message")%>' CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="Status" VisibleIndex="4" Width="40px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblStatus" runat="server" Text=' <%# Eval("Status")%>' CssClass="dxlabel"></asp:Label>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataTextColumn>
                                <dxGridview:GridViewDataTextColumn FieldName="LastModified" VisibleIndex="5" Width="100px">
                                    <DataItemTemplate>
                                        <asp:Label ID="lblModifiedDate" runat="server" Text=' <%# Eval("LastModified")%>'
                                            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="30px">
                                    <Settings AllowAutoFilter="false" />
                                    <DataItemTemplate>
                                        <asp:LinkButton ID="btnEdit" runat="server" ToolTip='<%# Session["Edit"] %>' data-toggle="tooltip"
                                            OnClick="EditLinkButton_Click" CommandName='<%# Eval("Templateid") %>' data-placement="top"
                                            CssClass="btn btn-defalut edit-icons" Style="color: #3C8DBC"></asp:LinkButton>
                                    </DataItemTemplate>
                                    <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                </dxGridview:GridViewDataColumn>
                            </Columns>
                            <SettingsPager PageSize="10">
                            </SettingsPager>
                            <SettingsText EmptyDataRow="No Records Found" />
                            <Settings ShowFilterRow="true" />
                            <SettingsBehavior SortMode="Value" AllowSort="true" AllowDragDrop="true" />
                            <Styles CssFilePath="../bootstrap/css/GridView.css" AlternatingRow-CssClass="table-bg">
                            </Styles>
                        </dxGridview:ASPxGridView>
                    </div>
                </div>
                <div class="row" align="right">
                    <div class="col-md-12">
                        <asp:HiddenField ID="hdnDisabledData" runat="server" />
                        <asp:HiddenField ID="hdnEnabledData" runat="server" />
                        <asp:LinkButton ID="btn_Enable" OnClientClick="return EnableData();" CssClass="btn save-btn fa-check-square-o"
                            runat="server" OnClick="btn_Enable_Click" />
                        <asp:LinkButton ID="btn_Disable" OnClientClick="return DisableData();" CssClass="btn save-btn fa-square-o"
                            runat="server" OnClick="btn_Disable_Click" CausesValidation="False" />
                    </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 < grdSmstemplate.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_grdSmstemplate_cell' + (i + grdSmstemplate.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                    document.getElementById('ctl00_BodyContentPH_grdSmstemplate_cell' + (i + grdSmstemplate.visibleStartIndex) + '_0_chkSelect').checked = true;
                    var hdnUserId = document.getElementById('ctl00_BodyContentPH_grdSmstemplate_cell' + (i + grdSmstemplate.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 < grdSmstemplate.pageRowCount; i++) {
                document.getElementById('ctl00_BodyContentPH_grdSmstemplate_cell' + (i + grdSmstemplate.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 < grdSmstemplate.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_grdSmstemplate_cell' + (i + grdSmstemplate.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                    varTotalEnabled = varTotalEnabled + 1;
                }
                if (document.getElementById('ctl00_BodyContentPH_grdSmstemplate_cell' + (i + grdSmstemplate.visibleStartIndex) + '_0_chkSelect').checked)
                    varTotalCheckedCount = varTotalCheckedCount + 1;
            }
            if (varTotalCheckedCount == varTotalEnabled)
                document.getElementById('ctl00_BodyContentPH_grdSmstemplate_header0_chkSelectAll').checked = true;
            else
                document.getElementById('ctl00_BodyContentPH_grdSmstemplate_header0_chkSelectAll').checked = false;
        }
        else {
            if (Array.contains(removeId, hdnUserId)) {
                Array.remove(removeId, hdnUserId);
            }
            hdnSelectRow.value = removeId;
            document.getElementById('ctl00_BodyContentPH_grdSmstemplate_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 = grdSmstemplate.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 = grdSmstemplate.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>
