diff --git a/app/controllers/match_proposals_controller.rb b/app/controllers/match_proposals_controller.rb index 79e5773..8d02ece 100644 --- a/app/controllers/match_proposals_controller.rb +++ b/app/controllers/match_proposals_controller.rb @@ -1,11 +1,32 @@ class MatchProposalsController < ApplicationController + def index @match = Match.find(params[:match_id]) end def new + match = Match.find(params[:match_id]) + @proposal = MatchProposal.new(match: match) + raise AccessError unless @proposal.can_create? cuser end def create + match = Match.find(params[:match_id]) + @proposal = MatchProposal.new(match: match) + raise AccessError unless @ban.can_create? cuser + @proposal.team = cuser.team + @proposal.status = MatchProposal::STATUS_PENDING + @proposal.proposed_time = params[:match_proposal][:proposed_time] + + if @proposal.save + flash[:notice] = 'Created new proposal' + redirect_to(match) + else + render :new + end end + + def update + end + end diff --git a/app/models/match_proposal.rb b/app/models/match_proposal.rb index c662420..56c3412 100644 --- a/app/models/match_proposal.rb +++ b/app/models/match_proposal.rb @@ -3,7 +3,7 @@ class MatchProposal < ActiveRecord::Base STATUS_PENDING = 0 STATUS_REVOKED = 1 STATUS_REJECTED = 2 - STATUS_ACCEPTED = 3 + STATUS_CONFIRMED = 3 belongs_to :match belongs_to :team @@ -11,8 +11,19 @@ class MatchProposal < ActiveRecord::Base validates_presence_of :match, :team, :proposed_time - def can_create? (match, cuser) - match && cuser && cuser.team.is_leader?(cuser) && (match.of_team cuser.team) + def status_strings + {STATUS_PENDING => 'Pending', + STATUS_REVOKED => 'Revoked', + STATUS_REJECTED => 'Rejected', + STATUS_CONFIRMED => 'Confirmed'} + end + + def can_create? cuser + cuser && cuser.team.is_leader?(cuser) && match.of_team(cuser.team) + end + + def can_update? cuser + cuser && cuser.team.is_leader?(cuser) && match.of_team (cuser.team) end def can_destroy? diff --git a/app/views/match_proposals/index.html.erb b/app/views/match_proposals/index.html.erb index 726f1da..d89fe99 100644 --- a/app/views/match_proposals/index.html.erb +++ b/app/views/match_proposals/index.html.erb @@ -15,7 +15,7 @@
Find me in app/views/match_proposals/new.html.erb
+