<%= call_hook :view_timelog_date_range_top, {:only_me => @only_me, :free_period => @free_period, :from => @from, :to => @to, :project => @project} %>
<div id="date-range">
  <div class="search-form-container gray-background">
    <p>
      <%= radio_button_tag 'period_type', '1', !@free_period, :onclick => '$("#from,#to").prop("disabled", true);$("#period").removeAttr("disabled");' %>
      <%= select_tag 'period', options_for_period_select(params[:period] || 'current_month'),
        :onchange => 'this.form.submit();',
        :onfocus => '$("#period_type_1").prop("checked", true);',
        :disabled => @free_period %>
    </p>
    <p>
      <%= radio_button_tag 'period_type', '2', @free_period, :onclick => '$("#from,#to").removeAttr("disabled");$("#period").prop("disabled", true);' %>
      <span onclick="$('#period_type_2').prop('checked', true);">
        <%= l(:label_date_from_to, :start => (text_field_tag('from', @from, :size => 10, :disabled => !@free_period, :onchange => "$(this).closest('span').click();") + calendar_for('from')),
          :end => (text_field_tag('to', @to, :size => 10, :disabled => !@free_period, :onchange => "$(this).closest('span').click();") + calendar_for('to'))).html_safe %>
      </span>
    </p>
    <%= call_hook :view_timelog_date_after_period_select_before_buttons, {:only_me => @only_me, :free_period => @free_period, :from => @from, :to => @to, :project => @project} %>
  </div>
  <p class="buttons">
    <%= link_to_function l(:button_apply), '$("#query_form").submit()', :class => 'icon icon-checked apply-link' %>
  </p>
</div>
<%= call_hook :view_timelog_date_before_middle, {:only_me => @only_me, :free_period => @free_period, :from => @from, :to => @to, :project => @project} %>
<div class="tabs">
  <% url_params = @free_period ? { :from => @from, :to => @to } : { :period => params[:period] } %>
  <ul>
    <% if !!@only_me -%>
      <li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'index', :project_id => @project, :issue_id => @issue, :only_me => @only_me}),
          :class => (action_name == 'index' ? 'selected' : nil)) %></li>
      <li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project, :issue_id => @issue, :only_me => @only_me}),
          :class => (action_name == 'report' ? 'selected' : nil)) %></li>
    <% else -%>
      <li><%= link_to(l(:label_details), url_params.merge({:controller => 'timelog', :action => 'index', :project_id => @project, :issue_id => @issue}),
          :class => (action_name == 'index' ? 'selected' : nil)) %></li>
      <li><%= link_to(l(:label_report), url_params.merge({:controller => 'timelog', :action => 'report', :project_id => @project, :issue_id => @issue}),
          :class => (action_name == 'report' ? 'selected' : nil)) %></li>
    <% end -%>
    <%= call_hook :view_timelog_date_range_in_tabs, {:only_me => @only_me, :free_period => @free_period, :from => @from, :to => @to, :project => @project} %>
  </ul>
</div>
<%= call_hook :view_timelog_date_range_bottom, {:only_me => @only_me, :free_period => @free_period, :from => @from, :to => @to, :project => @project} %>
<%= javascript_tag do %>
  $('#from, #to').change(function(){
  $('#period_type_interval').prop('checked', true); $('#from,#to').removeAttr('disabled'); $('#period').prop('disabled', true);
  });
<% end %>
