<!--[form:task]-->
<p>
<% if @task.backlog.nil? || @task.new_record? %>
  <label for="task_backlog_id"><%=l :backlog%></label><br/>
  <%= select 'task', 'backlog_id', [['', '']] + @backlogs.map{|backlog| [backlog.name, backlog.id]}, {}, :onchange => "form.action = '#{url_for}'; form.submit();" %>
<% else %>
  <label for="task_backlog_id"><%=l :backlog%></label>:
  <%=hidden_field 'task', 'backlog_id' %><%=detour_to h(@task.backlog.name), :controller => 'backlogs', :action => :show, :id => @task.backlog_id %>
<% end %>
<% if @task.backlog %>
  <%=image_detour_to('clipboard.png', "#{l(:backlog)} #{@task.backlog.name}", {:controller => 'backlogs', :action => :edit, :id => @task.backlog}, {:class => 'image-submit', :style => 'vertical-align: bottom'}) %>
<% end %>
<%=detour_to l(:new_backlog), :controller => 'backlogs', :action => :new %>
</p>


<% if @task.backlog && @task.backlog.enable_periods? %>
<p><label for="task_period_id"><%=l :period%></label><br/>
<%= select 'task', 'period_id', [['', '']] + @periods.map{|p| [p.name, p.id]}, {},
		:onchange => remote_function(:update => 'period_link', 
									 :url => { :controller => 'periods', :action => 'make_link', :id => "'+value+'", :escape => false }) %>
<span id="period_link">
	<%=render :partial => '/periods/link', :locals => {:period => @task.period}%>
</span>
<%=detour_to l(:new_period), :controller => 'periods', :action => :new %>
</p>
<% end %>


<% if @task.backlog %>

<p><label for="task_description"><%=l :task%> #<%=@task.id%></label><br/>
<% if @task.active? -%>
	<%=text_field 'task', 'description', :size => 64, :maxlength => 80 %>
<% else -%>
	<%=@task.description -%>
<% end -%>
</p>

<% if @task.enable_customer? %>
<p><label for="task_customer"><%=l :customer%></label><br/>
<%=select 'task', 'customer_id', [['', '']] + @customers.map{|c| [c.name, c.id]}  %>
<% if @task.customer %>
  <%=image_detour_to('customer.png', "#{l(:customer)} #{@task.customer.name}", {:controller => 'customers', :action => :edit, :id => @task.customer}, {:class => 'image-submit', :style => 'vertical-align: bottom'}) %>
<% end %>
<%=detour_to l(:new_customer), :controller => 'customers', :action => :new %>
</p>
<% end %>

<% if @task.track_todo? %>
  <% if @task.new_record? %>
    <p><label for="task_initial_estimate"><%=l :estimate%></label><br/>
      <%= text_field 'task', 'initial_estimate', :size => 4  %>
	</p>
  <% else %>
    <p style="float: left"><label for="estimate_todo"><%=l :estimate%></label><br/>
      <%=text_field 'estimate', 'todo', :size => 4, :value => @task.todo  %>
	</p>
  <% end %>
<% end %>

<% if @task.total_done != 0 -%>
  <p style="float: left"><%=l :done%></label><br/>
    <%=t @task.total_done%>
  </p>
<% end %>
<br clear="all" />

<p><label for="task_notes"><%=l :notes%></label><br/>
<%=text_area 'task', 'notes', :cols => '72', :rows => 16 %>
<%=if @task.notes and not @task.notes.empty? then image_link_to 'view_fullscreen.png', l(:view_fullscreen), :controller => 'tasks', :action => :notes, :id => @task end%>
</p>

<p><label for="task_file"><%=l :files%></label><br/>
<%=@task.task_files.map do |task_file|
  file_url = url_for(:controller => 'task_files', :action => :show, :id => task_file)
  if task_file.image?
    image_url = file_url
  else
    image_url = 'text-x-generic'
  end
  image_link_to(image_url, task_file.name, file_url, :extension => 'png', :height => 22)
end.join(' ')%><br clear="all"/>
<%= file_field 'task', 'file' %></p>

<% end %>
<!--[eoform:task]-->


<script type="text/JavaScript">
document.getElementById('<%=@task.backlog.nil? ? 'task_backlog_id' : @task.period.nil? ? 'task_period_id' : (@task.description.nil? || @task.description.empty?) ? 'task_description' : 'task_notes' %>').focus();
</script>