Introduce a "Save" button for the admin schedule

The changes were saved after you drop an event, and now it only saves the schedule when you're done with the changes and click the "Save" button.
This commit is contained in:
Ana 2016-07-22 17:57:26 +02:00 committed by Ana María Martínez Gómez
parent de2e316fee
commit 6f0cdc64c3
4 changed files with 105 additions and 57 deletions

View file

@ -6,7 +6,7 @@ module Admin
if @event_schedule.save
render json: { event_schedule_id: @event_schedule.id }
else
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
render json: { errors: parse_errors(@event_schedule) }, status: 422
end
end
@ -14,7 +14,7 @@ module Admin
if @event_schedule.update(event_schedule_params)
render json: { event_schedule_id: @event_schedule.id }
else
render json: { errors: "The event couldn't be scheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
render json: { errors: parse_errors(@event_schedule) }, status: 422
end
end
@ -22,7 +22,7 @@ module Admin
if @event_schedule.destroy
render json: {}
else
render json: { errors: "The event couldn't be unscheduled. #{@event_schedule.errors.full_messages.join('. ')}" }, status: 422
render json: { errors: parse_errors(@event_schedule) }, status: 422
end
end
@ -31,5 +31,11 @@ module Admin
def event_schedule_params
params.require(:event_schedule).permit(:schedule_id, :event_id, :room_id, :start_time)
end
def parse_errors(event_schedule)
title = event_schedule.event.try(:title).present? ? event_schedule.event.title : 'The event'
errors = event_schedule.errors.full_messages.present? ? " (#{event_schedule.errors.full_messages.join('. ')})" : ''
"#{title} couldn't be scheduled#{errors}. "
end
end
end