2017-05-01 14:57:32 +00:00
|
|
|
class MatchProposalsController < ApplicationController
|
2017-06-04 18:30:33 +00:00
|
|
|
before_filter :get_match
|
2017-05-01 14:57:32 +00:00
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2017-06-04 18:30:33 +00:00
|
|
|
@proposal = MatchProposal.new
|
|
|
|
@proposal.match = @match
|
2017-05-11 20:26:18 +00:00
|
|
|
raise AccessError unless @proposal.can_create? cuser
|
2017-05-01 14:57:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2017-06-04 18:30:33 +00:00
|
|
|
@proposal = MatchProposal.new(params[:match_proposal])
|
|
|
|
@proposal.match = @match
|
|
|
|
raise AccessError unless @proposal.can_create? cuser
|
2017-05-11 20:26:18 +00:00
|
|
|
@proposal.team = cuser.team
|
|
|
|
@proposal.status = MatchProposal::STATUS_PENDING
|
|
|
|
|
2017-06-11 14:36:10 +00:00
|
|
|
if @proposal.save
|
2017-05-11 20:26:18 +00:00
|
|
|
flash[:notice] = 'Created new proposal'
|
2017-06-11 14:36:10 +00:00
|
|
|
redirect_to(match_proposals_path(@match))
|
2017-05-11 20:26:18 +00:00
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
2017-05-01 14:57:32 +00:00
|
|
|
end
|
2017-05-11 20:26:18 +00:00
|
|
|
|
|
|
|
def update
|
2017-06-11 14:36:10 +00:00
|
|
|
@proposal = MatchProposal.find(params[:id])
|
2017-06-30 12:03:46 +00:00
|
|
|
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
|
2017-06-30 12:03:46 +00:00
|
|
|
# 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))
|
2017-05-11 20:26:18 +00:00
|
|
|
end
|
|
|
|
|
2017-06-04 18:30:33 +00:00
|
|
|
private
|
|
|
|
def get_match
|
|
|
|
@match = Match.find params[:match_id]
|
|
|
|
end
|
2017-05-01 14:57:32 +00:00
|
|
|
end
|