<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" />
    <telerik:RadCodeBlock ID="QSCodeBlk" runat="server">

        <script type="text/javascript">

            function ValidateFilter(sender, eventArgs)
            {
                var arguments = eventArgs.get_commandArgument().split("|");
                var columnName = arguments[0];
                var valueEnteredIntoFilterControl = arguments[1];

                if (columnName == "WeekEnding")
                {
                    if (valueEnteredIntoFilterControl != "")
                        if (isNaN(Date.parse(valueEnteredIntoFilterControl)))
                            eventArgs.set_cancel(true);
                }

            }


            function applySortForSP(sender, eventArgs)
            {
                var masterTable = $find("<%= gvSPInbox.ClientID %>").get_masterTableView();

                if (eventArgs.get_gridColumn().get_uniqueName() != "ShowDetails")
                {
                    masterTable.sort(eventArgs.get_gridColumn().get_uniqueName());
                }
            }

            function rowDoubleClickForSP(sender, eventArgs)
            {

                __doPostBack('<%= this.UniqueID %>', eventArgs.get_itemIndexHierarchical());

            }     
        </script>

    </telerik:RadCodeBlock>
</head>
<body>
    <form id="form1" runat="server">
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
            </Scripts>
        </telerik:RadScriptManager>

        <script type="text/javascript">
		//Put your JavaScript code here.
        </script>

        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        </telerik:RadAjaxManager>
        <div class="contentArea" id="sub2profile" style="clear: both; border-left: 0px; border-right: 0px">
            <table width="100%">
                <tr>
                    <td align="left" style="padding-bottom: 10px; padding-left: 5px;">
                        <asp:Label runat="server" ID="lblAddTimeSheet" Text=" you can`t Add new timesheet for one of the following:<br><menu><li>You have saved timesheet</li></menu>" />
                    </td>
                    <td align="right" style="padding-bottom: 10px;">
                        <asp:Button runat="server" ID="btnAddTimesheet" Text="Add Timesheet" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <telerik:RadGrid ID="gvSPInbox" AllowPaging="True" AllowSorting="True" PageSize="100"
                            Skin="Default" AllowFilteringByColumn="true" runat="server" AutoGenerateColumns="False">
                            <GroupingSettings CaseSensitive="false" />
                            <MasterTableView DataKeyNames="TimesheetID">
                                <NoRecordsTemplate>
                                    <asp:Label ID="Label1" Text="No results found." runat="server" />
                                </NoRecordsTemplate>
                                <Columns>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" FilterControlWidth="30px" HeaderStyle-Width="65px"
                                        ItemStyle-Width="65px" DataField="TimesheetID" HeaderText="Auto Control Number"
                                        UniqueName="TimesheetID" CurrentFilterFunction="EqualTo" ShowFilterIcon="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn HeaderStyle-Width="95px" ItemStyle-Width="95px" DataField="IntegerRegionCode"
                                        HeaderText="Region Code" UniqueName="IntegerRegionCode" AllowFiltering="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" FilterControlWidth="60px" HeaderStyle-Width="95px"
                                        ItemStyle-Width="95px" DataField="TerritoryCode" HeaderText="Terr" UniqueName="TerritoryCode"
                                        CurrentFilterFunction="EqualTo" ShowFilterIcon="false">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridDateTimeColumn FilterControlWidth="100px" HeaderStyle-Width="100px"
                                        ItemStyle-Width="100px" DataFormatString="{0:MM-dd-yyyy}" DataField="WeekEnding"
                                        SortExpression="WeekEnding" UniqueName="WeekEnding" HeaderText="Week Ending"
                                        AutoPostBackOnFilter="true" ShowFilterIcon="false" CurrentFilterFunction="EqualTo">
                                    </telerik:GridDateTimeColumn>
                                    <telerik:GridBoundColumn AutoPostBackOnFilter="true" ItemStyle-Width="70px" FilterControlWidth="70px"
                                        HeaderStyle-Width="70px" DataField="Status" HeaderText="Status" UniqueName="Status"
                                        CurrentFilterFunction="EqualTo" ShowFilterIcon="false">
                                        <FilterTemplate>
                                            <telerik:RadComboBox Width="70px" ID="rcbStatusFilter" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("Status").CurrentFilterValue %>'
                                                runat="server" OnClientSelectedIndexChanged="StatusIndexChanged" AppendDataBoundItems="true">
                                                <Items>
                                                    <telerik:RadComboBoxItem />
                                                    <telerik:RadComboBoxItem Value="1" Text="Saved" />
                                                    <telerik:RadComboBoxItem Value="2" Text="Pending" />
                                                    <telerik:RadComboBoxItem Value="3" Text="Rejected" />
                                                    <telerik:RadComboBoxItem Value="4" Text="Approved" />
                                                </Items>
                                            </telerik:RadComboBox>
                                            <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server">

                                                <script type="text/javascript">
                                                function StatusIndexChanged(sender, args)
                                                {
                                                    var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                    tableView.filter("Status", args.get_item().get_value(), "EqualTo");

                                                }
                                                </script>

                                            </telerik:RadScriptBlock>
                                        </FilterTemplate>
                                    </telerik:GridBoundColumn>
                                    <telerik:GridBoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
                                        FooterStyle-HorizontalAlign="Left" HeaderStyle-Width="100px" ItemStyle-Width="100px"
                                        AllowFiltering="false" DataField="RejectionDesc" HeaderText="Rejection Desc"
                                        UniqueName="RejectionDesc">
                                    </telerik:GridBoundColumn>
                                    <telerik:GridTemplateColumn UniqueName="ShowDetails" AllowFiltering="False" HeaderStyle-Width="35px"
                                        ItemStyle-Width="35px" HeaderStyle-Font-Underline="false">
                                        <ItemTemplate>
                                            <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="btn_arrow.gif" />
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
                                </Columns>
                            </MasterTableView>
                            <ClientSettings ClientEvents-OnColumnClick="applySortForSP" ClientEvents-OnRowDblClick="rowDoubleClickForSP">
                                <Selecting AllowRowSelect="true" />
                                <ClientEvents OnCommand="ValidateFilter" />
                            </ClientSettings>
                            <HeaderStyle Font-Bold="true" Font-Underline="true" />
                        </telerik:RadGrid>
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>
