From 02df70a9352e000d91c3fd16f2b2e712fccb1d12 Mon Sep 17 00:00:00 2001 From: Rahul Date: Tue, 13 Aug 2019 17:43:39 +0530 Subject: [PATCH] add condition to change state in booths controller organizer can now change state of all the booths with similar state --- app/controllers/admin/booths_controller.rb | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index 6c2ad8dc..7db8fb03 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -116,7 +116,37 @@ module Admin end def booths_state - redirect_to admin_conference_booths_path + current_state = booth_params[:current_booth_state] + all_booths = @booths.where(state: current_state) + new_state = booth_params[:new_booth_state] + failed_booth = [] + all_booths.each do |booth| + if ["Accept #{t 'booth'}", 'Accept with email'].include?(new_state) + booth.accept + elsif ['Reject', 'Reject with email'].include?(new_state) + booth.reject + elsif new_state == "To reject #{t 'booth'}" + booth.to_reject + elsif new_state == 'Start review' + booth.restart + elsif new_state == "To accept #{t 'booth'}" + booth.to_accept + elsif new_state == "Cancel #{t'booth'}" + booth.cancel + elsif new_state == "Confirm #{t 'booth'}" + booth.confirm + end + unless booth.save + failed_booth.push(booth.id) + end + end + if failed_booth.empty? + redirect_to admin_conference_booths_path(conference_id: @conference.short_title), + notice: "#{(t'booth').capitalize.pluralize} successfully updated." + else + redirect_to admin_conference_booths_path(conference_id: @conference.short_title) + flash[:error] = "#{(t 'booth').capitalize.pluralize} with id #{failed_booth.join(', ')} aren't updated." + end end private