<%= 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) %>';
		submissionack="<%= Setting.plugin_redmine_wktime['wktime_submission_ack'] %>";
		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]))%>';
		leavingMsg = '<%= l(:warning_leaving_message) %>';
		
		<% 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> <label><%= l(:field_comments) %></label>
			<textarea name="_edit_comments_" id="_edit_comments_" value="" cols="25" rows="2"> </textarea> </p>
		<% 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 => 'wktime/row_template' %>

<%= form_tag({:controller => 'wkexpense', :action => 'update'}, :method => :post, :id => 'wktime_edit') do %>
<%=h hidden_field_tag('tab', "#{controller_name}") %>
<h2><%= l(:label_wkexpense) %></h2>

<div style="overflow: auto">
	<table id="wktimeHeader">
		<tr valign="top"><td>
			<table id="wktimeStatus" class="list nowrap">
			<%= render :partial => 'wktime/edit_header' %>
			<% if !@wktime.blank? && @wktime.status == 'r' && !@wktime.notes.blank? %>
				<tr>
				<th align="left"><%=l(:label_wk_reject_reason)%></th>
				<td><%=h @wktime.notes %>
				</td>
				</tr>
			<% 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 => 'wktime/edit_issues', :locals => { :entries => @prev_template ? @prev_entries : @entries }%>

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

<% end %>

<!-- Display Attachments Files -->
<% 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 %>