<%= javascript_include_tag 'index', :plugin => "redmine_wktime" %>
<%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %>
<script type="text/javascript">
	prevTab = 'tab-<%= "#{controller_name}" %>';
	grpUrl="<%= "#{url_for(:controller => controller_name, :action => 'getMembersbyGroup')}" %>";
	userUrl="<%= "#{url_for(:controller => controller_name, :action => 'getusers')}" %>";
	rSubEmailUrl="<%= "#{url_for(:controller => controller_name, :action => 'sendSubReminderEmail')}" %>";
	rAppEmailUrl="<%= "#{url_for(:controller => controller_name, :action => 'sendApprReminderEmail')}" %>";
</script>
<% if @currentUser_loggable_projects.present? %>
	<div class="contextual">
	<% if (validateERPPermission('A_TE_PRVLG')) %>
		<%= link_to l(:label_lock), url_for(:controller => controller_name, :action => 'lockte'), :class => 'icon icon-time-add' %>
	<% end %>
	<%= link_to l(:"button_new_#{controller_name}"), url_for(action: 'edit', user_id: User.current.id, startday: Date.today, prev_template: true), :class => 'icon icon-time-add' %>
	</div>
<% end %>
<% if !@manage_projects.blank? %>

	<div id="reminder-email-dlg">
		<fieldset>
			<p>
				<label><%= l(:label_wk_reminder_notes) %></label>
				<textarea name="email_notes" id="email_notes" value="" style="width: 300px;min-height: 35px;"> </textarea>
			</p>
			<p><%= radio_button_tag 'reminder', '1' %><span><%= l(:label_wk_sub_reminder) %></span></p>
			<p><%= radio_button_tag 'reminder', '2' %><span><%= l(:label_wk_appr_reminder) %></span></p>
		</fieldset>
	</div>

<% end %>
<%= form_tag({:controller => controller_name, :action => 'index'}, :method => :get, :id => 'query_form') do %>

<%=h hidden_field_tag('tab', controller_name) %>
<%= hidden_field_tag "searchlist", controller_name %>

<%
	projectid = session[controller_name].try(:[], :project_id)
	groupid =session[controller_name].try(:[], :group_id)
	userid = session[controller_name].try(:[], :user_id)
	status = session[controller_name].try(:[], :status)
	filter_type = session[controller_name].try(:[], :filter_type)
	projGrp =false
	if filter_type == '1' || filter_type.blank?
		projGrp = true
	end
%>

<% #filters = call_hook(:view_te_filter) %>
<% if isSupervisorApproval %>
	<%#=	filters %>
	<%= render :partial => 'wktime/supervisor_index' %>
<% else %>
<% if !@manage_view_spenttime_projects.blank? %>
<div class="div-left">
<table>
<script type="text/javascript">
$(document).ready(function()
{
	<% if projGrp %>
		$("#group_id").attr("disabled", true);
		$("#project_id").removeAttr("disabled");
	<% else %>
		$("#project_id").attr("disabled", true);
		$("#group_id").removeAttr("disabled");
	<% end %>

});
 </script>
<tr>
<th><%= radio_button_tag 'filter_type', '1', projGrp,
 :onclick => 'progrpChanged(this, "#{User.current.id}", true);$("#user_id").removeAttr("disabled");$("#group_id").attr("disabled", true);$("#project_id").removeAttr("disabled");' %>
<%=l(:field_project)%></th>
<td class="project" align="left"><%=h select_tag('project_id',
	options_for_select(options_for_wktime_project(@manage_view_spenttime_projects),
	:selected => !projectid.nil? ? projectid.to_i: @selected_project.id),:disabled => @use_group,
	:onchange => "projChanged(this, #{User.current.id}, true);", :style=> "width:300px;") %></td>
</tr>
<% if !@groups.blank? %>
<tr>
<th><%= radio_button_tag 'filter_type', '2', !projGrp,
:onclick => 'progrpChanged(this, "#{User.current.id}", true);$("#user_id").removeAttr("disabled");$("#group_id").removeAttr("disabled");$("#project_id").attr("disabled", true);' %>
<%=l(:label_group_plural)%></th>
<td>
	<%=h select_tag('group_id',
	options_for_select( @groups.collect {|p| [p.name, p.id ]},
	:selected => (groupid.nil? ? 0 : groupid)),:disabled => !@use_group,
	:onchange => "grpChanged(this, #{User.current.id}, true);", :style=> "width:300px;") %>
</td>
</tr>
<% end %>
<tr>
<th><%=l(:label_member)%></th>
<td>
<%# show the blank value if more than one user is in the list %>
<%=h select_tag('user_id',
	options_for_select( [[l(:all_users_for_select),"0"]] + (@members.blank? ? [] : @members),
		:selected => userid.nil? ? (@user.nil? ? User.current.id : @user.id) : userid),
	:onchange => 'this.form.submit();', :style=> "width:200px;") %></td>
</tr>

</table>
</div>
<% end %>
<% end %>

<div id="rightMenu" class="div-right">
<table>
<tr>
<th valign="top"><%=l(:field_status)%></th>
<td class="status" align="left"><%=h select_tag('status',
	options_for_select(options_wk_status_select(status),
	:selected => status.nil? ? 0 : status.to_s ),
	:multiple=> true) %></td>
</tr>
</table>
</div>
<div style="clear:both"></div>
<%= render :partial => 'wktime/date_range' %>

<% end %>

<% if @entries.present? %>
	<div class="total-hours">
		<p><%= l(:label_total) %>: <%= "#{@unit}" %>&nbsp;<%= controller.total_all(@total_hours) %></p>
	</div>
	<%= render :partial => 'wktime/list', :locals => { :entries => @entries }%>
	<span class="pagination"><%= pagination_links_full @entry_pages, @entry_count %></span>
	<% other_formats_links do |f| %>
		<%= f.link_to_with_query_parameters 'CSV' %>
		<%= f.link_to_with_query_parameters 'PDF' %>
	<% end %>
<% else %>
	<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>