<%= title l(:label_leave_request) %>
<%= render partial: "wkattendance/render_hr_tabs" %>

<% 	group_id =session[controller_name].try(:[], :group_id)
	userID =session[controller_name].try(:[], :user_id)
	statusList = {'' => ''}.merge(getLeaveStatus)
%>
<fieldset>
	<legend><%= l(:label_filter_plural) %></legend>
	<div style="float:right">
		<%= link_to l(:label_new_leave_request), url_for(controller: controller_name, action: 'edit'), :class => 'icon icon-add' %>
	</div>
	<%= form_tag({controller: controller_name, action: 'index'}, method: :get) do %>
		<%= hidden_field_tag("searchlist", controller_name) %>
		<%= hidden_field_tag('tab', controller_name) %>
		<% period = session[:wkleaverequest].try(:[], :period) %>
		<% if isLeaveReqAdmin %>
			<label><%=l(:label_group_plural)%></label>&nbsp;
			<%= select_tag('group_id', options_for_select( [["", 0]] + (@groups.collect {|p| [p.name, p.id ]}),
						:selected => group_id), :onchange => "grpChanged(this, #{User.current.id}, true);", :style=> "width:300px;") %>&nbsp;
			<label><%=l(:label_member)%></label>&nbsp;
			<%= select_tag('user_id', options_for_select( [[l(:all_users_for_select), 0]] + @members, :selected => userID),
						:style=> "width:200px;") %>&nbsp;
		<% end %>
		<label><%= l(:label_leave_type) %></label>&nbsp;
		<%= select_tag('leave_type', options_for_select(get_leave_type.unshift(['','']), session[controller_name].try(:[], :leave_type))) %>&nbsp;
		<label><%= l(:field_status) %></label>&nbsp;
		<%= select_tag('lveStatus', options_for_select(statusList.invert, session[controller_name].try(:[], :lveStatus))) %>&nbsp;
		<fieldset id="date-range" class="collapsible">
			<legend onclick="toggleFieldset(this);" class="icon icon-expanded"><%= l(:label_date_range) %></legend>
			<div>
				<%= radio_button_tag 'period_type', '1', !@free_period, :onclick => '$("#from,#to").attr("disabled", true); $("#period").removeAttr("disabled");' %>
				<%= select_tag 'period', options_for_period_select(period),
										:onchange => 'this.form.submit();',
										:onfocus => '$("period_type_1").checked = true;',
										:disabled => @free_period %>
				<%= radio_button_tag 'period_type', '2', @free_period, :onclick => '$("#from,#to").removeAttr("disabled"); $("#period").attr("disabled", true);' %>
				<span onclick="$('period_type_2').checked = true;">
				<%= l(:label_date_from_to, :start => ( date_field_tag('from', @from, {:id => 'from', :size => 10, :disabled => !@free_period,
				 		:onchange =>"dateRangeValidation('from', 'to')"}) +
						calendar_for('from')), :end => ( date_field_tag('to', @to, {:id => 'to', :size => 10, :disabled => !@free_period,
						 :onchange =>"dateRangeValidation('from', 'to')"}) +
						calendar_for('to'))).html_safe %>
				</span>
			</div>
		</fieldset>
		<div>
			<%= submit_tag l(:button_apply), class: "small", name: nil %>
			<%= link_to l(:button_clear), {tab: controller_name, clear: true}, class: 'icon icon-reload' %>
		</div>
	<% end %>
</fieldset>

<% if @leaveReqEntires.present? %>
	<%= render :partial => 'leaverequest_list'%>
	<span class="pagination"><%= pagination_links_full @leave_pages, @leave_count %></span>
	<% other_formats_links do |f| %>
		<%= f.link_to_with_query_parameters 'CSV', {} %>
	<% end %>
<% else %>
	<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>