ensl.org/app/controllers/match_proposals_controller.rb

54 lines
1.7 KiB
Ruby
Raw Normal View History

2017-05-01 14:57:32 +00:00
class MatchProposalsController < ApplicationController
before_filter :get_match
2017-05-01 14:57:32 +00:00
def index
end
def new
@proposal = MatchProposal.new
@proposal.match = @match
raise AccessError unless @proposal.can_create? cuser
2017-05-01 14:57:32 +00:00
end
def create
@proposal = MatchProposal.new(params[:match_proposal])
@proposal.match = @match
raise AccessError unless @proposal.can_create? cuser
@proposal.team = cuser.team
@proposal.status = MatchProposal::STATUS_PENDING
2017-06-11 14:36:10 +00:00
if @proposal.save
flash[:notice] = 'Created new proposal'
2017-06-11 14:36:10 +00:00
redirect_to(match_proposals_path(@match))
else
render :new
end
2017-05-01 14:57:32 +00:00
end
def update
2017-06-11 14:36:10 +00:00
@proposal = MatchProposal.find(params[:id])
raise AccessError unless @proposal.can_update?(cuser, params[:match_proposal])
2017-06-11 14:36:10 +00:00
@proposal.status = params[:match_proposal][:status]
if @proposal.save
# TODO: rework messages
# TODO: make it so only one proposal can be confirmed for a match at any given time
2017-06-11 14:36:10 +00:00
action = case @proposal.status
when MatchProposal::STATUS_CONFIRMED
"Confirmed Proposal for #{Time.use_zone(view_context.timezone_offset) { @proposal.proposed_time.strftime('%d %B %y %H:%M %Z') }}"
when MatchProposal::STATUS_REJECTED
"Rejected Proposal for #{Time.use_zone(view_context.timezone_offset) { @proposal.proposed_time.strftime('%d %B %y %H:%M %Z') }}"
else
"Smthn went wrong"
end
flash[:notice] = action
else
flash[:notice] = "Error"
end
redirect_to(match_proposals_path(@match))
end
private
def get_match
@match = Match.find params[:match_id]
end
2017-05-01 14:57:32 +00:00
end