Add ability to add players to teams for admins

WIP!
This commit is contained in:
Ari Timonen 2019-08-26 23:40:07 +03:00
parent de62098c0a
commit 57a5ae5660
2 changed files with 39 additions and 0 deletions

View file

@ -21,6 +21,7 @@ class Teamer < ActiveRecord::Base
RANK_LEADER = 2
attr_protected :id, :created_at, :updated_at, :version
attr_accessor :username
validates_length_of :comment, :in => 0..15, :allow_blank => true
validates_uniqueness_of :user_id, :scope => [:team_id, :rank]
@ -28,6 +29,7 @@ class Teamer < ActiveRecord::Base
#validate_on_create:validate_team
#validate_on_create:validate_contests
validate :validate_team
validate :validate_username
scope :basic,
:include => :user,
@ -77,6 +79,16 @@ class Teamer < ActiveRecord::Base
end
end
def validate_username
if username
if u = User.first(:conditions => {:username => username})
self.user = u
else
errors.add(:username, t(:gatherer_wrong_username))
end
end
end
def validate_contests
# TODO
end

View file

@ -84,6 +84,19 @@
<%= f.submit "Update" %>
</div>
<% end %>
<%= form_for @team.teamers.build, html: { class: 'square' } do |f| %>
<%= f.hidden_field :team_id %>
<div class="fields horizontal">
<%= f.label :username, "Add user:" %>
<%= f.text_field :username %>
</div>
<div class="controls inline">
<%= f.submit "Add" %>
</div>
<% end %>
</div>
<div id="contests" class="tab">
@ -94,6 +107,20 @@
<div class="fields inline">
<%= f.collection_select :contest_id, Contest.active, :id, :name %>
</div>
<%= form_for @team.contesters.build, html: { class: 'square' } do |f| %>
<%= f.hidden_field :team_id %>
<div class="fields inline">
<%= f.collection_select :contest_id, Contest.active, :id, :name %>
</div>
<div class="controls inline">
<%= f.submit "Join" %>
</div>
<% end %>
</p>
</div>
</div>
<div class="controls inline">
<%= f.submit "Join" %>