Skip to content
Snippets Groups Projects
Commit 921764e9 authored by Tyler Lemburg's avatar Tyler Lemburg
Browse files

Add ability to remove recurring reservations can be removed en masse

parent 08111a07
No related branches found
No related tags found
No related merge requests found
require 'active_record'
class AddRecurringReservationTag < ActiveRecord::Migration
def change
add_column :reservations, :recurring_reference_id, :integer
end
end
\ No newline at end of file
...@@ -219,6 +219,7 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -219,6 +219,7 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
end end
end end
recurring_reference_id = (Reservation.maximum(:recurring_reference_id) || 0) + 1
if params.checked?('recurring') if params.checked?('recurring')
begin begin
recurs_until_date = Time.strptime(params[:recurs_until_date], '%m/%d/%Y').midnight.in_time_zone recurs_until_date = Time.strptime(params[:recurs_until_date], '%m/%d/%Y').midnight.in_time_zone
...@@ -406,7 +407,8 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -406,7 +407,8 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
:end_time => new_end, :end_time => new_end,
:is_training => false, :is_training => false,
:user_id => @user.id, :user_id => @user.id,
:title => params[:title] :title => params[:title],
:recurring_reference_id => recurring_reference_id
) )
successful += 1 successful += 1
end end
...@@ -416,14 +418,13 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -416,14 +418,13 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
unless messages.empty? unless messages.empty?
if params[:recurring_type] == 'daily' if params[:recurring_type] == 'daily'
flash :alert, 'Some recurring reservations were not created', "#{messages.count} recurring reservations were not made. This may be just because the space is closed for certain days." flash :alert, 'Some recurring reservations were not created', "#{messages.count} recurring reservations were not made. This may be just because the space is closed for certain days."
puts messages
else else
flash :alert, 'Some recurring reservations were not created', "<ul><li>#{messages.join('</li><li>')}</li></ul>" flash :alert, 'Some recurring reservations were not created', "<ul><li>#{messages.join('</li><li>')}</li></ul>"
end end
end end
end end
Reservation.create( res = Reservation.create(
:resource_id => resource.id, :resource_id => resource.id,
:event_id => nil, :event_id => nil,
:start_time => start_time, :start_time => start_time,
...@@ -432,6 +433,10 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do ...@@ -432,6 +433,10 @@ post '/:service_space_url_name/resources/:resource_id/reserve/?' do
:user_id => @user.id, :user_id => @user.id,
:title => params[:title] :title => params[:title]
) )
if params.checked?('recurring')
res.recurring_reference_id = recurring_reference_id
res.save
end
flash(:success, 'Reservation Created', "You have successfully reserved #{resource.name} for #{params[:length]} minutes at #{start_time.in_time_zone.strftime('%A, %B %d at %l:%M %P')}") flash(:success, 'Reservation Created', "You have successfully reserved #{resource.name} for #{params[:length]} minutes at #{start_time.in_time_zone.strftime('%A, %B %d at %l:%M %P')}")
redirect "/#{@space.url_name}/resources/#{resource.id}/calendar/#{params[:kiosk_mode] ? '?kiosk_mode=true' : ''}" redirect "/#{@space.url_name}/resources/#{resource.id}/calendar/#{params[:kiosk_mode] ? '?kiosk_mode=true' : ''}"
...@@ -628,4 +633,29 @@ post '/:service_space_url_name/resources/:resource_id/cancel/:reservation_id/?' ...@@ -628,4 +633,29 @@ post '/:service_space_url_name/resources/:resource_id/cancel/:reservation_id/?'
redirect back redirect back
end end
post '/:service_space_url_name/resources/:resource_id/cancel_all/:recurring_reference_id/?' do
require_login
load_service_space
# check that the user requesting cancel is the same as the one on the reservation
reservations = Reservation.where(:recurring_reference_id => params[:recurring_reference_id]).all
count = reservations.count
if reservations.empty?
flash :alert, 'Not Found', 'Those reservations were not found.'
redirect back
end
reservations.each do |reservation|
if reservation.user_id != @user.id
flash :alert, 'Unauthorized', 'That is not your reservation.'
redirect back
end
end
Reservation.where(:recurring_reference_id => params[:recurring_reference_id]).delete_all
flash :success, 'Reservations Cancelled', "#{count} reservations have been removed."
redirect back
end
...@@ -38,6 +38,11 @@ You have no upcoming reservations. You can view upcoming trainings to get certif ...@@ -38,6 +38,11 @@ You have no upcoming reservations. You can view upcoming trainings to get certif
<form method="POST" action="/<%= @space.url_name %>/resources/<%= reservation.resource.id %>/cancel/<%= reservation.id %>/" class="delete-form"> <form method="POST" action="/<%= @space.url_name %>/resources/<%= reservation.resource.id %>/cancel/<%= reservation.id %>/" class="delete-form">
<button class="wdn-button" type="submit">Remove</button> <button class="wdn-button" type="submit">Remove</button>
</form> </form>
<% unless reservation.recurring_reference_id.nil? %>
<form method="POST" action="/<%= @space.url_name %>/resources/<%= reservation.resource.id %>/cancel_all/<%= reservation.recurring_reference_id %>/" class="delete-form delete-recurring-reservation">
<button class="wdn-button" type="submit">Remove All</button>
</form>
<% end %>
</td> </td>
</tr> </tr>
<% end %> <% end %>
...@@ -114,4 +119,16 @@ You have not signed up for any upcoming events. Why not check out the calendar t ...@@ -114,4 +119,16 @@ You have not signed up for any upcoming events. Why not check out the calendar t
<% end %> <% end %>
</tbody> </tbody>
</table> </table>
<% end %> <% end %>
\ No newline at end of file
<script type="text/javascript">
require(['jquery'], function($) {
$(document).ready(function() {
$('.delete-recurring-reservation').submit(function (submit) {
if (!window.confirm('This will remove all recurrences of this reservation. Are you sure?')) {
submit.preventDefault();
}
});
});
});
</script>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment