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

<%@ Register TagPrefix="dxGridview" Namespace="DevExpress.Web" Assembly="DevExpress.Web.v14.2" %>
<%@ Register Assembly="DevExpress.Web.v14.2" Namespace="DevExpress.Web"
    TagPrefix="devxEditors" %>
<asp:Content ID="Content1" ContentPlaceHolderID="BodyContentPH" runat="server">
    <div class="content-header">
        <h1>
            <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="emp-filter">
            <div class="form-horizontal">
                <div class="row">
                    <div class="col-md-12">
                        <div class="form-group row">
                            <div class="col-md-12" style="overflow: auto; padding-bottom: 10px; overflow-y: hidden;">
                                <asp:HiddenField ID="hdnSelectRow" runat="server" />
                                <asp:HiddenField ID="hdnGetAllid" runat="server" />
                                <dxGridview:ASPxGridView ID="GridView1" EnableCallBacks="false" runat="server" ClientInstanceName="GridView1"
                                    DataSourceID="ObjectDataSource1" AutoGenerateColumns="false" KeyFieldName="chkSelect"
                                    Width="100%" OnHtmlRowCreated="GridView1_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("NewsEvent_Id") %>' />
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataColumn>
                                        <dxGridview:GridViewDataTextColumn FieldName="NewsEventFromDate" Caption="From Date"
                                            VisibleIndex="1" Width="90px">
                                            <DataItemTemplate>
                                                <asp:Label ID="lblNewsFromDate" Text='<%# Eval("NewsEventFromDate") %>' runat="server">
                                                </asp:Label>
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewDataTextColumn FieldName="NewsEventToDate" Caption="To Date"
                                            VisibleIndex="2" Width="90px">
                                            <DataItemTemplate>
                                                <asp:Label ID="lblNewsToDate" Text='<%# Eval("NewsEventToDate") %>' runat="server"></asp:Label>
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewDataTextColumn FieldName="NewsEventTitle" Caption="Title" VisibleIndex="3"
                                            Width="200px">
                                            <DataItemTemplate>
                                                <asp:Label ID="lblNewsTitle" Text='<%# Eval("NewsEventTitle") %>' runat="server"
                                                    Style="overflow-y: auto; overflow-x: auto; word-break: break-all; cursor: pointer; width: 160px; word-wrap: break-word; display: inline-block;"></asp:Label>
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewDataTextColumn FieldName="NewsEventDescription" Caption="Description"
                                            Width="310px" VisibleIndex="4">
                                            <DataItemTemplate>
                                                <asp:Label ID="lblNewsDesc" Text='<%# Eval("NewsEventDescription") %>' runat="server"
                                                    Style="overflow-y: auto; overflow-x: auto; word-break: break-all; word-wrap: break-word; display: inline-block;"></asp:Label>
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataTextColumn>
                                        <dxGridview:GridViewDataTextColumn FieldName="IsDeleted" Caption="Deleted" Visible="false"
                                            Width="80px">
                                            <DataItemTemplate>
                                                <asp:Label ID="lblIsDeleted" runat="server" Text='<%# Bind("IsDeleted") %>'></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="Organization_NewsEdit.aspx?nId=<%# Eval("NewsEvent_Id") %>&sid=<%=Session.SessionID %>">
                                                    <span class="btn btn-defalut edit-icons"></span></a>
                                            </DataItemTemplate>
                                            <HeaderStyle HorizontalAlign="center" Wrap="true" />
                                        </dxGridview:GridViewDataColumn>
                                    </Columns>
                                    <SettingsPager PageSize="10">
                                    </SettingsPager>
                                    <Settings ShowFilterRow="true" />
                                    <SettingsBehavior SortMode="Value" AllowSort="true" AllowDragDrop="false" />
                                    <Styles AlternatingRow-CssClass="table-bg">
                                    </Styles>
                                </dxGridview:ASPxGridView>
                            </div>
                        </div>
                        <div class="form-group row" style="padding-right: 15px;">
                            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="selectNews"
                                TypeName="NewsEventData">
                                <SelectParameters>
                                    <asp:SessionParameter Name="UserGroupName" Type="String" SessionField="UserGroupName" />
                                </SelectParameters>
                            </asp:ObjectDataSource>
                            <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 ID="btn_Delete" CssClass="btn save-btn fa-trash-o" runat="server"
                                            CausesValidation="false" OnClientClick="return Permanentconfirmdelete(this.form);"
                                            OnClick="btn_PermanentDelete_Click" />
                                        <asp:LinkButton ID="btn_Restore" CssClass="but" runat="server" OnClientClick="return RestoreData();"
                                            OnClick="btn_Restore_Click" Visible="false" />
                                        <asp:HiddenField ID="hdnDeletedData" runat="server" />
                                        <asp:LinkButton ID="btn_PermanentDelete" CssClass="but" runat="server" OnClientClick="return Permanentconfirmdelete(this.form);"
                                            OnClick="btn_PermanentDelete_Click" Visible="false" />
                                    </div>
                                </div>
                            </div>
                        </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 < GridView1.pageRowCount; i++) {
                    if (document.getElementById('ctl00_BodyContentPH_GridView1_cell' + (i + GridView1.visibleStartIndex) + '_0_chkSelect').disabled == false) {
                        document.getElementById('ctl00_BodyContentPH_GridView1_cell' + (i + GridView1.visibleStartIndex) + '_0_chkSelect').checked = true;
                        var hdnUserId = document.getElementById('ctl00_BodyContentPH_GridView1_cell' + (i + GridView1.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 < GridView1.pageRowCount; i++) {
                    document.getElementById('ctl00_BodyContentPH_GridView1_cell' + (i + GridView1.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 < GridView1.pageRowCount; i++) {
                if (document.getElementById('ctl00_BodyContentPH_GridView1_cell' + (i + GridView1.visibleStartIndex) + '_0_chkSelect').checked)
                    varTotalCheckedCount = varTotalCheckedCount + 1;
                else
                    break;
            }
            if (varTotalCheckedCount == GridView1.pageRowCount)
                document.getElementById('ctl00_BodyContentPH_GridView1_header0_chkSelectAll').checked = true;
            else
                document.getElementById('ctl00_BodyContentPH_GridView1_header0_chkSelectAll').checked = false;
        }
        else {
            if (Array.contains(removeId, hdnUserId)) {
                Array.remove(removeId, hdnUserId);
            }
            hdnSelectRow.value = removeId;

            document.getElementById('ctl00_BodyContentPH_GridView1_header0_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 = GridView1.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>
