app/views/repeating_events/_form.html.erb
<% calculate_default_times_repeating_events %>
<%= form_for @repeating_event do |f| %>
<%if @errors%>
<strong>The repeating event could not be applied for the following reasons</strong>
<ul>
<% @errors.each do |error| %>
<li><%=error%></li>
<%end%>
</ul>
<%end%>
<p>
<%= f.label :start_date %><br />
<%= f.date_select :start_date, default: @default_start_date.previous_sunday.to_date %>
</p>
<p>
<%= f.label :end_date %><br />
<%= f.date_select :end_date, default: @default_start_date.previous_sunday.to_date + 6.days %>
</p>
<p>
<%= f.label :calendar %><br />
<%= f.collection_select(:calendar_id, @department.calendars, :id, :name) %>
</p>
<p>
<%= f.label "Apply to entire calendar?" %><br />
<%= check_box_tag "whole_calendar", "1", true %>
</p>
<p>
<strong>Days:</strong><br />
<% WEEK_DAYS.each_with_index do |day, i| %>
<%= check_box_tag "days[]", i, @repeating_event.days && @repeating_event.days.include?(day), {id: "days_#{i}"} %>
<%= day %>
<% end %>
</p>
<p>
<%= f.label :start_time %><br />
<%= f.time_select :start_time, {
start_time: @range_start_time,
end_time: @range_end_time,
include_start_time: true,
include_end_time: false,
default: @repeating_event.start_time
# default: Time.now.to_date + current_department.department_config.schedule_start.minutes,
} %>
</p>
<p>
<%= f.label :end_time %><br />
<%= f.time_select :end_time, {
start_time: @range_start_time,
end_time: @range_end_time,
include_start_time: false,
include_end_time: true,
default: @repeating_event.end_time
# default: Time.now.to_date + current_department.department_config.schedule_end.minutes,
} %>
</p>
<p>
<%= f.label "wipe_conflicts?" %><br />
<%= check_box_tag "wipe", "1", false %>
<p>
<strong>Time Slot or Shift?</strong> <br />
<%= f.label :time_slot %>
<%= f.radio_button( :slot_or_shift, "time_slot", checked: @repeating_event.has_time_slots? ) %>
<%= f.label :shift %>
<%= f.radio_button( :slot_or_shift, "shift", checked: @repeating_event.has_shifts? ) %>
</p>
<div id = "time_slot_fields">
<h3> Time Slot </h3>
<p>
<%# isn't this view restricted to admins anyway? %>
<%# if current_user.is_admin_of?(current_department) %>
<%#= check_box_tag :department_wide_locations, current_department.id, false, style: "display: none;" %>
<%#= label_tag "department_wide_locations", text = current_department.name + " (all locations)"%>
<%# end %>
<div id = "all_locations">
<% for loc_group in current_department.loc_groups do %>
<li id = "repeating_event_li">
<%= check_box_tag "for_location_groups[]", loc_group.id, loc_group_checked_event?(loc_group, @repeating_event) %>
<%= label_tag "location_group_#{loc_group.id}", text = loc_group.name %>:
<% for location in loc_group.locations do %>
<%= check_box_tag "for_locations[]", location.id, location_checked_event?(location, @repeating_event) %>
<%= label_tag "location_#{location.id}", text = location.short_name %>
<% unless location == loc_group.locations.last %> , <%end%>
<% end %>
</li>
<% end %>
</div>
</p>
</div>
<div id="shift_fields">
<h3> Shift </h3>
</p>
<p>
<%= f.label :user %><br />
<%= f.collection_select(:user_id, current_department.active_users, :id, :name, {prompt: "Select a user"}) %>
</p>
<p>
<%= f.label :location %><br />
<%= select_tag 'shift[location_id]', option_groups_from_collection_for_select(@department.loc_groups, :locations, :name, :id, :name, @repeating_event.location_ids ? @repeating_event.location_ids[0] : nil)%><br/>
</p>
</div>
<p><%= f.submit "Submit" %></p>
<% end %>