<%@ page language="VB" autoeventwireup="false" inherits="Manage_EmployeesLeaveEntries, App_Web_sxxm_njl" enableEventValidation="false" %>
<%@ Register TagPrefix="obout" Namespace="Obout.Grid" Assembly="obout_Grid_NET" %>
<%@ Register TagPrefix="obout" Namespace="OboutInc.Flyout2" Assembly="obout_Flyout2_NET"%>
<%@ Register TagPrefix="uctrl" Src="~/Header.ascx" TagName="header" %>

<script type="text/javascript">	
	// Client-Side Events for Delete
	function OnBeforeDelete(record) 
	    {
	        record.Error='';
		    document.getElementById("<%=hdn_EmployeeLeaveEntryId.ClientID %>").value = record.LeaveEntryId;
	        if(confirm("Are you sure you want to delete? "))
	            return true;
	        else
	            return false;
	    }
	
	function OnDelete(record) 
	{
	    alert(record.Error);
	}
	
	function OnInsert(record) 
	{
		document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML = record.Error;
	}
	
</script>

<!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>Untitled Page</title>
    <link href="../StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body onload="IsApproved_CheckedChange();">
    <form id="form1" runat="server">
    <div>
    <uctrl:header ID="MyHeader" runat="server" />
            <table cellpadding="0" cellspacing="0" style="border-right: gray 1px solid; border-top: gray 1px solid;
                border-left: gray 1px solid; border-bottom: gray 1px solid;">
                <tr style="font-weight: bold; font-size: 14px; background-color: lightsteelblue;
                    padding-left: 5px; padding-top: 3px; padding-bottom: 3px; color: white;">
                    <td  style="font-weight: bold; font-size: 14px; background-color: lightsteelblue;padding:5px; color: white;">
                        Employee Leave Entries
                    </td>
                    
                </tr>
                
                <tr style=" background-color: lightsteelblue;">
                <td colspan="2">
                <hr />
                </td>
                </tr>
                
                
                <tr>
                    <td colspan="2" >
    <obout:Grid id="Dg_EmployeeLeaveEntries" runat="server" CallbackMode="true" EnableRecordHover="true" AllowFiltering="true" KeepSelectedRecords="true"  Serialize="true" AutoGenerateColumns="false" FolderStyle="~/styles/grid/styles/premiere_blue" AllowAddingRecords="true" ShowLoadingMessage="false"
                 OnRebind="RebindGrid" OnInsertCommand="InsertRecord"  OnDeleteCommand="DeleteRecord">
                            <ClientSideEvents OnClientInsert="OnInsert" OnBeforeClientDelete="OnBeforeDelete" OnClientDelete="OnDelete"/>
			<TemplateSettings NewRecord_TemplateId="tplAddBtn" />
			
			<Columns>
				<obout:Column ID="Column0" DataField="LeaveEntryId" Visible="false" Width="100" HeaderText="LeaveEntryId" runat="server" />
				<obout:Column ID="Column1" Visible="true" DataField="FromDate" DataFormatString="{0:dd-MMM-yyyy}"  Width="90" HeaderText="From Date" runat="server"/>
                <obout:Column ID="Column2" Visible="true" DataField="ToDate" DataFormatString="{0:dd-MMM-yyyy}"    Width="90" HeaderText="To Date" runat="server"/> 
                <obout:Column ID="Column3" DataField="EmployeeCode" Visible="true" Width="90" HeaderText="Emp Code" runat="server" />
                <obout:Column ID="Column4" DataField="EmployeeName" Visible="true" Width="100" HeaderText="Emp Name" runat="server" />
                <obout:Column ID="Column5" DataField="LeaveTypeSName" Visible="true" Width="70" HeaderText="Type" runat="server" />
                <obout:Column ID="Column6" DataField="LeaveStatus" Visible="true" Width="105" HeaderText="Leave Status" runat="server" />
                <obout:Column ID="Column7" DataField="CompanySName" Visible="true" Width="105" HeaderText="Company" runat="server" />
                <obout:Column ID="Column8" DataField="DepartmentSName" Visible="true" Width="100" HeaderText="Department" runat="server" />
                <obout:Column ID="Column9" DataField="Designation" Visible="false" Width="110" HeaderText="Designation" runat="server" />
                <obout:Column ID="Column10" DataField="CategorySName" Visible="true" Width="90" HeaderText="Category" runat="server" />
                <obout:Column ID="Column11" DataField="EmployeesStatus" Visible="false" Width="80" HeaderText="Status" runat="server" />
                <obout:Column ID="Column12" DataField="EmployementType" Visible="false" Width="80" HeaderText="Emp Type" runat="server" />
                <obout:Column ID="Column13" DataField="IsApproved" Visible="false" Width="80" HeaderText="IsApproved" runat="server" />
                <obout:Column ID="Column14" DataField="ApprovedBy" Visible="false" Width="80" HeaderText="ApprovedBy" runat="server" />
                <obout:Column ID="Column15" DataField="Remarks" Visible="false" Width="80" HeaderText="Remarks" runat="server" />
                <obout:Column ID="Column16" DataField="LeaveTypeId" Visible="false" Width="80" HeaderText="LeaveTypeId" runat="server" />
                <obout:Column ID="Column17" DataField="EmployeeId" Visible="false" Width="80" HeaderText="Emp Type" runat="server" />
                <obout:Column ID="Column18" Visible="true" Width="125" SortOrder="Desc" HeaderText="Approval Status" runat="server" ><TemplateSettings TemplateId="tplApprovalStatus" /></obout:Column>
                <obout:Column ID="Column19" DataField="LastModifiedBy" HeaderText="Modified By" Visible="true" Width="98"  runat="server" />
                <obout:Column ID="Column20" Visible="false"  Width="90" HeaderText="From Date" runat="server"> <TemplateSettings TemplateId="TP_FromDateFormat" /></obout:Column>
                <obout:Column ID="Column21" Visible="false" Width="90" HeaderText="To Date" runat="server"> <TemplateSettings TemplateId="TP_ToDateFormat" /></obout:Column>
                <obout:Column  Width="45" HeaderText="Edit"  AllowEdit="false" AllowDelete="false" Visible="true" ><TemplateSettings TemplateId="tplEditeLeaveEntriesBtn" /></obout:Column>
                <obout:Column  Width="50" HeaderText="Delete" AllowEdit="false" AllowDelete="true" Visible="true" ></obout:Column>
			</Columns>					
			<Templates>
			
			<obout:GridTemplate runat="server" ID="TP_FromDateFormat">
			                    <Template>
			                        <%#ParseDateTime(Container.DataItem.Item("FromDate"))%>
			                    </Template>
			                </obout:GridTemplate>
			                
			                 <obout:GridTemplate runat="server" ID="TP_ToDateFormat">
			                    <Template>
			                        <%#ParseDateTime(Container.DataItem.Item("ToDate"))%>
			                    </Template>
			                </obout:GridTemplate>
			                
			     <obout:GridTemplate runat="server" ID="tplEditeLeaveEntriesBtn">
			        <Template>
			            <a href="javascript: //" id="grid_link_<%# Container.PageRecordIndex %>" onclick="attachFlyoutToLink(this,'Update')" class="ob_gAL"><%#CheckPermissionsEdit("Edit")%></a>
			        </Template>
			    </obout:GridTemplate>
			    
			    <obout:GridTemplate runat="server" ID="tplDeleteLeaveEntriesBtn">
			        <Template>
			            <a href="javascript: //" id="grid_link_<%# Container.PageRecordIndex %>" class="ob_gAL">Delete</a>
			        </Template>
			    </obout:GridTemplate>
			    
			    
			     <obout:GridTemplate runat="server" ID="tplAddBtn">
			        <Template>
			            <asp:Hyperlink runat="server" CssClass="ob_gAL" Text='<%#CheckPermissions("Assign Leave Entries")%>'  NavigateUrl='<%# "~/manage/AssignEmployeesLeaveEntries.aspx"%>' ID="AA1" />
			        </Template>
			    </obout:GridTemplate>
			    
			      <obout:GridTemplate runat="server" ID="tplApprovalStatus" >
                                    <Template>
                                        <%#ParseApprovalStatus(Container.DataItem.Item("IsApproved"), Container.DataItem.Item("ApprovedBy"))%>
                                    </Template>
                                </obout:GridTemplate>
                                
                                
			</Templates>
		</obout:Grid>
	
	</td>
                </tr>
            </table>	
            
            <obout:Flyout runat="server" ID="Flyout1" Align="left" Position="BOTTOM_left" CloseEvent="NONE" OpenEvent="NONE" DelayTime="500">
		    <table class="rowEditTable">
                    <tr>
                        <td >
                            <fieldset>
                                <legend>Update Employee Leave Entries</legend>
                                <table>
                                    <tr>
                                        <td style="width: 528px">
                                            Employee Name&nbsp;
                                            <asp:TextBox ID="txt_EmployeeName" runat="server" Width="422px" Enabled="false"   ></asp:TextBox>
                                        </td>
                                    </tr>
                                    
                                    <tr>
                    <td>
                    <table>
                    <tr>
                    <td>
                    <asp:RadioButtonList ID="rbtn_LeaveDays" runat="server" RepeatDirection="Horizontal" Enabled="false">
                        <asp:ListItem Value="FullDay" Selected="True" onclick="AssignLeaveDays_onClick();">Full Day</asp:ListItem>
                        <asp:ListItem Value="3/4Day"  onclick="AssignLeaveDays_onClick();">3/4 Day</asp:ListItem>
                        <asp:ListItem Value="HalfDay"  onclick="AssignLeaveDays_onClick();">1/2 Day</asp:ListItem>
                        <asp:ListItem Value="QuarterDay"  onclick="AssignLeaveDays_onClick();">1/4 Day</asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                    <td>
                     <asp:CheckBox ID="chk_IsApproved" runat="server" Text="Is Approved"   onclick="IsApproved_CheckedChange();" />
                    </td>
                    </tr>
                    </table>
                    
                    </td>
                    </tr>
                                     <tr>
                                     <td style="width: 528px">
                                            From Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <select id="drp_FromDateday"  runat="server" style="width:46px;">
                                            </select>&nbsp;&nbsp;<select id="drp_FromDatemonth" runat="server" style="width:48px;"></select>
                                            &nbsp;&nbsp;<select id="drp_FromDateYear" runat="server" 
                                                  style="width:69px;" >
                                            </select>&nbsp;Approved By&nbsp;<asp:TextBox ID="txt_ApprovedBy" runat="server" Width="150px" Enabled="false"   ></asp:TextBox>
                                            
                                        </td>
                                    </tr>
                                     <tr>
                                        <td style="width: 528px">
                                            To Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            <select id="drp_ToDateday"   runat="server">
                                            </select>&nbsp;&nbsp;<select id="drp_ToDatemonth" runat="server"  ></select>
                                            &nbsp;&nbsp;<select id="drp_ToDateYear" runat="server"  >
                                            </select>&nbsp;Leave Type&nbsp;&nbsp;&nbsp;<select id="drp_LeaveType" runat="server"    style="width: 155px">
                                            </select>
                                        </td>
                                    </tr>
                                     <tr>
                                        <td style="width: 528px">
                                            Remarks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="txt_Remarks" runat="server" TextMode="MultiLine" Width="421px"></asp:TextBox>
                                            
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" colspan="2">
                            <asp:Label runat="server" foreColor="red" EnableViewState="false" ID="Lbl_InvalidError"></asp:Label>
                            <input id="btn_Save" type="button" value="Save" onclick="javascript:btn_Save_onclick();" />&nbsp;&nbsp;<input
                                id="btn_Cancel" type="button" value="Close" onclick="javascript:closeFlyout();" />
                                <asp:HiddenField ID="hdn_EmployeeLeaveEntryId" runat="server" />
                        <asp:HiddenField ID="hdn_EmployeeId" runat="server" />
                        <asp:HiddenField ID="hdn_LoginEmpName" runat="server" />
                                
                        </td>
                    </tr>
                </table>
			</obout:Flyout>
			
    </div>
    </form>
    
     <script runat="server">
        Function CheckPermissions(ByVal Action As String) As String
            If Not Session.Item("LoginUser") Is Nothing Then
            
                 If CType(Session("LoginUser"), eTimeTrackLiteLibrary.Data.Admin.User).PermissionNameList.Contains("AddLeaveEntries") Then
                     Return Action
                 End If
                Return ""
            End If
        End Function
        
         Function CheckPermissionsEdit(ByVal Action As String) As String
            If Not Session.Item("LoginUser") Is Nothing Then
                If CType(Session("LoginUser"), eTimeTrackLiteLibrary.Data.Admin.User).PermissionNameList.Contains("EditLeaveEntries") Then
                    Return Action
                End If
                Return ""
            End If
         End Function
         
         Function ParseApprovalStatus(ByVal IsApproved As String, ByVal ApprovedBy As String)
             If IsApproved = "-1" Then
                 Return "Approved(" + ApprovedBy + ")"
             Else
                 Return "Not Approved"
             End If
           
            
         End Function
        
         Function ParseDateTime(ByVal DateValue As Date) As String
             Return DateValue.ToString("yyyy-MM-dd")
         End Function
         
    </script>
    
    <script type="text/javascript">
    
        function AssignLeaveDays_onClick1()
            {
                 if(document.getElementById("Flyout1_rbtn_LeaveDays_0").checked)
                   {
                       document.getElementById('<%=drp_ToDateday.ClientID %>').disabled=false;
                       document.getElementById('<%=drp_ToDatemonth.ClientID %>').disabled=false;
                       document.getElementById('<%=drp_ToDateYear.ClientID %>').disabled=false;
                   }
                   
                   else if(document.getElementById("Flyout1_rbtn_LeaveDays_1").checked || document.getElementById("Flyout1_rbtn_LeaveDays_2").checked || document.getElementById("Flyout1_rbtn_LeaveDays_3").checked)
                   {
                       document.getElementById('<%=drp_ToDateday.ClientID %>').disabled=true;
                       document.getElementById('<%=drp_ToDatemonth.ClientID %>').disabled=true;
                       document.getElementById('<%=drp_ToDateYear.ClientID %>').disabled=true;
                   }
            }
            
            function AssignLeaveDays_onClick()
            {
                 
            }
            
		    function attachFlyoutToLink(oLink,Action)
		     {	
		     try 
		     {	
		        ClearFlyout();
		       <%=Flyout1.getClientID()%>.AttachTo(oLink.id);		            		            
		       <%=Flyout1.getClientID()%>.Open();
		            populateEditControls(oLink.id.toString().replace("grid_link_", ""));
              }
            catch(ex){}
		    }
		    
		    function ClearFlyout()
		    {
		        document.getElementById("<%=Lbl_InvalidError.ClientID %>").innerHTML = '';
	            document.getElementById("<%=hdn_EmployeeLeaveEntryId.ClientID %>").value = '0';
	            document.getElementById("<%=hdn_EmployeeId.ClientID %>").value = '0';
                    document.getElementById( "<%=txt_Remarks.ClientID %>").value='';
	            
		    }
		    
		    
		function closeFlyout() 
		    {
		        <%=Flyout1.getClientID()%>.Close();
		    }
		    
		    function populateEditControls(iRecordIndex) 
		    {	
		            var FromDate=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[20].Value;
		            var ToDate=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[21].Value;
		            var EmployeeName=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[4].Value;
		            var LeaveTypeId=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[16].Value;
		            var LeaveTypeId=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[16].Value;
		            var ApprovedBy=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[14].Value;
		            var IsApproved=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[13].Value;
		            var Remarks=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[15].Value.replace(/<BR>/gi,'\n');
		            var LeaveStatus=Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[6].Value;
		            
	                SetValueInDropDown(document.getElementById("<%=drp_FromDateday.ClientID %>"),document.getElementById("<%=drp_FromDatemonth.ClientID %>"),document.getElementById("<%=drp_FromDateYear.ClientID %>"),FromDate);
	                SetValueInDropDown(document.getElementById("<%=drp_ToDateday.ClientID %>"),document.getElementById("<%=drp_ToDatemonth.ClientID %>"),document.getElementById("<%=drp_ToDateYear.ClientID %>"),ToDate);
                    document.getElementById( "<%=txt_EmployeeName.ClientID %>").value =EmployeeName;
                    if(IsApproved=='-1')
                        document.getElementById( "<%=chk_IsApproved.ClientID %>").checked=true;
                    else
                        document.getElementById( "<%=chk_IsApproved.ClientID %>").checked=false;
                    document.getElementById( "<%=txt_ApprovedBy.ClientID %>").value=ApprovedBy;
                    document.getElementById( "<%=txt_Remarks.ClientID %>").value=Remarks;
                    document.getElementById( "<%=drp_LeaveType.ClientID %>").value=LeaveTypeId;
                
                  if(LeaveStatus=='FullDay')
                  document.getElementById("Flyout1_rbtn_LeaveDays_0").checked=true;
                  
                  else if(LeaveStatus=='3/4Day')
                  document.getElementById("Flyout1_rbtn_LeaveDays_1").checked=true;
                  
                  else if(LeaveStatus=='HalfDay')
                  document.getElementById("Flyout1_rbtn_LeaveDays_2").checked=true;
                  
                  else if(LeaveStatus=='QuarterDay')
                  document.getElementById("Flyout1_rbtn_LeaveDays_3").checked=true;
                
                  document.getElementById("<%=hdn_EmployeeLeaveEntryId.ClientID %>").value = Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[0].Value;
	              document.getElementById("<%=hdn_EmployeeId.ClientID %>").value = Dg_EmployeeLeaveEntries.Rows[iRecordIndex].Cells[17].Value;
                  AssignLeaveDays_onClick();
		    }
		    
		   function SetValueInDropDown(ddobject,mmobject,yyobject,value)
		    {
		        var Day=value.split('-')[2].replace(/^\s+|\s+$/g,"");
                var Month=value.split('-')[1].replace(/^\s+|\s+$/g,"");
                var Year=value.split('-')[0].replace(/^\s+|\s+$/g,"");
                ddobject.value=Day;
                mmobject.value=Month;
                yyobject.value=Year;
		    }
		    
		     
		    
		   
		      
		     function btn_Save_onclick()
		     {
		          var oRecord = new Object();
		        
                  if(document.getElementById("Flyout1_rbtn_LeaveDays_0").checked)
                  oRecord.LeaveStatus='Full Day';
                  
                  else if(document.getElementById("Flyout1_rbtn_LeaveDays_1").checked)
                  oRecord.LeaveStatus='3/4 Day';
                  
                  else if(document.getElementById("Flyout1_rbtn_LeaveDays_2").checked)
                  oRecord.LeaveStatus='1/2 Day';
                  
                  else if(document.getElementById("Flyout1_rbtn_LeaveDays_3").checked)
                  oRecord.LeaveStatus='Quarter Day';
                  
                  oRecord.Error='';
		          Dg_EmployeeLeaveEntries.executeInsert(oRecord);
		     }
		     
		     function IsApproved_CheckedChange()
                {
                    var object=document.getElementById('<%=chk_IsApproved.ClientID %>');
                    if(object.checked)
                    {
                        document.getElementById('<%=txt_ApprovedBy.ClientID %>').value=document.getElementById('<%=hdn_LoginEmpName.ClientID %>').value;
                    }    
                    else
                    {
                        document.getElementById('<%=txt_ApprovedBy.ClientID %>').disabled=true;
                        document.getElementById('<%=txt_ApprovedBy.ClientID %>').value='';
                     }   
                }
		     
		     
		    
            
		
    </script>
</body>
</html>
