<% hidden_fields ||= []; allowed_trackers ||= []; block_name ||= '' %>
<% issue.estimated_hours = estimated_hours || 0.0 %>

<div class="issue_updatable_fields tabular">
  <div id="<%= "#{block_name}issue-dependent-fields" %>">
    <%= labelled_fields_for block_name+'issue', issue do |f| %>
      <div class="properties_fields">
        <%= toggling_container("issue-updatable-attributes-heading-#{params[:format]}", User.current, {:heading => l(:label_issue_updatable_attributes_heading), :wrapping_heading_element_classes => ' icon icon-workflow'}) do  %>
          <%= hidden_field_tag 'show_fields_option', show_fields_option %>
          <p class="attribute" style="<%= 'display:none;' if hidden_fields.include?(:project_id) %>">
            <% selected_project_value = (issue.project.nil? ? {:name => '', :id => ''} : {:name => issue.project.name, :id => issue.project.id}) %>
            <%= label_tag "#{block_name}issue[project_id]", l(:field_project) %>
            <%= easy_select_tag(
              "#{block_name}issue[project_id]", selected_project_value, projects.nil? ? nil : project_tree_options_for_select(projects, {:selected => issue.project}),
              easy_autocomplete_path('add_issue_projects'),
              :onchange => "$.ajax({url: '#{j(url_for({:controller => :my, :action => :update_my_page_new_issue_dependent_fields})).html_safe}', type: 'post', data: $('##{block_name}issue_project_id').closest('form').serialize()})",
              :html_options => {:id => "#{block_name}issue_project_id"}, :root_element => 'projects') -%>
          </p>
          <% if issue.safe_attribute?('tracker_id') %>
            <p class="attribute" style="<%= 'display:none;' if hidden_fields.include?(:tracker_id) %>">
              <%= f.select :tracker_id, allowed_trackers.collect {|t| [t.name, t.id]}, {:required => true},
                {:onchange => "$.post('#{j(url_for({:controller => :my, :action => :update_my_page_new_issue_dependent_fields})).html_safe}', $(this).closest('form').serialize(), function(data) {$('#{block_name}issue-dependent-fields').html(data)})"} -%>
            </p>
          <% end %>
          <% if issue.safe_attribute?('assigned_to_id') && (issue.tracker.nil? || !issue.tracker.easy_distributed_tasks?) %>
            <p class="attribute" style="<%= 'display:none;' if hidden_fields.include?(:assigned_to_id) %>">
              <% assignable_users_for_options = options_for_select(assignable_users.collect{|i| [i.name, i.id]}, issue.assigned_to_id)
              if assignable_users.include?(user)
                assignable_users_for_options = content_tag(:option, "<< #{l(:label_me)} >>".html_safe, :value => User.current.id) + assignable_users_for_options
                end %>
              <%= f.select :assigned_to_id, assignable_users_for_options, :include_blank => true, :required => required_attributes.include?('assigned_to_id') %>
            </p>
          <% end %>
          <% if issue.safe_attribute?('priority_id') %>
            <p class="attribute" style="<%= 'display:none;' if hidden_fields.include?(:priority_id) %>">
              <%= f.select :priority_id, options_for_select(issue_priorities.collect{|i| [i.name, i.id]}, issue.priority_id), {:required => true} %>
            </p>
          <% end %>
          <% if issue.safe_attribute?('status_id') %>
            <p class="attribute" style="<%= 'display:none;' if hidden_fields.include?(:status_id) %>">
              <%= f.select :status_id, options_for_select(allowed_statuses.collect{|s| [s.name, s.id]}, issue.status_id), :required => true %>
            </p>
          <% end %>
          <% if only_selected %>
            <% if issue.safe_attribute? 'start_date' %>
              <p class="attribute nowrap" style="<%= 'display:none;' if hidden_fields.include?(:start_date) %>">
                <%= f.text_field :start_date, :value => issue.start_date, :size => 10, :required => false %><%= calendar_for(block_name+'issue_start_date') %>
              </p>
            <% end %>
            <% if issue.safe_attribute? 'due_date' %>
              <p class="attribute nowrap" style="<%= 'display:none;' if hidden_fields.include?(:due_date) %>">
                <%= f.text_field :due_date, :value => issue.due_date, :size => 10, :required => required_attributes.include?('due_date') %><%= calendar_for(block_name+'issue_due_date') %>
              </p>
            <% end %>
            <% if issue.project && issue.project.module_enabled?(:time_tracking) && issue.safe_attribute_names.include?('estimated_hours') && (issue.tracker.nil? || !issue.tracker.easy_distributed_tasks?) %>
              <p class="attribute nowrap" style="<%= 'display:none;' if hidden_fields.include?(:estimated_hours) %>">
                <%= f.text_field :estimated_hours, :size => 3, :placeholder => l(:field_hours), :required => required_attributes.include?('estimated_hours') %>
              </p>
            <% end %>
          <% end %>
          <% if issue.safe_attribute?('category_id') && issue.project && issue.project.issue_categories.any? %>
            <p class="select-with-button" style="<%= 'display:none;' if hidden_fields.include?(:category) %>">
              <%= f.select :category_id, issue_category_tree_options_for_select(issue.project.issue_categories, :selected => issue.category_id), {:include_blank => true, :required => required_attributes.include?('category_id')}, {:tabindex => 60} %>
            </p>
          <% end %>

          <% if issue.project && issue.project.module_enabled?(:time_tracking) && issue.safe_attribute_names.include?('activity_id') %>
            <div>
              <p class="attribute" id="<%= "#{block_name}issue-time-entry-activity-container" %> ">
                <%= render :partial => 'timelog/time_entry_activity', :locals => {:tag_name_prefix => "#{block_name}issue", :entity => issue, :activity_collection => issue.project.activities, :container_id => "#{block_name}issue-time-entry-activity-container", :project => issue.project, :options => {:hide_role_select => true}} %>
              </p>
            </div>
          <% end %>
        </div>
      <% end %>

      <% if issue.safe_attribute? 'custom_field_values' %>
        <div class="attribute" style="<%= 'display:none;' if hidden_fields.include?(:custom_fields) || issue.editable_custom_field_values.empty? %>">
          <div class="custom_fields">
            <%= toggling_container("issue-form-custom-fields-#{params[:format]}", User.current, {:heading => l(:label_custom_field_plural), :wrapping_heading_element_classes => ' icon icon-db-key'}) do  %>
              <div class="box">
                <% issue.editable_custom_field_values.each_with_index do |value, idx| %>
                  <p class="new-issue-custom-field"><%= custom_field_tag_with_label block_name+'issue', value %></p>
                <% end %>
              </div>
            </div>
          <% end %>
        </div>
      <% end %>

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