Fix match admin page

This commit is contained in:
Ari Timonen 2014-05-10 13:02:57 +03:00
parent 1577d83fca
commit 314d47b7bf
4 changed files with 43 additions and 12 deletions

View file

@ -31,4 +31,7 @@ $ ->
$(this).closest('form').submit()
return false
$('select.autosubmit').change ->
$(this).closest('form').submit()
$('#notification').delay(3000).fadeOut()

View file

@ -294,8 +294,12 @@ class Match < ActiveRecord::Base
def can_update? cuser, params = {}
return false unless cuser
return true if cuser.admin?
return true if cuser.caster? and Verification.contain params, [:caster_id]
return true if cuser.ref? and !referee and Verification.contain params, [:referee_id]
return true if cuser.caster? and Verification.contain params, [:caster_id] \
and (params[:caster_id] && params[:caster_id].to_i == cuser.id && caster_id.blank?) \
or (params[:caster_id].blank? && caster_id == cuser.id)
return true if cuser.ref? and Verification.contain params, [:referee_id] \
and (params[:referee_id] && params[:referee_id].to_i == cuser.id && referee_id.blank?) \
or (params[:referee_id].blank? && referee_id == cuser.id)
return true if cuser.ref? and referee == cuser \
and Verification.contain params, [:score1, :score2, :forfeit, :report, :demo_id, :motm_name, :matchers_attributes, :server_id]
return true if match_time.past? and !score1 and !score2 and !forfeit \

View file

@ -194,7 +194,7 @@ class User < ActiveRecord::Base
end
def caster?
group.exists? :id => Group::CASTERS
groups.exists? :id => Group::CASTERS
end
def verified?
@ -286,4 +286,12 @@ class User < ActiveRecord::Base
def self.search(search)
search ? where("LOWER(username) LIKE LOWER(?) OR steamid LIKE ?", "%#{search}%", "%#{search}%") : scoped
end
def self.refadmins
Group.find(Group::REFEREES).users.order(:username) + Group.find(Group::ADMINS).users.order(:username)
end
def self.casters
Group.find(Group::CASTERS).users.order(:username)
end
end

View file

@ -25,18 +25,34 @@
\- #{h match.score2}
%td
- if match.caster
= namelink match.caster
- elsif match.can_update?(cuser, {:caster_id => 1})
= form_for match do |f|
= f.hidden_field :caster_id, {:value => cuser.id}
= link_to "Take!", "#form_submit"
= f.hidden_field :caster_id, {:value => nil}
= namelink match.caster
- if match.can_update?(cuser, {:caster_id => nil})
= link_to "#form_submit" do
%i.fa.fa-times
- elsif match.can_update?(cuser, {:caster_id => cuser.id})
= form_for match do |f|
- if cuser.admin?
= f.collection_select :caster_id, Group.casters, :id, :username, {:include_blank => true}, {:class => "autosubmit"}
- else
= f.hidden_field :caster_id, {:value => cuser.id}
= link_to "Take!", "#form_submit"
%td
- if match.referee
= namelink match.referee
- elsif match.can_update?(cuser, {:referee_id => 1})
= form_for match do |f|
= f.hidden_field :referee_id, {:value => cuser.id}
= link_to "Take!", "#form_submit"
= f.hidden_field :referee_id, {:value => nil}
= namelink match.referee
- if match.can_update?(cuser, {:referee_id => nil})
= link_to "#form_submit" do
%i.fa.fa-times
- elsif match.can_update?(cuser, {:referee_id => cuser.id})
= form_for match do |f|
- if cuser.admin?
= f.collection_select :referee_id, User.refadmins, :id, :username, {:include_blank => true}, {:class => "autosubmit"}
- else
= f.hidden_field :referee_id, {:value => cuser.id}
= link_to "Take!", "#form_submit"
%td.actions
- if cuser.ref? || cuser.admin?
= link_to "Admin", match_ref_path(match)
= link_to "Admin", "/matches/ref/#{match.id}"