<% back_url = params[:back_url].presence || original_url || easy_attendances_path %>
<%= javascript_tag "eaatf = true;" -%>
<%= error_messages_for easy_attendance -%>
<%= error_messages_for(easy_attendance.time_entry) if easy_attendance.time_entry -%>
<%= hidden_field_tag(:back_url, back_url) -%>
<div class="easy-attendance-advanced-datetime-fields <%= 'with-time-select' if EasySetting.value(:easy_attendance_use_time_select) %>">
  <%= call_hook :view_easy_attendances_form_top, {:easy_attendance => easy_attendance, :back_url => back_url, :f => f} %>

  <div style="float: left; width: 150px;">
    <%= call_hook :view_easy_attendances_form_top_in_activity_bar, {:easy_attendance => easy_attendance, :back_url => back_url, :f => f} %>
      <% easy_attendance_activities.each do |activity| %>
        <% if f.object.new_record? || (activity.at_work? == easy_attendance.easy_attendance_activity.at_work?) %>
          <p class="easy-attendance-activity">
            <%= f.radio_button(:easy_attendance_activity_id, activity.id, {:data => {:url => change_activity_easy_attendances_path}}) -%>
            <%= f.label "easy_attendance_activity_id_#{activity.id}", activity.name -%>
          </p>
        <% end %>
      <% end %>
  </div>
  <div style="margin-left: 155px; overflow: hidden" class="tabular">
    <%= call_hook :view_easy_attendances_form_right_top, {:easy_attendance => easy_attendance, :back_url => back_url, :f => f} %>
    <div id="easy_attendance_form_fields_container">
      <% if easy_attendance.easy_attendance_activity %>
          <%= render(:partial => 'easy_attendances/form_fields', :locals => {:activity => easy_attendance.easy_attendance_activity, :easy_attendance => easy_attendance}) %>
      <% else %>
        <%= f.hidden_field(:arrival) %>
        <%= f.hidden_field(:departure) %>
      <% end -%>
    </div>

    <% if User.current.allowed_to?(:edit_easy_attendances, nil, :global => true) %>
      <p class="user-select">
        <%= f.label(:user_id, l(:label_user)) %>
        <% users = User.active.non_system_flag.easy_type_internal.sorted.to_a
           users.unshift(f.object.user) if f.object.user && !users.include?(f.object.user) %>
        <% if f.object.new_record? %>
          <%= autocomplete_field_tag("#{f.object_name}[user_id][]", users.map{|u| [u.name, u.id]}, @user_ids || Array(f.object.user_id), {select_first_value: true, show_toggle_button: true, jquery_auto_complete_options: {:appendTo => '#ajax-modal'}.to_json}) %>
        <% else %>
          <%= f.select(:user_id, users.map{|u| [u.name, u.id]}) -%>
        <% end -%>
      </p>
    <% end %>

    <% if EasyGlobalTimeEntrySetting.value('timelog_comment_editor_enabled', User.current.roles) %>
      <p class="text_area">
        <%= f.text_area(:description) %>
        <%= wikitoolbar_for('easy_attendance_description') %>
      </p>
    <% else %>
      <p>
        <%= f.label(:description, l(:field_description)) %>
        <%= f.text_field(:description, :size => 100) %>
      </p>
    <% end -%>
    <%= call_hook :view_easy_attendances_form_right_bottom, {:easy_attendance => easy_attendance, :back_url => back_url, :f => f} %>
  </div>
  <%= call_hook :view_easy_attendances_form_bottom, {:easy_attendance => easy_attendance, :back_url => back_url, :f => f} %>
</div>
<div class="clear"></div>
