<%= render :partial => 'common/calendar_listing_links', :locals => {:period => :month, :calendar => @calendar, :url_options => {:tab => :calendar}} -%>

<% if @query.valid? %>
  <div id="easy_attendances" class="easy-attendances easy-attendace-calendar-container">
    <%= render :partial => 'common/calendar', :locals => {:calendar => @calendar, :modul_uniq_id => 'attendances', :easy_user_working_time_calendar => @easy_user_working_time_calendar} %>
    <div class="legend cal easy-calendar-export">
      <span class="starting"><%= l(:starting, :scope => [:easy_attendance, :calendar, :legend]) %></span>
      <span class="ending"><%= l(:ending, :scope => [:easy_attendance, :calendar, :legend]) %></span>
      <span class="starting ending "><%= l(:starting_ending, :scope => [:easy_attendance, :calendar, :legend]) %></span>
      <span class="starting ending approval-status-1"><%= l(:pending, :scope => [:easy_attendance, :calendar, :legend]) %></span>
      <span class="starting ending approval-status-3"><%= l(:rejected, :scope => [:easy_attendance, :calendar, :legend]) %></span>
    </div>
  </div>

<% end %>
<script type="text/javascript">
  function addEasyCalendarAction(path, month, day) {
    var add = $('<a><%= l :new, :scope => :easy_attendance -%></a>').attr({'class': 'easy-attendance-calendar-add-quick-event icon icon-add', 'title': '<%= l :new, :scope => :easy_attendance -%>'});
    add.click(function() { $.get(path); });
    $('#attendances-day-num-' + month + '-' + day).parent().append('<div class="calendar-actions">');
    $('#attendances-day-num-' + month + '-' + day + ' ~ .calendar-actions').append(add);
  }

<% day = @calendar.startdt
if User.current.allowed_to_globally?(:use_easy_attendances)
  while day <= @calendar.enddt %>
    addEasyCalendarAction('<%= j new_easy_attendance_path(:arrival_at => day, :back_url => original_url).html_safe %>', <%= day.month %>, <%= day.day %>);
    <% day += 1 %>
<% end
end %>
</script>
