 <%= stylesheet_link_tag 'wk-time', :plugin => "redmine_wktime" %>
  <%= javascript_include_tag 'edit', :plugin => "redmine_wktime" %>
	<script type="text/javascript">
		lblPleaseSelect = '<%=l(:actionview_instancetag_blank_option) %>'
		lblWarnUnsavedTE = '<%=l(:text_warn_on_leaving_unsaved) %>'
		decSeparator = '<%=l(:general_csv_decimal_separator) %>';
		issueField = '<%= l(:field_issue) %>';
		invalidMsg = " <%= (CGI.unescapeHTML l('activerecord.errors.messages.invalid')).html_safe %>";
		submissionack="<%= Setting.plugin_redmine_wktime['wktime_submission_ack'] %>";
		maxHourAlertMsg = "<%= l(:text_wk_warning_max_hour, :value => "#{controller.maxHour}").html_safe %>";
		minHourAlertMsg = "<%= l(:text_wk_warning_min_hour, :value => "#{controller.minHour}").html_safe %>";
		minHourperWeekAlertMsg = "<%= l(:text_wk_warning_min_hour_week, :value => "#{controller.minHourPerWeek}").html_safe %>";
		maxHourperWeekAlertMsg = "<%= l(:text_wk_warning_max_hour_week, :value => "#{controller.maxHourPerWeek}").html_safe %>";
		editUrl = '<%= raw(url_for(:controller => controller.controller_name, :action => "edit", :startday => @startday, :user_id => params[:user_id], :sheet_view => params[:sheet_view], :project_id => params[:project_id]))%>';
		breakvalue = '<%= Setting.plugin_redmine_wktime['wktime_break_time'] %>';
		leavingMsg = '<%= l(:warning_leaving_message) %>';
		<% if @renderer.showWorkTimeHeader && controller.showWorktimeHeader %>
				showWorkHeader = true;
				footerRows = 2;
				headerRows = 4;
				<% if showBilling && controller.showSpentFor%>
					hStartIndex = hStartIndex + 1 ;
				<% end %>
				<% if @renderer.showSpentOnInRow %>
					hStartIndex = hStartIndex + 1 ;
				<% end %>
				<% if controller.enterCommentInRow %>
					hStartIndex = hStartIndex + 1 ;
				<% end %>
				<% if controller.enterCustomFieldInRow(1) %>
					hStartIndex = hStartIndex + 1 ;
				<% end %>
				<% if controller.enterCustomFieldInRow(2) %>
					hStartIndex = hStartIndex + 1 ;
				<% end %>
				totalBreakTime = <%= controller.getTotalBreakTime %>;
		<% end %>
		<% if !Setting.plugin_redmine_wktime['wktime_allow_blank_issue'].blank? &&
			Setting.plugin_redmine_wktime['wktime_allow_blank_issue'].to_i == 1 %>
				allowBlankIssue = true;
		<% end %>
		<% if !Setting.plugin_redmine_wktime['wktime_enter_comment_in_row'].blank? &&
			Setting.plugin_redmine_wktime['wktime_enter_comment_in_row'].to_i == 1 %>
				commentInRow = true;
		<% end %>

	</script>

	<div id="comment-dlg">
	<!-- modified class .ui-widget-header to change the header color -->
		<span id="_edit_comm_proj_">project</span>,
		<span id="_edit_comm_iss_">issue</span>,
		<span id="_edit_comm_act_">activity</span>
		<fieldset>
		<% if Setting.plugin_redmine_wktime['wktime_enter_comment_in_row'].blank? ||
			Setting.plugin_redmine_wktime['wktime_enter_comment_in_row'].to_i == 0 %>
			<p style="display: flex;align-items: center;"><label style="padding-right: 5px"><%= l(:field_comments) %></label></b>
			<textarea name="_edit_comments_" id="_edit_comments_" value="" cols="25" rows="2"></textarea></p>
		<% end %>


		<% if !Setting.plugin_redmine_wktime['wktime_use_detail_popup'].blank? &&
			Setting.plugin_redmine_wktime['wktime_use_detail_popup'].to_i == 1 %>

			<% unless @new_custom_field_values.blank? %>
				<p><%= l(:label_custom_field_plural) %></p>
				<%
					cf_ids = ""
					@new_custom_field_values.each do |custom_value|
						custom_field = custom_value.custom_field
						#if the custom field is not setup on the row
						if !((!Setting.plugin_redmine_wktime['wktime_enter_cf_in_row1'].blank? &&
							Setting.plugin_redmine_wktime['wktime_enter_cf_in_row1'].to_i == custom_field.id) ||
							(!Setting.plugin_redmine_wktime['wktime_enter_cf_in_row2'].blank? &&
							Setting.plugin_redmine_wktime['wktime_enter_cf_in_row2'].to_i == custom_field.id))

							if cf_ids.blank?
								cf_ids = "_custom_field_values_#{custom_field.id}"
							else
								cf_ids += ",_custom_field_values_#{custom_field.id}"
							end
				%>
							<p><%= custom_field_tag_with_label '', custom_value %></p>
						<% 	end %>

				<% 	end %>
				<script type="text/javascript"> cf_ids = '<%=cf_ids%>';</script>
			<% end %>
		<% end %>

		</fieldset>

	</div>

	<div id="notes-dlg">

		<fieldset>
			<p> <label><%= l(:label_wk_reject_reason) %></label>
			<textarea name="_edit_notes_" id="_edit_notes_" value="" cols="25" rows="2"> </textarea> </p>
		</fieldset>

	</div>

	<%= render :partial => 'attendance' %>

<%= render :partial => 'row_template' %>
<%= form_tag({:controller => controller.controller_name, :action => 'update'}, :method => :post, :id => 'wktime_edit') do %>


<div style="float: left;">
<h2><%= controller.getEntityLabel %></h2>
</div>
<div style="clear: both;"></div>
<%=h hidden_field_tag('tab', "#{controller_name}") %>

<div style="overflow: auto">
	<table id="wktimeHeader">
		<tr valign="top"><td>
			<table id="wktimeStatus" class="list nowrap">
				<%= render :partial => 'edit_header' %>

				<% if !@wktime.blank? && @wktime.status == 'r' && !@wktime.notes.blank? %>
					<tr>
						<th align="right"><%=l(:label_wk_reject_reason)%></th>
						<td><%=h @wktime.notes %></td>
					</tr>
				<% end %>

				<% custom_values = @wktime.nil? ?  Wktime.new.custom_field_values : @wktime.custom_field_values %>
				<% unless custom_values.blank? %>
					<%
						# wk time custom fields
						wkcf_ids = ""
						custom_values.each do |custom_value|
							custom_field = custom_value.custom_field
							wkcf_ids += ",wktime_custom_field_values_#{custom_field.id}"
					%>
						<tr>
							<th>
								<% # Martin Dube Contribution: show required field in Wktime custom field %>
								<%= custom_field_label_tag "wktime", custom_value %>
							</th>
							<td>
								<% if @editable %>
									<%= custom_field_tag "wktime", custom_value %>
								<% else %>
									<%= custom_value.value %>
								<% end %>
							</td>
						</tr>
					<% end %>
				<% end %>
			</table>
		</td>
		<td><%= render :partial => 'wktime/edit_options' %></td>
		<td width="100%">
			<% if isChecked('te_save_geo_location') %>
			<% 	startLocations = @entries.map{ |entry|
						!entry.spent_for || (entry.spent_for.s_longitude == entry.spent_for.e_longitude && entry.spent_for.s_latitude == entry.spent_for.e_latitude) ? ["",""] :
						[ entry.spent_for.s_longitude || '', entry.spent_for.s_latitude || '', entry.project.name+ "\n"+ (entry.issue ? entry.issue.subject : "")+"\n"+entry.hours.to_s, "S" ]
					}
					endLocations = @entries.map{ |entry|
						entry.spent_for ? [ entry.spent_for.e_longitude || '', entry.spent_for.e_latitude || '', entry.project.name+ "\n"+
						(entry.issue ? entry.issue.subject : "")+"\n"+entry.hours.to_s, "E" ] : ["",""]
					}
					locations = startLocations + endLocations
					locations = [["", ""]] if locations.length == 0
			%>
				<div  id='mapContainer' style="float: right;width: 300px;height: 200px"></div>
				<%= render partial: "wkgeolocation/location_map", locals: { locations: locations } %>
			<% end %>
		</td>
		</tr>
	</table>
</div>

<%= render :partial => 'edit_issues', :locals => { :entries => @prev_template ? @prev_entries : @entries }%>

<%= render :partial => 'edit_footer' %>

<% end %>

<!-- Display Attachments Files -->
<% if controller.showAttachments %>
	<% editable = !@locked && (@wktime.nil? || @wktime.status == 'n' || @wktime.status == 'r') %>
	<% count = 0 %>
	<% @entries.each{|e| count += 1 if e.present? && e.attachments.any?} %>
	<% if count > 0 %>
		<div>
			<fieldset id="<%= 'attachment_' + @row.to_s() + '_' + @wday_index.to_s %>" class="attachment">
				<legend><%=l(:label_attachment)%></legend>
				<% @entries.each do |entry| %>
					<% if entry.present? && entry.attachments.any? && (controller.check_approvable_status && @approvable_projects.pluck(:id).include?(entry.project_id) || (@wktime.nil? || ['n'].include?(@wktime.status)) || (['s', 'a'].include?(@wktime.status) && !controller.check_approvable_status && entry.user_id == params[:user_id].to_i)) %>
							<%= attachments_links entry, { editable: editable, deletable: editable, hideImage: true, author: false } %>
					<% end %>
				<% end %>
			</fieldset>
		</div>
	<% end %>
<% end %>