mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-02-03 06:51:04 +00:00
Added view for creating proposals and added some controller functionality
This commit is contained in:
parent
0f05829bcc
commit
04f2fd77ff
5 changed files with 48 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<tr class="<%=cycle('even', 'odd') %>">
|
||||
<td><%= proposal.team.name %></td>
|
||||
<td><%= longtime proposal.proposed_time %> </td>
|
||||
<td><%= proposal.status %></td>
|
||||
<td><%= proposal.status_strings[proposal.status] %></td>
|
||||
<td>test</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
@ -1,2 +1,11 @@
|
|||
<h1>MatchProposals#new</h1>
|
||||
<p>Find me in app/views/match_proposals/new.html.erb</p>
|
||||
<h1>New Proposal</h1>
|
||||
<%= form_for @proposal, html: { class: 'square' } do |f| %>
|
||||
<%= render 'shared/errors', messages: @proposal.errors.full_messages %>
|
||||
<div class="fields horizontal">
|
||||
<%= f.label :proposed_time %>
|
||||
<%= f.datetime_select :proposed_time, minute_step: 15 %>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<%= f.submit 'Propose' %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
@ -61,7 +61,7 @@ Ensl::Application.routes.draw do
|
|||
get "matches/ref/:id" => "matches#ref", as: :match_ref
|
||||
resources :matches do
|
||||
get :admin, to: "matches#admin", on: :collection
|
||||
resources :match_proposals, path: "proposals", as: "proposals", only: [:index, :new, :create]
|
||||
resources :match_proposals, path: "proposals", as: :proposals, only: [:index, :new, :create, :update]
|
||||
end
|
||||
|
||||
resources :maps
|
||||
|
|
Loading…
Reference in a new issue