<%= stylesheet_link_tag "wk-time", :plugin => "redmine_wktime" %>
<% show_on_map = session[controller_name].try(:[], :show_on_map) %>
<div class="autoscroll">
	<table class="list time-entries" style="<%= "width:37%; float:left;" if show_on_map %>">
		<thead>
		  <% if action_name == "index" %>
				<tr>
					<%= sort_header_tag("activity_type", :caption => l(:label_activity_type), class: "lbl-txt-align") if !controller.is_referral && !show_on_map %>
					<%= sort_header_tag("subject_name", :caption => l(:field_subject), class: "lbl-txt-align") %>
					<%= sort_header_tag("status", :caption => l(:field_status), class: "lbl-txt-align") %>
					<%= sort_header_tag("parent_type", :caption => l(:label_relates_to), class: "lbl-txt-align") if !show_on_map %>
					<%= sort_header_tag("start_date", :caption => l(:label_start_date_time), class: "lbl-txt-align") %>
					<%= sort_header_tag("end_date", :caption => l(:label_end_date_time), class: "lbl-txt-align") if !controller.is_referral && !show_on_map %>
					<%= sort_header_tag("assigned_user_id", :caption => l(:field_assigned_to), class: "lbl-txt-align") %>
					<%= sort_header_tag("updated_at", :caption => l(:field_updated_on), class: "lbl-txt-align") if !show_on_map %>
					<th></th>
				</tr>
		  <% else %>
				<tr>
					<% unless controller.is_referral %><th class="lbl-txt-align"><%= l(:label_activity_type) %></th><% end %>
					<% if controller.is_referral %><th class="lbl-txt-align"><%= l(:field_type) %></th><% end %>
					<th class="lbl-txt-align"><%= l(:field_subject) %></th>
					<th class="lbl-txt-align"><%= l(:field_status) %></th>
					<th class="lbl-txt-align"><%= l(controller.is_referral ? :label_rating : :label_relates_to) %></th>
					<th class="lbl-txt-align"><%= l(:label_start_date_time) %></th>
					<% unless controller.is_referral %><th class="lbl-txt-align"><%= l(:label_end_date_time) %></th><% end %>
					<th class="lbl-txt-align"><%=  controller.is_referral ? l(:label_interviewer) : l(:field_assigned_to) %></th>
					<th class="lbl-txt-align"><%= l(:field_updated_on) %></th>
					<th></th>
				</tr>
		  <% end %>
		</thead>
		<tbody>
			<% unless activities.blank? %>
				<% activities.each do |entry| %>
					<tr>
						<% if !show_on_map && !controller.is_referral %>
							<td class="lbl-txt-align"><%=h acttypeHash[entry.activity_type] %></td>
						<% end %>
						<% if !show_on_map && controller.is_referral %><td class="lbl-txt-align"><%= entry&.interview_type&.name %></td><% end %>
						<td class="lbl-txt-align"><%=h entry.name %></td>
						<td class="lbl-txt-align">
							<%= controller.is_referral ? rf_status[entry.status] : (["M", "C"].include?(entry.activity_type) ? meetCallStatusHash[entry.status] : taskStatusHash[entry.status]) %>
						</td>
						<% if !show_on_map %>
							<td class="lbl-txt-align"><%=h controller.is_referral ? entry.rating : relatedHash[entry.parent_type] %></td>
						<% end %>
							<td class="lbl-txt-align"><%=h entry&.start_date&.localtime&.strftime("%Y-%m-%d %H:%M:%S") %></td>
						<% if !controller.is_referral && !show_on_map %>
							<td class="lbl-txt-align"><%=h entry&.end_date&.localtime&.strftime("%Y-%m-%d %H:%M:%S") %></td>
						<% end %>
						<td class="lbl-txt-align"><%=h entry.assigned_user.name unless entry.assigned_user.blank? %></td>
						<% if !show_on_map %>
							<td class="lbl-txt-align"><%=h entry&.updated_at&.localtime&.strftime("%Y-%m-%d %H:%M:%S") %></td>
						<% end %>
						<td class="lbl-txt-align">
							<%= link_to image_tag("edit.png"),
								{controller: "wkcrmactivity", action: "edit", activity_id: entry.id, tab: "wkcrmactivity", controller_from: controller_name, action_from: action_name, id: entry.id},
								title: l(:button_edit) if !controller.is_referral || controller.deletePermission %>
							<% if controller.deletePermission %>
								<%= link_to image_tag("delete.png"),
									{controller: "wkcrmactivity", action: "destroy", activity_id: entry.id, tab: "wkcrmactivity", controller_from: controller_name, action_from: action_name, id: entry.id},
									data: {confirm: l(:text_are_you_sure)}, method: :delete, title: l(:button_delete) %>
							<% end %>
						</td>
					</tr>
				<% end %>
			<% end %>
		</tbody>
	</table>

	<% if show_on_map %>
		<%= render partial: "wkgeolocation/show_on_map", locals: { entries: activities, model: "activity", height: "95%", width: "62%" } %>
	<% end %>
</div>